java - 在 Get 方法中验证 DTO
问题描述
我想将 DTO 传递给 Get 方法:
@GetMapping
public void my_get(MyDto myDto){
}
上面的代码工作正常,但字段验证不起作用。
@Data
@AllArgsConstructor
@NoArgsConstructor
public class MyDto {
@NotNull
@NotBlank(message = ValidateConstant.NOT_BLANK_MESSAGE)
String id;
String uri;
String type;
String version;
}
我还添加@Valid
了注释,但 Get 方法也返回 200 作为响应。
解决方案
添加@Valid
注释
public void my_get(@Valid MyDto myDto){
如果这没有帮助,@Validated
请在班级级别添加。
推荐阅读
- flutter - 小部件未在提供程序变量更改时重绘 - Flutter
- python - Python:记录键盘并检测窗口变化(WIN10)
- git - 如何在提交后将当前提交引用放入我的 tex 文件中?
- javascript - Discord.js 的事件处理程序中的代码未按需要运行
- excel - Excel数据提取问题
- javascript - VueJS:在同一组件的两个实例之间切换的最佳方式
- c# - 从 FileName 获取日期并保留为变量 DateTime
- ajax - Ember-qunit 单元测试失败,全局错误 Ajax 中止
- conv-neural-network - 特征图中的每个单元都连接到前一层的几个邻域
- angular - 角手柄从虚拟滚动数组中删除项目