删除和修改基于查询和插入,查询和插入获取http://t.csdn.cn/Hqu9c
点击删除即可删除对应用户,点击修改则弹出右侧的修改页面,因为我建的user表没设id,所有我们通过用户名来修改对应用户,修改完成点击修改按钮,在重新查找就会发现用户被修改
利用以前的查找和插入页面,在查找成功后的页面进行修改和删除,这里我们只需要加上修改的内容页面
<%--修改--%>
<div id="update" class="update" style="float: right;margin-top: -500px;background: deepskyblue;width: 500px;height: 500px">
div>
function selectUserAndLogin(){
var params =$form.serialize();
params = decodeURIComponent(params,true);
$.ajax({
url:"http://localhost:8080/javaee_war_exploded/selectUserAndLogin",
type:"post",
data:params,
dataType:"json",
success:function (data){
var str="用户名 姓名 性别 年龄 电话 密码 操作 --- ";
$.each(data,function (index,obj){
str+=""+obj.name+" "+obj.username+" "+obj.sex+" "+obj.age+" "+obj.telephone+" "+obj.loginVo.password+" " +
"+"\""+obj.name+"\""+")'>删除 " +
"+"\""+obj.name+"\""+","+"\""+obj.username+"\""+","+"\""+obj.sex+"\""+","+"\""+obj.age+"\""+","+"\""+obj.telephone+"\""+")'>修改 ";
})
$('#show').empty();
$('#show').append(str);
},
error:function (){
alert("error");
}
})
}
function deleteuser(infor){
console.log(infor)
serialize="name"+"="+infor;
$.ajax({
url:"http://localhost:8080/javaee_war_exploded/deleteuser",
type:"get",
data:serialize,
dataType:"json",
success:function (data){
if(data.count==1){
alert("删除成功")
}else {
alert("删除失败")
}
},
error:function (){
alert("error");
}
})
}
function updateuser(name,username,sex,age,telephone){
str="用户名:
" +
"姓名:
" +
"性别:
" +
"年龄:
" +
"手机号:
" +
""
$('#update').empty();
$('#update').append(str);
}
function updateuser2(){
console.log();
var name=document.getElementById("name1").value;
var username=document.getElementById("username1").value;
var sex=document.getElementById("sex1").value;
var age=document.getElementById("age1").value;
var telephone=document.getElementById("telephone1").value;
serialize="name"+"="+name+"&"+"username"+"="+username+"&"+"sex"+"="+sex+"&"+"age"+"="+age+"&"+"telephone"+"="+telephone;
params=decodeURIComponent(serialize,true);
$.ajax({
url:"http://localhost:8080/javaee_war_exploded/updateuser",
type:"get",
data:params,
dataType:"json",
success:function (data){
if(data.count==1){
alert("修改成功")
}else {
alert("修改失败")
}
},
error:function (){
alert("error");
}
})
}
@RequestMapping( "/deleteuser")
@ResponseBody
public String deleteuser(String name) throws JsonProcessingException {
System.out.println(name);
int i=userService.deleteuser(name);
HashMap<String,String> map=new HashMap<>();
map.put("count",i+"");
ObjectMapper mapper=new ObjectMapper();
String json=mapper.writeValueAsString(map);
return json;
}
@RequestMapping(value = "/updateuser",produces = "application/json;charset=utf-8")
@ResponseBody
public String updateuser(User user) throws JsonProcessingException {
System.out.println(user.getUsername());
int i=userService.updateuser(user);
HashMap<String,String> map=new HashMap<>();
map.put("count",i+"");
ObjectMapper mapper=new ObjectMapper();
String json=mapper.writeValueAsString(map);
return json;
}
public int deleteuser(String name);
public int updateuser(User user);
@Override
public int deleteuser(String name) {
return mapper.deleteuser(name);
}
@Override
public int updateuser(User user) {
return mapper.updateuser(user);
}
public int deleteuser(@Param("name") String name);
public int updateuser(User user);
<update id="updateuser" parameterType="User" >
update user set username =#{username} , sex=#{sex} , age=#{age} , telephone=#{telephone} where name=#{name}
update>
<delete id="deleteuser" parameterType="String">
delete from user where name=#{name}
delete>