Commit 1c058bce by danmo

分类bug修改

1 parent aa0949bc
...@@ -3,8 +3,13 @@ package com.linkwechat.web.controller.wecom; ...@@ -3,8 +3,13 @@ package com.linkwechat.web.controller.wecom;
import com.linkwechat.common.core.domain.AjaxResult; import com.linkwechat.common.core.domain.AjaxResult;
import com.linkwechat.common.exception.wecom.WeComException; import com.linkwechat.common.exception.wecom.WeComException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
/** /**
* @author danmo * @author danmo
...@@ -20,6 +25,17 @@ public class WeExceptionController { ...@@ -20,6 +25,17 @@ public class WeExceptionController {
return AjaxResult.error(ex.getCode(),ex.getMessage()); return AjaxResult.error(ex.getCode(),ex.getMessage());
} }
@ExceptionHandler({MethodArgumentNotValidException.class})
public AjaxResult customException(MethodArgumentNotValidException e) {
// 获取参数校验失败信息
List<ObjectError> list = e.getBindingResult().getAllErrors();
StringBuilder errorMsg = new StringBuilder();
for (ObjectError error : list){
errorMsg.append(error.getDefaultMessage()).append("\n");
}
return AjaxResult.error(errorMsg.toString());
}
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public AjaxResult runtimeException(Exception ex){ public AjaxResult runtimeException(Exception ex){
log.error("接口异常拦截 ex:{}",ex); log.error("接口异常拦截 ex:{}",ex);
......
linkwechat.nacos.host=119.45.28.29
linkwechat.nacos.port=10848
linkwechat.nacos.namespace=627a666a-76b2-42ad-a1b0-70a12d2c73fd
linkwechat.nacos.username=nacos
linkwechat.nacos.password=jerryjin666
\ No newline at end of file \ No newline at end of file
linkwechat.nacos.host=
linkwechat.nacos.port=
linkwechat.nacos.namespace=
linkwechat.nacos.username=
linkwechat.nacos.password=
\ No newline at end of file \ No newline at end of file
...@@ -12,6 +12,7 @@ import lombok.Data; ...@@ -12,6 +12,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
@Data @Data
@TableName("we_category") @TableName("we_category")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!