public class BaseAction<T> extends ActionSupport implements ModelDriven<T>{

    // 1. 封装数据
private T t;
public T getModel(){
return t;
} // 1.1 实例化 t
public BaseAction(){
try{
// 得到当前运行类的 Class
Class c = this.getClass();
ParameterizedType ptype = (ParameterizedType)c.getGenericSuperclass(); Type[] types = ptype.getActualTypeArguments();
Class<T> clazz = (Class<T>)types[0]; t = clazz.newInstance();
} catch(Exception e){
throw new RuntimeException(e);
}
} // 2. Spring 注入 service, 多个
// 提供 set 方法, 让 spring 进行注入的;
// 提供 get 方法, 让子类可以获得 spring 注入的对象
private CustomerService customerService;
public void setCustomerService(CustomerService customerService){
this.customerService = customerService;
}
public CustomerService getCustomerService(){
return customerService;
} // 3. 分页数据
private Integer pageCode = 1; // 第几页
public void setPageCode(Integer pageCode){
if(pageCode == null){
pageCode = 1;
}
this.pageCode = pageCode;
}
public Integer getPageCode(){
return pageCode;
} private Integer pageSize = 2; // 每页显示数据的条数
public void setPageSize(Integer pageSize){
this.pageSize = pageSize;
}
public Integer getPageSize(){
return pageSize;
} // 4. 简化值栈操作
public void push(Object obj){
ActionContext.getContext().getValueStack().push(obj);
} public void set(String key, Object obj){
ActionContext.getContext().getValueStack().set(key,obj);
} public void put(String key, Object obj){
ActionContext.getContext().put(key,obj);
} public void putSession(String key, Object obj){
ActionContext.getContext().getSession().put(key,value);
} public void putApplication(String key, Object obj){
ActionContext.getContext().getApplication().put(key,value);
}
}

BaseAction 类的更多相关文章

  1. zTree实现地市县三级级联Action类

    zTree实现地市县三级级联Action类 ProvinceAction.java: /** * @Title:ProvinceAction.java * @Package:com.gwtjs.str ...

  2. Java类的继承与多态特性-入门笔记

    相信对于继承和多态的概念性我就不在怎么解释啦!不管你是.Net还是Java面向对象编程都是比不缺少一堂课~~Net如此Java亦也有同样的思想成分包含其中. 继承,多态,封装是Java面向对象的3大特 ...

  3. strust2中使用session

    在Struts2里,如果需要在Action中使用session,可以通过下面两种方式得到1.通过ActionContext class中的方法getSession得到2.Action实现org.apa ...

  4. SSH:Struts2.2+Hibernate3.6+Spring3.1分页示例[转]

    参考资料 1 ssh分页(多个例子) http://useryouyou.iteye.com/blog/593954 2 ssh2分页例子 http://459104018-qq-com.iteye. ...

  5. struts2: config-browser-plugin 与 convention-plugin 学习

    struts2被很多新手诟病的一个地方在于“配置过于复杂”,相信不少初学者因为这个直接改投Spring-MVC了.convention-plugin. config-browser-plugin这二个 ...

  6. 国家电力项目SSH搭建

    SSH项目框架搭建总结: 1.建立Web工程 * 导入需要的jar的包 db:连接数据库的驱动包 hibernate:使用hibernate的jar包 jstl:java的标准标签库 junit:测试 ...

  7. 在某公司时的java开发环境配置文档

    1 开发环境配置 1.1.  MyEclipse 配置 1.MyEclipse下载地址:\\server\共享文件\backup\MyEclipse9.0 2.修改工作空间编码为UTF-8,如下图 3 ...

  8. struts2动态方法

    动态方法调用 在Struts2中动态方法调用有三种方式,动态方法调用就是为了解决一个Action对应多个请求的处理,以免Action太多 第一种方式:指定method属性 这种方式我们前面已经用到过, ...

  9. SSH电力项目

    第一步:创建测试表Elec_Text: create table Elec_Text(textID varchar(50) not null primary key,textName varchar( ...

随机推荐

  1. log4j 具体解说(不能再具体了)

    日志是应用软件中必不可少的部分.Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录.在apache站点:jakarta.apache.org/log4j 能够免费下载到Log ...

  2. iptables 使用

    原文链接 本文介绍25个常用的iptables用法.如果你对iptables还不甚了解,可以参考上一篇iptables详细教程:基础.架构.清空规则.追加规则.应用实例,看完这篇文章,你就能明白ipt ...

  3. Makefile 自动变量之 $(@D),$(@F)

    参考:http://www.gnu.org/software/make/manual/make.html '$(@D)'The directory part of the file name of t ...

  4. Spring事务的隔离级别

    1.  ISOLATION_DEFAULT: 这是一个 PlatfromTransactionManager  默认的隔离级别,使用数据库默认的事务隔离级别. 另外四个与 JDBC的隔离级别相对应: ...

  5. linux学习笔记24---命令grep

    Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是global search regular expression(RE) and ...

  6. zookeeper安装与集群搭建

    此处以centos系统下zookeeper安装为例,详细步骤可参考官网文档:zookeeper教程 一.单节点部署 1.下载zookeeper wget http://mirrors.hust.edu ...

  7. 【黑马Android】(04)数据库的创建和sql语句增删改查/LinearLayout展示列表数据/ListView的使用和BaseAdater/内容提供者创建

    数据库的创建和sql语句增删改查 1. 载入驱动. 2. 连接数据库. 3. 操作数据库. 创建表: create table person( _id integer primary key, nam ...

  8. Iptables规则执行顺序详解

      1.The first is the mangle table which is responsible for the alteration of quality of service bits ...

  9. Class.forName(String className)这个方法的作用

    Class.forName(String className)这个方法的作用 解答:通过类的全名获得该类的类对象

  10. jQuery学习笔记1——操作属性

    一.获得和设置内容 三个简单实用的用于 DOM 操作的 jQuery 方法: text() - 设置或返回所选元素的文本内容, 得到匹配元素集合中每个元素的文本内容结合,包括他们的后代, 即由所有匹配 ...