SSH前后端数据交互
2016-12-18 17:37
387 查看
jsp页面
form标注为role-editUI
然后在struts.xml里面配置action
editUI.jsp对应的方法为类roleAction下面的editUI()方法
然后通过service和hibernate就可以达到编辑的效果。
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>sss <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> <title>My JSP 'index.jsp' starting page</title> </head> <body> <s:form action="role_editUI"> <s:hidden name="id"></s:hidden> <s:textfield name="name"></s:textfield> <s:textarea name="description"></s:textarea> <s:submit name="提交"></s:submit> </s:form> </body> </html>
form标注为role-editUI
然后在struts.xml里面配置action
<action name="role_*" class="roleAction" method="{1}"> <result name="list">/WEB-INF/JSP/roleAction/list.jsp</result> <result name="addUI">/WEB-INF/JSP/roleAction/addUI.jsp</result> <result name="editUI">/WEB-INF/JSP/roleAction/editUI.jsp</result> <result name="toList" type="redirectAction">role_list</result> </action>
editUI.jsp对应的方法为类roleAction下面的editUI()方法
package cn.itcast.oa.view.action; import java.util.List; import javax.annotation.Resource; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import cn.itcast.oa.domain.Role; import cn.itcast.oa.service.RoleService; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; @Controller @Scope("prototype") public class RoleAction extends ActionSupport{ private Long id; private String name; private String description; @Resource private RoleService roleService; /** * 列表 * @return * @throws Exception */ public String list() throws Exception{ List<Role> roleList = roleService.findAll(); ActionContext.getContext().put("roleList", roleList); return "list"; } /** * 删除 * @return * @throws Exception */ public String delete() throws Exception{ return "toList"; } /** * 添加 * @return * @throws Exception */ public String add() throws Exception{ Role role = new Role(); role.setName(name); role.setDescription(description); roleService.save(role); return "toList"; } /** * 修改 * @return * @throws Exception */ public String edit() throws Exception{ //要更新到数据库 Role role = roleService.getById(id); role.setName(name); role.setDescription(description); roleService.update(role); return "toList"; } /** * 添加页面 * @return * @throws Exception */ public String addUI() throws Exception{ return "addUI"; } /** * 修改页面 * @return * @throws Exception */ public String editUI() throws Exception{ //准备回显的数据 Role role=roleService.getById(id); //ActionContext.getContext().getValueStack().push(role); this.name=role.getName(); this.description=role.getDescription(); return "editUI"; } }
然后通过service和hibernate就可以达到编辑的效果。
相关文章推荐
- ssh前后台交互, list传输到前后展示,table传输到台数据!!!。ssh对象传输
- asp.net 前端跟后端通过接口调用实现数据交互(含分页)
- 前后端数据交互方法
- SSH中后端获取到的数据传向页面显示
- 前后端数据交互方法 汇总
- flex和后端的数据交互(一)--XML和HTTPService
- ajax前后端数据交互简析
- java连接MySQL数据库 json数据前后端交互
- Ueditor 前后端数据交互
- 使用AngularJS实现的前后端分离的数据交互过程
- 前后端数据交互方法
- spring mvc 前后端数据交互笔记(解决httprequest400,415问题)
- web前后端数据交互
- 前后端数据交互总结
- Unity3d 前端与后端之间的数据交互
- 在非英文字符集的页面上,如果使用Ajax方式进行数据交互的话,就必须要注意保证前后端数据的统一编码,否则,很容易就出现乱码!
- 基于websocket的前端与后端之间的数据交互
- ssh配置客户端和服务器的交互json传递数据
- 前后端数据交互方法
- 一种安全的前后端数据交互方案