首页 > 技术文章 > 温故知新

loveJavaJava 2020-08-11 21:17 原文

2020/8/11

   今天在公司继续熟练 后端增删查改,分页,理解代码,温故知新:首字母大写的是类,如Student,小写的是变量student

for each格式for(变量:数组/集合){}

变量类型与数组或集合类型相同

第一遍遍历数组第一个/集合,第二次第二个,一直到集合为空

敲service就自动出protected void service(之前是post和get各自请求)

写servlet是new servlet

key 是键,getParameter(key):键对应的值

if(){

只有一句

} return可放在里面

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>查询</title>
<script src="js/jQuery1.11.min.js"></script>
<script src="js/添加.js"></script>
<script type="text/javascript">
// $.ajaxSetup 全局,当前页面调用均可 timeout:5000,请求服务器超过5s$("div").html("服务器异常、请稍后再试")
// async:false,同步 async:true是异步,发送请求后不用等着可以去做别的事(刷别的网页)
$.ajaxSetup({
timeout:5000,
async:false,
dataType:"json",
beforeSend:function(){
$("div").html("数据正在加载...")
},
error:function(){
$("div").html("服务器异常、请稍后再试")
},
})

function test1(){
$.get("http://localhost:8080/web005/GetStudentAll",{},function(data){
$("div").html("服务器请求成功")
alert(data)
let tbody=document.querySelector("tbody")
let msg=""
for(let i=0;i<data.length;i++){
msg+="<tr>"
msg+="<td>"+data[i].id+"</td>"
msg+="<td>"+data[i].name+"</td>"
msg+="<td>"+data[i].pwd+"</td>"
msg+="<td>"+data[i].classid+"</td>"
msg+="<td>删除 修改</td>"
msg+="</tr>"
}
tbody.innerHTML=msg
})
}


function addStudent2() {
$.post("http://localhost:8080/web005/AddStudent",$("#form1").serialize(),function (data) {
if (data)
location.href="manager.html"
})

}
alert('服务器请求完毕')

</script>
</head>
<body>
<div></div>
<button onclick="test1()">查询</button>
<button onclick="addStudent2()">添加</button>

<table>
<thead>
<tr>
<td>编号</td>
<td>姓名</td>
<td>密码</td>
<td>班级</td>
<td>操作</td>
</tr>
</thead>
<form id="form1" hidden>
<table>
<tr>
<td>姓名</td>
<td><input type="text" id="name" name="name"></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password" id="pwd" name="pwd"></td>
</tr>
<tr>
<td>班级</td>
<td>
<select id="classid" name="classid">
<option value="1">全职太太</option>
<option value="2">销售</option>
<option value="3">电视台</option>

</select>
</td>
</tr>
</table>
</form>

<tbody>

</tbody>
</table>
</body>
</html>

 

推荐阅读