S2SH整合以及图片上传(10)之修改信息(1)
2018-03-07 16:50
513 查看
在这篇文章中,我们开始讲修改操作。
关于修改,由于我们是将图片放置到服务器下面的,只是将其路径存到了数据库中,如果要修改图片的话,需要先将原先的图片删除,然后再为新图片创建一个路径,如此比较繁琐。
因此,我们这里直接设定图片为不可修改状态。
第一步,我们需要在list.jsp页面添加一个操作选项:
代码如下:
<td>修改用户</td>
代码如下:
//得到一个人员
public Person getPerson(Integer personid); 第三步,我们需要在PersonDaoImpl类中实现该方法: //得到一个人员
@Override
public Person getPerson(Integer personid) {
return (Person) sessionFactory.getCurrentSession().get(Person.class,
personid);
} 第四步,在PersonService接口中添加如下方法:
代码如下:
//得到一个人员
public Person getPerson(Integer personid); 第五步,我们需要在PersonServiceImpl类中实现该方法: //得到一个人员
@Override
public Person getPerson(Integer personid) {
return personDao.getPerson(personid);
} 第六步,在PersonAction中实现跳转至修改页面: //跳转至修改页面
public String goUpdate(){
// 将参数存至request域里
request.setAttribute("personUpdate", personService.getPerson(Integer
.parseInt(request.getParameter("id"))));
return "goupdate";
}
第七步,我们还需要在struts.xml中配置一个result:
代码如下:
<result name="goupdate">/update.jsp</result>
第八步,我们需要写一个update.jsp页面:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Person Operate Page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h2>S2SH整合以及图片上传</h2>
<h2>修改人员</h2>
<s:form action="person!update" namespace="/person" method="post">
<table>
<tr>
<td>id</td>
<td><input type="text" readonly="readonly" value="${personUpdate.id }"
name="personDto.id" />
</td>
</tr>
<tr>
<td>name</td>
<td><input type="text" value="${personUpdate.name }" name="personDto.name" />
</td>
</tr>
<tr>
<td>img</td>
<td><img src="${pageContext.request.contextPath}/${personUpdate.imgurl}" alt="图片无法显示" height="200" width="300"/>
</td>
</tr>
<tr>
<td><input type="submit" value="修改" />
</td>
<td><input type="reset" value="重置" />
</td>
</tr>
</table>
</s:form>
</body>
</html>
第九步,测试:
S2SH整合以及图片上传(11)之修改信息(2)
关于修改,由于我们是将图片放置到服务器下面的,只是将其路径存到了数据库中,如果要修改图片的话,需要先将原先的图片删除,然后再为新图片创建一个路径,如此比较繁琐。
因此,我们这里直接设定图片为不可修改状态。
第一步,我们需要在list.jsp页面添加一个操作选项:
代码如下:
<td>修改用户</td>
<td> <a href="${pageContext.request.contextPath}/person/person!goUpdate?id=${person.id }">修改用户</a> </td>第二步,我们在PersonDao接口中添加如下方法:
代码如下:
//得到一个人员
public Person getPerson(Integer personid); 第三步,我们需要在PersonDaoImpl类中实现该方法: //得到一个人员
@Override
public Person getPerson(Integer personid) {
return (Person) sessionFactory.getCurrentSession().get(Person.class,
personid);
} 第四步,在PersonService接口中添加如下方法:
代码如下:
//得到一个人员
public Person getPerson(Integer personid); 第五步,我们需要在PersonServiceImpl类中实现该方法: //得到一个人员
@Override
public Person getPerson(Integer personid) {
return personDao.getPerson(personid);
} 第六步,在PersonAction中实现跳转至修改页面: //跳转至修改页面
public String goUpdate(){
// 将参数存至request域里
request.setAttribute("personUpdate", personService.getPerson(Integer
.parseInt(request.getParameter("id"))));
return "goupdate";
}
第七步,我们还需要在struts.xml中配置一个result:
代码如下:
<result name="goupdate">/update.jsp</result>
第八步,我们需要写一个update.jsp页面:<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Person Operate Page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h2>S2SH整合以及图片上传</h2>
<h2>修改人员</h2>
<s:form action="person!update" namespace="/person" method="post">
<table>
<tr>
<td>id</td>
<td><input type="text" readonly="readonly" value="${personUpdate.id }"
name="personDto.id" />
</td>
</tr>
<tr>
<td>name</td>
<td><input type="text" value="${personUpdate.name }" name="personDto.name" />
</td>
</tr>
<tr>
<td>img</td>
<td><img src="${pageContext.request.contextPath}/${personUpdate.imgurl}" alt="图片无法显示" height="200" width="300"/>
</td>
</tr>
<tr>
<td><input type="submit" value="修改" />
</td>
<td><input type="reset" value="重置" />
</td>
</tr>
</table>
</s:form>
</body>
</html>
第九步,测试:
S2SH整合以及图片上传(11)之修改信息(2)
相关文章推荐
- S2SH整合以及图片上传(11)之修改信息(2)
- S2SH整合以及图片上传(9)之删除图片
- S2SH整合以及图片上传(6)之图片上传
- S2SH整合以及图片上传(5)之struts2的搭建
- S2SH整合以及图片上传(7)之解决懒加载
- S2SH整合以及图片上传(8)之显示图片
- S2SH整合以及图片上传(1)之spring搭建
- S2SH整合以及图片上传(12)之分页显示
- S2SH整合以及图片上传(3)之hibernate搭建(2)
- SpringMVC:学习笔记(10)——整合Ckeditor且实现图片上传
- 头像上传 模拟(个人信息修改 有头像图片上传 一般 用form 表单提交)
- html5移动端图片剪切上传 以及修改file标签样式
- Android中相机拍摄照片,以及相册选择图片压缩上传(压缩后保存进SD中)(可用于修改头像等)
- yii php ajaxUpload上传图片以及post提交记住已填信息
- 一次提交实现注册或修改信息并上传图片文件
- Camera的学习,图片的保存(两种),获取手机图片以及图片信息修改(小的图片浏览器)
- (一)上传图片至服务器,写入到数据库Blob字段中,以及从数据库读取Blob信息(iframe父子页面传值)
- 上传图片至服务器,写入到数据库Blob字段中,以及从数据库读取Blob信息(iframe父子页面传值)(1)
- (二)上传图片至服务器,写入到数据库Blob字段中,以及从数据库读取Blob信息(iframe父子页面传值)
- Javascript上传图片:获取图片名称、大小、类型、上次修改时间、图片宽高等信息