日期:2014-05-16 浏览次数:20348 次
public class CRUDAction extends ActionSupport { private CRUDEntity crudEntity;//实体Bean private List<CRUDEntity> entityList; private CRUDService crudService;//实体业务类 private int cpage = 1;//默认当前页是1 private static final int pageSize = 10;//每页显示10条 public void setCrudEntity(CRUDEntity curdEntity){ this.crudEntity = curdEntity; } public CRUDEntity getCrudEntity(){ return this.crudEntity } public void setCrudService(CRUDService crudService){ this.crudService = crudService; } public CURDService getCRUDService(){ return this.crudService; } ....//其它set,get方法 /** * 分页显示实体信息 * **/ public public String list(){ entityList = crudService.pagedQuery(cpage,pageSize); return SUCCESS; } /** * 删除实体记录 * **/ public String delete(){ if(crudEntity!=null && crudEntity.getId() !=null){//首先判断不为空 crudService.deleteById(crudEntity.getId());//id是主键 } return SUCCESS; } }
<action name="list" method="list" class="crudAction"> <result>/entityManage.jsp</result> </action> <action name="delete" method="delete" class="crudAction"> <result type="redirect-action">list</result> </action>
<%@page language="java" contentType="text/html; charset=utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>资源来源管理</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> </head> <body> <table width="100%" cellspacing="0" cellpadding="0" align="center"> <tr> <th> 序号 </th> <th> 名称 </th> ... <th> 删除 </th> </tr> <s:iterator value="entityList" status="stats"> <tr> <td> <s:property value="#stats.count"/> </td> <td> <s:property value="name"/> </td> ... <td> <s:url action="delete" id="delete"> <s:param name="crudEntity.id" value="%{id}"/> </s:url> <s:a href="%{deelte}"> 删除 </s:a> </td> </tr> </s:iterator> </table> </body> </html>
<action name="list" method="list" class="crudAction"> <result>/entityManage.jsp</result> </action> <action name="show" method="list" class="crudAction"> <result>/entityManage_main.jsp</result> </action> <action name="delete" method="delete" class="crudAction"> <result type="redirect-action">show</result> </action>
<%@page language="java" contentType="text/html; charset=utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>资源来