完善框架结构,解决了validation和saToken的问题
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.guo.learningprogresstracker.common;
|
||||
|
||||
import com.guo.learningprogresstracker.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.exception.AppException;
|
||||
import com.guo.learningprogresstracker.exception.ErrorParameterException;
|
||||
import com.guo.learningprogresstracker.exception.NotFindEntitiesException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||
|
||||
|
||||
/**
|
||||
* @author guo
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler({ErrorParameterException.class})
|
||||
@ResponseBody
|
||||
public CommonResult errorParameterException(ErrorParameterException ex){
|
||||
//code:400
|
||||
return CommonResult.error(ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler({NotFindEntitiesException.class})
|
||||
@ResponseBody
|
||||
public CommonResult notFindEntitiesException(NotFindEntitiesException ex){
|
||||
//code:400
|
||||
return CommonResult.error(ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler({AppException.class})
|
||||
@ResponseBody
|
||||
public CommonResult AppException(AppException ex){
|
||||
//code:500
|
||||
return CommonResult.serverError(ex.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseBody
|
||||
public CommonResult MyMethodArgumentNotValidException(MethodArgumentNotValidException ex){
|
||||
BindingResult bindingResult = ex.getBindingResult();
|
||||
//code:400
|
||||
return CommonResult.error(bindingResult.getFieldError().getDefaultMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.guo.learningprogresstracker.common;
|
||||
|
||||
import jakarta.validation.groups.Default;
|
||||
|
||||
/**
|
||||
* 全局数据验证分组
|
||||
* GlobalValidationGroup -> OpenGroups ->ops
|
||||
* @author guo
|
||||
*/
|
||||
public interface Ops {
|
||||
// 创建组
|
||||
interface CreateG extends Default {}
|
||||
// 更新组
|
||||
interface UpdateG {}
|
||||
}
|
||||
Reference in New Issue
Block a user