Commit 15158aee by Suvalue

参数空值判断

parent cd19c234
...@@ -66,6 +66,10 @@ public class Result<T> { ...@@ -66,6 +66,10 @@ public class Result<T> {
return new Result(ErrorCode.ERROR.getCode(), ErrorCode.ERROR.getEnMessage(), null); return new Result(ErrorCode.ERROR.getCode(), ErrorCode.ERROR.getEnMessage(), null);
} }
public static Result error(String msg){
return new Result(ErrorCode.ERROR.getCode(), msg, null);
}
public static Result error(ErrorCode errorCode){ public static Result error(ErrorCode errorCode){
return new Result(errorCode.getCode(), errorCode.getEnMessage(), null); return new Result(errorCode.getCode(), errorCode.getEnMessage(), null);
} }
......
...@@ -5,13 +5,20 @@ import com.bsoft.api.common.exceptions.DBConfigurationError; ...@@ -5,13 +5,20 @@ import com.bsoft.api.common.exceptions.DBConfigurationError;
import com.bsoft.api.common.exceptions.ExceptionBase; import com.bsoft.api.common.exceptions.ExceptionBase;
import com.bsoft.api.common.exceptions.InvalidTokenException; import com.bsoft.api.common.exceptions.InvalidTokenException;
import com.bsoft.common.utils.HttpUtil; import com.bsoft.common.utils.HttpUtil;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/** /**
* 全局异常处理类 * 全局异常处理类
...@@ -34,6 +41,26 @@ public class GlobalExceptionHandler { ...@@ -34,6 +41,26 @@ public class GlobalExceptionHandler {
return Result.error(); return Result.error();
} }
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseBody
public Object MethodArgumentNotValidErrorHandler(HttpServletRequest request, MethodArgumentNotValidException e){
String url = request.getRequestURI();
BindingResult bindingResult = e.getBindingResult();
List<ObjectError> allErrors = bindingResult.getAllErrors();
StringBuilder errorStrBu = new StringBuilder();
allErrors.forEach(objectError -> {
FieldError fieldError = (FieldError) objectError;
errorStrBu.append(fieldError.getDefaultMessage());
errorStrBu.append(",");
});
String errorStr = errorStrBu.toString();
log.error(url + "请求未知异常:" + e.getMessage(), e);
return Result.error(errorStr.substring(0,errorStr.length()-1));
}
/** /**
* 其他内部异常 * 其他内部异常
* @param request * @param request
......
...@@ -3,6 +3,8 @@ package com.bsoft.api.model.reqmodel; ...@@ -3,6 +3,8 @@ package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@ApiModel(description = "调用blockValues请求的数据") @ApiModel(description = "调用blockValues请求的数据")
public class BlockValues { public class BlockValues {
...@@ -56,5 +58,6 @@ public class BlockValues { ...@@ -56,5 +58,6 @@ public class BlockValues {
@ApiModelProperty("医生") @ApiModelProperty("医生")
private Integer doctor; private Integer doctor;
@ApiModelProperty("时间") @ApiModelProperty("时间")
@NotNull(message = "time 参数必传")
private Integer time; private Integer time;
} }
...@@ -2,10 +2,12 @@ package com.bsoft.api.model.reqmodel; ...@@ -2,10 +2,12 @@ package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.util.Map; import java.util.Map;
public class BlockValuesNew { public class BlockValuesNew {
@ApiModelProperty(value = "pageCode",required = true) @ApiModelProperty(value = "pageCode",required = true)
@NotNull(message = "pageCode 参数必传")
private Integer pageCode; private Integer pageCode;
@ApiModelProperty("维度查询值") @ApiModelProperty("维度查询值")
private Map<String,String> dim; private Map<String,String> dim;
......
...@@ -3,10 +3,14 @@ package com.bsoft.api.model.reqmodel; ...@@ -3,10 +3,14 @@ package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@ApiModel("账号密码") @ApiModel("账号密码")
public class CodeAndPwd { public class CodeAndPwd {
@ApiModelProperty(value="账号",required = true) @ApiModelProperty(value="账号",required = true)
@NotNull(message = "账号 参数必传")
String loginName; String loginName;
@NotNull(message = "密码 参数必传")
@ApiModelProperty(value="密码",required = true) @ApiModelProperty(value="密码",required = true)
String password; String password;
......
...@@ -2,6 +2,7 @@ package com.bsoft.api.model.reqmodel; ...@@ -2,6 +2,7 @@ package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
public class Disease { public class Disease {
...@@ -11,6 +12,7 @@ public class Disease { ...@@ -11,6 +12,7 @@ public class Disease {
public static class DiseaseIDorLevel { public static class DiseaseIDorLevel {
@ApiModelProperty(value = "时间",required = true) @ApiModelProperty(value = "时间",required = true)
@NotNull(message = "date 参数必传")
private String date; private String date;
@ApiModelProperty(value = "疾病编码",required = false) @ApiModelProperty(value = "疾病编码",required = false)
private String disease; private String disease;
......
...@@ -3,6 +3,7 @@ package com.bsoft.api.model.reqmodel; ...@@ -3,6 +3,7 @@ package com.bsoft.api.model.reqmodel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
...@@ -17,6 +18,7 @@ public class DiseaseDoc { ...@@ -17,6 +18,7 @@ public class DiseaseDoc {
@ApiModelProperty("科室编码") @ApiModelProperty("科室编码")
private String deptCode; private String deptCode;
@ApiModelProperty(value = "时间",required = true) @ApiModelProperty(value = "时间",required = true)
@NotNull(message = "date 参数必传")
private String date; private String date;
public String getDate() { public String getDate() {
......
...@@ -7,11 +7,12 @@ import javax.validation.constraints.NotNull; ...@@ -7,11 +7,12 @@ import javax.validation.constraints.NotNull;
public class ReqDimValue { public class ReqDimValue {
@ApiModelProperty(value = "pageCode",required = true) @ApiModelProperty(value = "pageCode",required = true)
@NotNull(message = "pageCode 参数必传")
private String pageCode; private String pageCode;
@ApiModelProperty("机构id") @ApiModelProperty("机构id")
private Long orgId; private Long orgId;
@ApiModelProperty("时间") @ApiModelProperty("时间")
@NotNull @NotNull(message = "date 参数必传")
private String date; private String date;
public String getPageCode() { public String getPageCode() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment