环境搭建参考https://blog.csdn.net/YKYZSYA/article/details/108000053
对象封装参考https://blog.csdn.net/YKYZSYA/article/details/108070188
查所有参考https://blog.csdn.net/YKYZSYA/article/details/108034576
参考查所有的界面,修改需要显示初始值,首先查询单个
Dao层接口层 PersonDao.java
//查一个
public Person queryone(int pid);
Dao层mapper层 Personmapper.xml
<select id="queryone" resultMap="personmap" parameterType="int">
select * from Person where pid=#{pid}
</select>
Service层接口层 PersonSer.java
public Person queryone(int pid);
Service层实现层 PersonSerImpl.java
@Override
public Person queryone(int pid) {
// TODO Auto-generated method stub
return personDao.queryone(pid);
}
Controller层 PersonCon.java
@RequestMapping("queryone")
public ModelAndView queryone(int pid) {
Person person = personSer.queryone(pid);
ModelAndView mv=new ModelAndView("update.jsp");
mv.addObject("person",person);
return mv;
}
前台jsp显示update.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="update" method="post">
<input type="hidden" name="userinfo.uid" value="${person.userinfo.uid }">
<input type="hidden" name="pid" value="${person.pid }">
<table border="1px solid red" cellpadding="0px" cellspacing="0px" align="center">
<tr>
<td>姓名:</td>
<td><input type="text" name="pname" value="${person.pname }"></td>
</tr>
<tr>
<td>身份证:</td>
<td><input type="text" name="idcard" value="${person.idcard }"></td>
</tr>
<tr>
<td>电话:</td>
<td><input type="text" name="phone" value="${person.phone }"></td>
</tr>
<tr>
<td>性别:</td>
<td><input type="radio" name="sex" value="男" checked="checked">男
<input type="radio" name="sex" value="女">女</td>
</tr>
<tr>
<td>体温:</td>
<td><input type="text" name="temperature" value="${person.temperature }"><br></td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
开始修改
Dao层接口层 PersonDao.java
//修改
public int update(Person person);
Dao层mapper层 Personmapper.xml
<update id="update" parameterType="person">
update Person set pname=#{pname},phone=#{phone},idcard=#{idcard},temperature=#{temperature},sex=#{sex},uid=#{userinfo.uid} where pid=#{pid}
</update>
Service层接口层 PersonSer.java
public int update(Person person);
Service层实现层 PersonSerImpl.java
@Override
public int update(Person person) {
// TODO Auto-generated method stub
return personDao.update(person);
}
Controller层 PersonCon.java
@RequestMapping("update")
public ModelAndView update(Person person) {
ModelAndView mv=new ModelAndView();
if (personSer.update(person)>0) {
//跳到查所有
mv.setViewName("redirect:queryall");
}
return mv;
}