当前位置:网站首页>解决@Valid List传参无法校验的问题
解决@Valid List传参无法校验的问题
2022-07-20 22:34:00 【Fanzongshen】
@Validated当传入list对象无法生效解决方案,直接上代码
controller层
@PostMapping("/savePersons")
public String savePersons(@Validated @RequestBody PersonListValidDTO persons) {
System.out.println(persons);
//return this.personService.save(person);
return "ok";
}
DTO层
package com.fan.dto;
import com.fan.entity.Person;
import lombok.Data;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;
/** * @author およそ神 * @version JDK 1.8 */
@Data
public class PersonListValidDTO implements Serializable {
@Valid
List<Person> list;
}
实体类
package com.fan.entity;
import java.io.Serializable;
import java.util.Date;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
/** * @author * gsxx * finished */
@Data
@NoArgsConstructor
@ApiModel(value="com.fan.entity", description="Person实体类")
public class Person implements Serializable {
/** * 编号 */
@ApiModelProperty(value = "编号")
//@NotNull(message = "id不能为空")
private Integer id;
/** * 名字 */
@ApiModelProperty(value = "名字")
@NotBlank(message = "姓名不能为空")
private String name;
/** * 年龄 */
@ApiModelProperty(value = "年龄")
//@NotNull(message = "年龄不能为空")
private Integer age;
/** * 修改人 */
@ApiModelProperty(value = "修改人")
private String updateby;
/** * 修改时间 */
@ApiModelProperty(value = "修改时间")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
private Date updatetime;
private static final long serialVersionUID = 1L;
}
边栏推荐
- 100 page slide illustration "data exit safety assessment measures" and revision comparison (download attached)
- 消息队列-Rocket基础
- 4.76 million. Targeted procurement of Bank of Hebei: F5 load balancing (10 sets)
- GameFramework——前言
- 内网探测2-PowerShell收集域信息 & 敏感资料/数据/信息收集整理
- [Baoyan] - answer to open questions in Baoyan summer camp
- 支持同花顺的证券公司怎么选?手机上开户安全吗
- C#中Internal关键字的总结
- Go语言 结构体
- STM32 serial port screen learning
猜你喜欢
Codeforces Round #808 (Div. 2)
[Flink] how to stop Flink task gracefully
Network security module B of national vocational college skills competition "comprehensive penetration test of web security"
油猴插件使用
渗透测试成功的8个关键
OneFlow v0.8.0正式发布
ython + Selenium Web自动化 2022更新版教程 自动化测试 软件测试 爬虫-笔记博客整理
Go语言 结构体
View的滑动
938. 二叉搜索树的范围和
随机推荐
Scala wordcount case
【方法】判断exe或dll是32位还是64位
Sanfeng intelligent tanghaiqin: insert smart wings for "agriculture, rural areas and farmers" and be the "leader" of smart agriculture | magnesium guest. Please go ahead
ORA-01795 列表中的最大表达式数为1000
476 万、河北银行定向采购:F5 负载均衡(10 台)
Okaleido tiger NFT is about to log in to the binance NFT platform. Are you looking forward to it?
相关性分析及SPSS软件操作
Part 131 erc20 lock up contract
Pit encountered by pl/sql
1190. 反转每对括号间的子串
c# winform 实际操作XML代码,包括创建、保存、查询、删除窗体演示
字节顺序-大端/小端、big-endian/little-endian
Scala exercises student scores case
中国 HCI 软件市场 TOP 10:华为、新华三、深信服、VMware、联想、SmartX、浪潮、青云、路坦力、曙光
ABAP语法基础
渗透测试成功的8个关键
【程序源代码】资讯小程序
Codeforces Round #808 (Div. 2)
主成分分析及SPSS的使用------笔记
Scala(二)IO流 读取文件和保存文件