Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions src/main/java/com/company/project/configurer/WebMvcConfigurer.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.company.project.configurer;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.company.project.core.Result;
import com.company.project.core.ResultCode;
import com.company.project.core.ServiceException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand All @@ -24,14 +26,13 @@
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4;
import com.company.project.core.Result;
import com.company.project.core.ResultCode;
import com.company.project.core.ServiceException;

/**
* Spring MVC 配置
Expand Down Expand Up @@ -181,7 +182,7 @@ private String getIpAddress(HttpServletRequest request) {
ip = request.getRemoteAddr();
}
// 如果是多级代理,那么取第一个ip为客户端ip
if (ip != null && ip.indexOf(",") != -1) {
if (ip != null && ip.contains(",")) {
ip = ip.substring(0, ip.indexOf(",")).trim();
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/company/project/core/Result.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Result {
private Object data;

public Result setCode(ResultCode resultCode) {
this.code = resultCode.code;
this.code = resultCode.getCode();
return this;
}

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/company/project/core/ResultCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
* 响应码枚举,参考HTTP状态码的语义
*/
public enum ResultCode {
SUCCESS(200),//成功
FAIL(400),//失败
UNAUTHORIZED(401),//未认证(签名错误)
NOT_FOUND(404),//接口不存在
INTERNAL_SERVER_ERROR(500);//服务器内部错误
SUCCESS(200), //成功
FAIL(400), //失败
UNAUTHORIZED(401), //未认证(签名错误)
NOT_FOUND(404), //接口不存在
INTERNAL_SERVER_ERROR(500);//服务器内部错误

public int code;
private int code;

ResultCode(int code) {
this.code = code;
ResultCode(int code) {
this.code = code;
}

public int getCode() {
return code;
}
}