package com.ssh.demo.action; |
02 |
03 |
import java.io.InputStream; |
04 |
import java.lang.reflect.ParameterizedType; |
05 |
import java.util.List; |
06 |
import java.util.Map; |
07 |
08 |
import javax.annotation.Resource; |
09 |
10 |
import org.apache.struts2.interceptor.ApplicationAware; |
11 |
import org.apache.struts2.interceptor.RequestAware; |
12 |
import org.apache.struts2.interceptor.SessionAware; |
13 |
14 |
import com.opensymphony.xwork2.ActionSupport; |
15 |
import com.opensymphony.xwork2.ModelDriven; |
16 |
import com.ssh.demo.service.UserService; |
17 |
18 |
@SuppressWarnings ( "unchecked" ) |
19 |
public class BaseAction<T> extends ActionSupport implements RequestAware, |
20 |
SessionAware,
ApplicationAware, ModelDriven<T> { |
21 |
22 |
protected T
model; //
model 有可能为 user,student,teacher等等........ |
23 |
protected Map<String,
Object> jsonMap = null ; |
24 |
protected List<T>
jsonList = null ; |
25 |
protected InputStream
inputStream = null ; |
26 |
protected Map<String,
Object> application; |
27 |
protected Map<String,
Object> session; |
28 |
protected Map<String,
Object> request; |
29 |
30 |
@Resource |
31 |
protected UserService
userService; |
32 |
/** |
33 |
*
通过反射动态的创建对象 |
34 |
*/ |
35 |
public BaseAction()
{ |
36 |
ParameterizedType
type = (ParameterizedType) this .getClass() |
37 |
.getGenericSuperclass(); |
38 |
Class
clazz = (Class) type.getActualTypeArguments()[ 0 ]; |
39 |
try { |
40 |
model
= (T) clazz.newInstance(); |
41 |
} catch (Exception
e) { |
42 |
throw new RuntimeException(e); |
43 |
} |
44 |
} |
45 |
46 |
@Override |
47 |
public T
getModel() { |
48 |
return model; |
49 |
} |
50 |
51 |
public void setJsonMap(Map<String,
Object> jsonMap) { |
52 |
this .jsonMap
= jsonMap; |
53 |
} |
54 |
55 |
public Map<String,
Object> getJsonMap() { |
56 |
return jsonMap; |
57 |
} |
58 |
59 |
public List<T>
getJsonList() { |
60 |
return jsonList; |
61 |
} |
62 |
63 |
public void setJsonList(List<T>
jsonList) { |
64 |
this .jsonList
= jsonList; |
65 |
} |
66 |
67 |
public InputStream
getInputStream() { |
68 |
return inputStream; |
69 |
} |
70 |
71 |
public void setInputStream(InputStream
inputStream) { |
72 |
this .inputStream
= inputStream; |
73 |
} |
74 |
75 |
@Override |
76 |
public void setApplication(Map<String,
Object> application) { |
77 |
this .application
= application; |
78 |
} |
79 |
80 |
@Override |
81 |
public void setSession(Map<String,
Object> session) { |
82 |
this .session
= session; |
83 |
} |
84 |
85 |
@Override |
86 |
public void setRequest(Map<String,
Object> request) { |
87 |
this .request
= request; |
88 |
} |
89 |
} |