Baseaction of OA Project

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.