您的位置:首页 > 其它

S2SH整合以及图片上传(10)之修改信息(1)

2018-03-07 16:50 513 查看
    在这篇文章中,我们开始讲修改操作。
    关于修改,由于我们是将图片放置到服务器下面的,只是将其路径存到了数据库中,如果要修改图片的话,需要先将原先的图片删除,然后再为新图片创建一个路径,如此比较繁琐。
    因此,我们这里直接设定图片为不可修改状态。

    第一步,我们需要在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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ssh整合 图片上传
相关文章推荐