使用@Validated 和 BindingResult 遇到的坑及解决
作者:dolphin0516 时间:2022-12-18 20:36:28
@Validated和BindingResult 使用遇到的坑
@Validated 与BindingResult 需要相邻,否则 变量result 不能接受错误信息
控制台输出
Field error in object 'entity' on field '变量': rejected value [null]; codes [NotNull.entity.变量,NotNull.变量,NotNull.java.lang.String,NotNull]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes
正确的内容截图
@Validated @Valid三种异常捕获处理
异常共三种
BindException
:表单提交有效,对于以json格式提交将会失效MethodArgumentNotValidException
:前段以json格式有效ConstraintViolationException
:参数上加@RequestParam或参数加@NotBlank @NotNull等
来源:https://blog.csdn.net/weixin_43849519/article/details/103626739
标签:@Validated,BindingResult
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
基于SpringBoot中activeMq的JmsTemplate的实例
2021-11-04 15:36:34
Java字符串查找的三种方式
2023-11-18 22:00:30
Android Framework如何实现Binder
2021-12-09 03:54:20
Java使用线程同步解决线程安全问题详解
2022-02-28 02:03:24
![](https://img.aspxhome.com/file/2023/9/78029_0s.png)
C#使用opencv截取旋转矩形区域图像的实现示例
2023-11-12 22:20:44
![](https://img.aspxhome.com/file/2023/2/70412_0s.png)
Java网络编程TCP实现聊天功能
2023-12-01 17:05:35
![](https://img.aspxhome.com/file/2023/1/103851_0s.jpg)
c++ 预处理的图灵完备之引言
2023-02-20 01:37:20
解析在内部循环中Continue外部循环的使用详解
2023-09-24 08:03:50
Android自定义View基础开发之图片加载进度条
2022-05-01 05:52:14
![](https://img.aspxhome.com/file/2023/6/138126_0s.jpg)
Java中Maven项目导出jar包配置的示例代码
2023-01-26 20:09:32
Flutter源码分析之自定义控件(RenderBox)指南
2022-09-08 21:17:28
![](https://img.aspxhome.com/file/2023/5/123345_0s.png)
Java中包装类介绍与其注意事项
2023-03-20 18:26:36
![](https://img.aspxhome.com/file/2023/0/62810_0s.png)
Android Notification使用方法详解
2023-12-14 13:03:17
Android通过Handler与AsyncTask两种方式动态更新ListView(附源码)
2022-04-14 03:32:22
Java中Runnable与Callable接口的区别详解
2021-12-22 11:33:28
Java流程控制语句之If选择结构
2023-11-11 04:02:29
![](https://img.aspxhome.com/file/2023/3/58853_0s.png)
Unity2019-2020 个人版官方免费激活详细方法
2023-12-08 21:57:39
![](https://img.aspxhome.com/file/2023/4/81364_0s.png)
初识Spring Boot框架和快速入门
2022-10-17 00:58:52
![](https://img.aspxhome.com/file/2023/2/97932_0s.png)
Android数字华容道小游戏开发
2023-10-06 22:31:35
![](https://img.aspxhome.com/file/2023/1/92611_0s.png)
Android项目实战之ListView悬浮头部展现效果实现
2022-08-11 16:35:32
![](https://img.aspxhome.com/file/2023/9/114359_0s.gif)