Action层代码封装模板
来源:互联网 发布:淘宝店招设计素材 编辑:程序博客网 时间:2024/06/05 06:19
模板action
package cn.jxlg.oa.util;
import java.lang.reflect.ParameterizedType;
import javax.annotation.Resource;
import cn.jxlg.oa.domain.User;
import cn.jxlg.oa.service.DepartmentService;
import cn.jxlg.oa.service.ForumService;
import cn.jxlg.oa.service.PrivilegeService;
import cn.jxlg.oa.service.ReplyService;
import cn.jxlg.oa.service.RoleService;
import cn.jxlg.oa.service.TopicService;
import cn.jxlg.oa.service.UserService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public abstract class BaseAction<T> extends ActionSupport implements
ModelDriven<T> {
// =============== ModelDriven的支持 ==================
protected T model;
public BaseAction() {
try {
// 通过反射获取model的真实类型
ParameterizedType pt = (ParameterizedType) this.getClass()
.getGenericSuperclass();
Class<T> clazz = (Class<T>) pt.getActualTypeArguments()[0];
// 通过反射创建model的实例
model = clazz.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public T getModel() {
return model;
}
// =============== Service实例的声明 ==================
@Resource
protected RoleService roleService;
@Resource
protected DepartmentService departmentService;
@Resource
protected UserService userService;
@Resource
protected PrivilegeService privilegeService;
@Resource
protected ForumService forumService;
@Resource
protected TopicService topicService;
@Resource
protected ReplyService replyService;
/**
* 获取当前登录的用户
*
* @return
*/
protected User getCurrentUser() {
return (User) ActionContext.getContext().getSession().get("user");
}
// ============== 分页用的参数 =============
protected int pageNum = 1; // 当前页
protected int pageSize = 10; // 每页显示多少条记录
public int getPageNum() {
return pageNum;
}
public void setPageNum(int pageNum) {
this.pageNum = pageNum;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
}
使用案例
public class ForumAction extends BaseAction {}
- Action层代码封装模板
- DAO层接口代码封装模板
- DAO层实现代码封装模板
- 增删改(Action层)模板
- 增删改(Action层)模板
- dorado pr/action 层数据处理模板
- 弹出层(封装代码)
- java web ssh 整合封装Action Service Dao 层
- 如果在Action层和DAO层之间不使用Biz层,Action层的代码量将变大
- Struts2 Result-type(封装Action层到View层的跳转逻辑)
- Jeecms6中后台控制层Action如何将值传入前台视图层模板中的?
- 封装模板
- 批量删除,可作为JDBC DAO层模板代码
- 关于持久层和业务层代码封装的一点点设计
- dao层 service层 action层
- 数据库层封装
- 数据库层封装
- Android网络层封装
- HDU(1850) Being a Good Boy in Spring Festival (博弈)
- Vizrt数据处理中的终极武器之SMM-Shared Memory Map
- HDU(1517)A Multiplication Game(博弈)
- php 常用正则表达式
- HDU(1849)Rabbit and Grass(博弈)
- Action层代码封装模板
- HDU(2188)悼念512汶川大地震遇难同胞——选拔志愿者
- FZU Problem 1534 阿甘的珠宝 (博弈)
- 程序的可移植性——字长/不透明数据/数据对齐/大小端
- HDU(1536)S-Nim (博弈)
- HDU(1867)A + B for you again (KMP)
- Codeforces Round #106 (Div. 2) 149/E E. Martian Strings
- HDU(4522) 湫湫系列故事——过年回家
- HDU(2955)Robberies (0-1背包)