Ajax 实战
创建项目
创建Java项目
点击finish完成项目创建,然后右键选择"add Framework Support..."
勾选红框中的选项,点击"OK",完成后项目下出现web文件夹
点击"project structure"
点击Modules,选择"Web"模块,再按图示点击"+",按默认路径, 再点击"OK"
选择Edit Configuration...
选择Deployment标签,点击右侧"+",选择要部署的项目,按默认就可以
添加要部署的war文件,Application context设置为"/",点击ok。
添加依赖包
在"dependencies"标签中,点击右侧"+",选择Library...,添加 Tomcat
根据实际情况继续添加其它必要的依赖,如fastjson,commonslang等。
导入jquery包
在web目录下,创建js文件夹,把jquery-3.6.0.js放到js目录下
创建实体类User
package com.itbaizhan.ajax.pojo; public class User { private Integer id; private String username; private String password; private Double salary; private String birthday; public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Double getSalary() { return salary; } public void setSalary(Double salary) { this.salary = salary; } public String getBirthday() { return birthday; } public void setBirthday(String birthday) { this.birthday = birthday; } public User(Integer id, String username, String password, Double salary, String birthday) { this.id = id; this.username = username; this.password = password; this.salary = salary; this.birthday = birthday; } public User() { } }
创建页面
创建index.jsp中的静态部分
<body> <div> <table align="center" width="60%" border="1"> <tr> <td>ID:</td> <td><input type="text" name="id" id="id"/></td> <td>姓名:</td> <td><input type="text" name="username" id="username"/></td> <td>密码:</td> <td><input type="text" name="password" id="password"/></td> </tr> <tr> <td>收入:</td> <td><input type="text" name="salary" id="salary"/></td> <td>出生日期:</td> <td><input type="text" name="birthday" id="birthday"/></td> <td colspan="2"></td> </tr> <tr align="center"> <td colspan="6"> <input type="button" value="添加用户" id="add" /> <input type="button" value="更新用户" id="update"/> </td> </tr> </table> <hr/> <table align="center" width="60%" bgcolor="" border="1" id="myTable"> <thead> <tr align="center"> <td>ID</td> <td>姓名</td> <td>密码</td> <td>收入</td> <td>生日</td> <td>操作</td> </tr> </thead> <tbody id="tBody"></tbody> </table> </div> </body>
Ajax技术【Ajax 实战】(二)-全面详解(学习总结---从入门到深化)(下):https://developer.aliyun.com/article/1419259