Commit 41d942a9e08a1acafcab8c9ba55b4119c006bdeb

Authored by maliang
1 parent f62436cb15
Exists in master

同步代码

Showing 1 changed file with 43 additions and 43 deletions

core.sdk/src/main/java/com/lyms/web/controller/BaseController.java View file @ 41d942a
... ... @@ -14,6 +14,7 @@
14 14  
15 15 import org.slf4j.Logger;
16 16 import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
17 18 import org.springframework.beans.propertyeditors.CustomDateEditor;
18 19 import org.springframework.util.StringUtils;
19 20 import org.springframework.web.bind.ServletRequestDataBinder;
20 21  
... ... @@ -34,10 +35,10 @@
34 35  
35 36 protected Logger logger = LoggerFactory.getLogger(this.getClass());
36 37  
37   - // @Autowired
  38 + @Autowired
38 39 protected HttpServletRequest request;
39 40  
40   - // @Autowired
  41 + @Autowired
41 42 protected HttpServletResponse response;
42 43  
43 44 @InitBinder
44 45  
... ... @@ -316,48 +317,47 @@
316 317 }
317 318 return new MobileInfo(appVersion, systemVersion, deviceId, width, height, night != 0);
318 319 }
319   -
320   - /**
321   - * <li>@Description:获取客户端IP
322   - * <li>@param request
323   - * <li>@return
324   - * <li>创建人:方承
325   - * <li>创建时间:2016年11月26日
326   - * <li>修改人:
327   - * <li>修改时间:
328   - */
329   - public static final String getHost(HttpServletRequest request) {
330   - String ip = request.getHeader("X-Forwarded-For");
331   - if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
332   - ip = request.getHeader("Proxy-Client-IP");
333   - }
334   - if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
335   - ip = request.getHeader("WL-Proxy-Client-IP");
336   - }
337   - if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
338   - ip = request.getHeader("X-Real-IP");
339   - }
340   - if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
341   - ip = request.getRemoteAddr();
342   - }
343   - if ("127.0.0.1".equals(ip)) {
344   - InetAddress inet = null;
345   - try { // 根据网卡取本机配置的IP
346   - inet = InetAddress.getLocalHost();
347   - } catch (UnknownHostException e) {
348   - e.printStackTrace();
349   - }
350   - ip = inet.getHostAddress();
351   - }
352   - // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
353   - if (ip != null && ip.length() > 15) {
354   - if (ip.indexOf(",") > 0) {
355   - ip = ip.substring(0, ip.indexOf(","));
356   - }
357   - }
358   - return ip;
359   - }
360 320  
  321 + /**
  322 + * <li>@Description:获取客户端IP
  323 + * <li>@param request
  324 + * <li>@return
  325 + * <li>创建人:方承
  326 + * <li>创建时间:2016年11月26日
  327 + * <li>修改人:
  328 + * <li>修改时间:
  329 + */
  330 + public static final String getHost(HttpServletRequest request) {
  331 + String ip = request.getHeader("X-Forwarded-For");
  332 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  333 + ip = request.getHeader("Proxy-Client-IP");
  334 + }
  335 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  336 + ip = request.getHeader("WL-Proxy-Client-IP");
  337 + }
  338 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  339 + ip = request.getHeader("X-Real-IP");
  340 + }
  341 + if (StrUtils.isBlank(ip) || "unknown".equalsIgnoreCase(ip)) {
  342 + ip = request.getRemoteAddr();
  343 + }
  344 + if ("127.0.0.1".equals(ip)) {
  345 + InetAddress inet = null;
  346 + try { // 根据网卡取本机配置的IP
  347 + inet = InetAddress.getLocalHost();
  348 + } catch (UnknownHostException e) {
  349 + e.printStackTrace();
  350 + }
  351 + ip = inet.getHostAddress();
  352 + }
  353 + // 对于通过多个代理的情况,第一个IP为客户端真实IP,多个IP按照','分割
  354 + if (ip != null && ip.length() > 15) {
  355 + if (ip.indexOf(",") > 0) {
  356 + ip = ip.substring(0, ip.indexOf(","));
  357 + }
  358 + }
  359 + return ip;
  360 + }
361 361  
362 362 }