会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133510个问题
JAVA 全系列/第十阶段:权限控制与安全认证/Spring Security(旧) 9317楼
JAVA 全系列/第六阶段:JavaWeb开发/Servlet技术详解 9318楼

public class Test08 {
    public static void main(String[] args) {
        Emp[] emp= {
            new Emp(1001,"高小琪",18,"讲师","2-14"),
            new Emp(1002,"高小七",19,"助教","10-10"),
            new Emp(1003,"高小琴",20,"主任","5-5")
        };
        

        for(Emp temp:emp){
            System.out.println(temp);
        }
    }
}

class Emp{
    private int id;
    private String name;
    private int age;
    private String job;
    private String Date;

    public Emp(int id, String name, int age, String job, String date) {
        this.id = id;
        this.name = name;
        this.age = age;
        this.job = job;
        Date = date;
    }

    @Override
    public String toString() {
        return "{"+id+"\t"+name+"\t"+age+"\t"+job+"\t"+ Date+"}";
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getJob() {
        return job;
    }

    public void setJob(String job) {
        this.job = job;
    }

    public String getDate() {
        return Date;
    }

    public void setDate(String date) {
        Date = date;
    }
}

老师,我这里创建了一个Emp的类,又创建了一个用Emp声明的数组。为什么这里的数组的声明要用Emp声明,我创建的数组的声明类型和我创建的类有什么联系?

JAVA 全系列/第一阶段:AI驱动的JAVA编程/数组和数据存储 9319楼
WEB前端全系列/第十四阶段:React知识体系/React基础知识 9321楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO流技术 9322楼
JAVA 全系列/第九阶段:SpringBoot与MybatisPlus/Spring Boot旧 9323楼

为什么size数值为0?
package 栈结构;

import java.util.Arrays;
import java.util.EmptyStackException;

public class MyStack<E>{
    private Object[] arr;
    private int stackLength =4;
    private int size;
    private int index =-1;


    public boolean empty(){
        return this.size==0;
    }


    public E pop(){
        if (this.index == -1){
                throw new EmptyStackException();
    }
        this.size--;
        return  (E)this.arr[index--];
    }


    public  E push(E item){
        this.capacity();
        this.arr[++index]=item;
        return item;
    }

    private void capacity(){
        if ( this.arr==null ){
            this.arr=new Object[this.stackLength];
        }
        if (this.size-(this.stackLength-1)>=0 ){
            this.stackLength=this.stackLength+(this.stackLength>>1);
            this.arr= Arrays.copyOf(this.arr,this.stackLength);
        }
    }

    public static void main( String[] args ) {
        MyStack<String> ms = new MyStack<>();
        ms.push("a");
        ms.push("b");
        ms.push("c");
        System.out.println(ms.size);
        System.out.println(ms.pop() );
        System.out.println(ms.pop() );
        System.out.println(ms.pop() );
    }
}

image.png

JAVA 全系列/第二阶段:JAVA 基础深化和提高/数据结构 9324楼
JAVA 全系列/第一阶段:AI驱动的JAVA编程/JAVA入门和背景知识 9325楼
JAVA 全系列/第十一阶段:百战旅游网项目/百战旅游网 9326楼

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>06php与MySQL增删改查</title>
    <script src="./jquery-3.6.0.min.js"></script>
</head>

<body>
    <form action="06php与MySQL增.php" method="post" id="insert">
        <span>账号:</span><input type="text" placeholder="请输入您的账号" name="insert-userName" id="userName">
        <span>密码:</span><input type="password" placeholder="请输入您的密码" name="insert-password" id="password">
        <span>电子邮箱:</span><input type="text" placeholder="请输入您的电子邮箱" name="insert-email" id="email">
        <button type="submit">增</button>
    </form>
    <form action="06php与MySQL删.php" method="post" id="delete">
        <span>id:</span><input type="text" placeholder="请输入您要删除的id号" name="delete-id" id="id">
        <button type="submit">删</button>
    </form>
    <form>
        <!-- 修改密码 -->
        <span>账号:</span><input type="text" placeholder="请输入您的账号" name="update-userName" id="update-userName">
        <span>修改后的密码:</span><input type="text" placeholder="请输入您修改后的密码" name="update-password" id="update-password">
        <button id="update-pwd-btn">提交改后的密码</button><span id="update-result"></span>
        <br>
        <!-- 按用户名查找 -->
        <span>查找的账号:</span><input type="text" placeholder="请输入您要查找的账号" name="select-userName" id="select-userName">
        <button id="select-btn">提交</button><span id="select-result"></span>
        <script>
            $("#update-pwd-btn").click(function() {
                var updateUserName = $("#update-userName").val();
                var updatePwd = $("#update-password").val();
                $.ajax({
                    type: 'get',
                    url: "http://localhost/php/06php与MySQL改.php",
                    data: {
                        userName: updateUserName,
                        password: updatePwd
                    },
                    success: function(res) {
                        //$("#update-result").html(res);
                        console.log("改操作成功!");
                    }
                })
            })

            $("#select-btn").click(function() {
                var selectUserName = $("#select-userName").val();
                $.ajax({
                    type: "post",
                    url: "http://localhost/php/06php与MySQL查.php",
                    data: {
                        userName: selectUserName
                    },
                    success: function(res) {
                        // $("#select-result").html(res);
                        console.log('查操作成功');
                    }
                })
            })
        </script>

    </form>
    <script>
    </script>
</body>

</html>

Snipaste_2022-07-20_11-16-43.png我给每一个增删改查都写了一个php文件,增和删没用ajax,可以跳转实现功能。但是用Ajax做的改查,数据库的数据是可以改,但是success对应的回调函数不执行。我把回调函数就写成console.log('查操作成功')也不可以。一打开控制台就会有报错:DevTools 无法加载来源映射:无法加载 chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/browser-polyfill.js.map 的内容:系统错误: net::ERR_FILE_NOT_FOUND

下面是我写的查操作的php文件

<?php

    $userName=$_GET['userName'];

    $password=$_GET['password'];


    $con=mysqli_connect('localhost','root','','zirenqimysql');

    if($con){

        mysqli_query($con,"set names utf8");

        $sql="update `usertable` set password='$password' where userName='$userName'";

        $result=mysqli_query($con,$sql);

        mysqli_close($con);

        if($result>0){

            echo "改操作成功!";

        }else{

            echo "改操作失败!";

        }

       

    }else{

        echo "连接失败!";

    }

?>

我不知道为什么success对应的函数没有结果,控制台的报错要怎么改?

WEB前端全系列/第五阶段:前后端交互/服务器与数据库交互 9327楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 9328楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 9329楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637