zoukankan      html  css  js  c++  java
  • struts2的BaseAction<T>继承ActionSupport实现ModelDriven<T>

    public class BaseAction<T> extends ActionSupport implements ModelDriven<T> {
    
        private static final long                serialVersionUID    = 1L;
        protected T                                model;
        //页面表单映射到model相当于struts1的formbean
    
        //将所有的service写入到BaseAction中
        @Resource protected RoleService            roleService;
        @Resource protected DepartmentService    departmentService;
        @Resource protected UserService            userService;
        @Resource protected PrivilegeService    privilegeService;
    
        // 页码默认为第1页
        protected int                            pageNum                = 1;
    
        @SuppressWarnings({ "rawtypes", "unchecked" })
        public BaseAction() {
            try {
                // 得到model的类型信息
                ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass();
                Class clazz = (Class) type.getActualTypeArguments()[0];
                // 通过反射生成model的实例
                model = (T) clazz.newInstance();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
    
        }
    
        public T getModel() {
            return model;
        }
    }
  • 相关阅读:
    生产环境经常用到的命令
    JDK 安装部署
    oracle备份脚本
    HTTP与HTTPS的区别
    TCP和UDP的优缺点及区别
    Web服务器优化
    DDOS攻击的三种常见方式
    Xss Csrf DDOS sql注入及防范
    session共享
    Cookie防伪造防修改
  • 原文地址:https://www.cnblogs.com/sallet/p/3962316.html
Copyright © 2011-2022 走看看