Springmvc参数校验
springMVC 的基本参数校验
使用@RequestParam 注解控制请求参数
@GetMapping("/hello")
public Response sayHello(@RequestParam String hello,long start) {
return Response.success(hello);
} @ExceptionHandler
public Response exceptionMatchHandle(Exception e){
//参数绑定异常 SpringMVC异常
if (e instanceof ServletRequestBindingException){
log.error("发生了SpringMVC异常:{}",e.getMessage());
if (e instanceof MissingRequestHeaderException){
return Response.failure(ErrorCode.ERROR_PARMS_NO_HEADER);
}
return Response.failure(ErrorCode.ERROR_PARMS_NO_PARM);
}
}@RequestParam的使用
使用JSR-303验证框架
如何使用验证框架
相关注解
如何使用
框架的高级用法
框架的扩展
自定义校验
结语
最后更新于