6.Eclipse+SSM+修改

环境搭建参考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;
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值