1. I forgot that I didn't write baseaction in the previous articles. The improvement of this action is to save the development code and extract the public code in the action, the code for each system action is as follows:
package com.icss.oa.base;import java.lang.reflect.ParameterizedType;import javax.annotation.Resource;import com.icss.oa.domain.Department;import com.icss.oa.domain.User;import com.icss.oa.service.DepartmentService;import com.icss.oa.service.RoleService;import com.icss.oa.service.UserService;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public class BaseAction<T> extends ActionSupport implements ModelDriven<T> { @Resourceprotected RoleService roleService;@Resourceprotected DepartmentService departmentService ;@Resourceprotected UserService userService ;protected T model ;public BaseAction() {ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();Class clazz = (Class) pt.getActualTypeArguments()[0];try {model = (T) clazz.newInstance();} catch (InstantiationException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public T getModel() {// TODO Auto-generated method stubreturn model;} }
Note: How to Use generics? How do I obtain a class with the parameter type? How to obtain a generic instance? And how to return the model? Note that the annotation cannot be forgotten. The constructor is used here, because the constructor must be executed once.
The servcie layer of each persistence layer object needs to be injected
Baseaction of OA Project