BaseController.java
5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package com.fh.controller.base;
import java.util.List;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.session.Session;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;
import com.fh.entity.Page;
import com.fh.entity.system.User;
import com.fh.util.Const;
import com.fh.util.Jurisdiction;
import com.fh.util.Logger;
import com.fh.util.PageData;
import com.fh.util.UuidUtil;
/**
* 修改时间:2015、12、11
*/
public class BaseController {
protected Logger logger = Logger.getLogger(this.getClass());
private static final long serialVersionUID = 6357869213649815390L;
/**
* new PageData对象
*
* @return
*/
public PageData getPageData() {
return new PageData(this.getRequest());
}
/**
* 得到ModelAndView
*
* @return
*/
public ModelAndView getModelAndView() {
return new ModelAndView();
}
/**
* 得到request对象
*
* @return
*/
public HttpServletRequest getRequest() {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
return request;
}
/**
* 得到request对象
*
* @return
*/
public HttpServletResponse getResponse() {
HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getResponse();
return response;
}
/**
* 得到32位的uuid
*
* @return
*/
public String get32UUID() {
return UuidUtil.get32UUID();
}
/**
* 得到分页列表的信息
*
* @return
*/
public Page getPage() {
return new Page();
}
public static void logBefore(Logger logger, String interfaceName) {
logger.info("");
logger.info("start");
logger.info(interfaceName);
}
public static void logAfter(Logger logger) {
logger.info("end");
logger.info("");
}
public String getUsername() {
Session session = Jurisdiction.getSession();
User user = (User) session.getAttribute(Const.SESSION_USER);
if (user != null) {
return user.getUSERNAME();
}
return "ERROR";
}
public String getUserID() {
Session session = Jurisdiction.getSession();
User user = (User) session.getAttribute(Const.SESSION_USER);
if (user != null) {
return user.getUSER_ID();
}
return "ERROR";
}
public String getRole() {
Session session = Jurisdiction.getSession();
String role = (String) session.getAttribute(getUsername()
+ Const.ROLE_ID);
return role;
}
public String getTeacherID() {
Session session = Jurisdiction.getSession();
User user = (User) session.getAttribute(Const.SESSION_USER);
if (user != null) {
return user.getTeacherID();
}
return "ERROR";
}
public String getSchoolID() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.SCHOOL_ID);
return schoolName;
}
public String getSchoolName() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.SCHOOL_NAME);
return schoolName;
}
public String getGradeID() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.GRADE_ID);
return schoolName;
}
public String getGradeName() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.GRADE_NAME);
return schoolName;
}
public String getSubjectId() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.SUBJECT_ID);
return schoolName;
}
public String getSubjectName() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.SUBJECT_NAME);
return schoolName;
}
public String getClassId() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.CLASS_ID);
return schoolName;
}
public String getClassName() {
Session session = Jurisdiction.getSession();
String schoolName = (String) session.getAttribute(getUsername()
+ Const.CLASS_NAME);
return schoolName;
}
public String getCookieLanguage() {
Cookie[] cookies = getRequest().getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie.getName().equals("lang")) {
return cookie.getValue();
}
}
}
return null;
}
public String getLang() {
String lang = getCookieLanguage();
if (lang == null) {
lang = getRequest().getLocale().getLanguage();
Cookie cookies = new Cookie("lang", lang);
getResponse().addCookie(cookies);
}
return lang;
}
public boolean isChineseLanguageClient() {
String lang = getLang();
if (lang != null && lang.length() >= 2) {
lang = lang.substring(0, 2);
}
return "zh".equals(getLang());
}
/**
* 判断List中是否含有指定字符串
*/
public Integer indexOfStrInList(List<String> list,String str){
for(int i = 0 ;i<list.size();i++){
if(list.get(i).equals(str)) return i;
}
return -1;
}
}