当前位置:网站首页>Solve the problem that @valid list parameters cannot be verified
Solve the problem that @valid list parameters cannot be verified
2022-07-21 17:10:00 【Fanzongshen】
@Validated When it comes to list Object cannot take effect solution , Go straight to the code
controller layer
@PostMapping("/savePersons")
public String savePersons(@Validated @RequestBody PersonListValidDTO persons) {
System.out.println(persons);
//return this.personService.save(person);
return "ok";
}
DTO layer
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 およそ god * @version JDK 1.8 */
@Data
public class PersonListValidDTO implements Serializable {
@Valid
List<Person> list;
}
Entity class
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 Entity class ")
public class Person implements Serializable {
/** * Number */
@ApiModelProperty(value = " Number ")
//@NotNull(message = "id Can't be empty ")
private Integer id;
/** * name */
@ApiModelProperty(value = " name ")
@NotBlank(message = " Name cannot be empty ")
private String name;
/** * Age */
@ApiModelProperty(value = " Age ")
//@NotNull(message = " Age cannot be empty ")
private Integer age;
/** * Modifier */
@ApiModelProperty(value = " Modifier ")
private String updateby;
/** * Modification time */
@ApiModelProperty(value = " Modification time ")
@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;
}
边栏推荐
- Ython + selenium web automation 2022 updated tutorial automated testing software test crawler - Notes blog collation
- 今年,熬下去,才有盼头
- 泄漏电流、无接地保护措施……1296个进口电热水壶存在重大安全隐患
- 【NOI2020】制作菜品(构造,结论,背包DP,bitset优化)
- First meet shadowless cloud computer
- "Cloud primitives kubernetes" deeply analyzes the principle of pod in kubernetes
- Monitor Deep Learning Training Progress
- When using mysql, please make good use of JSON
- Scala (II) IO stream read file and save file
- 1190. Invert the substring between each pair of parentheses
猜你喜欢
1744. Can you eat your favorite candy on your favorite day?
16个你要注意的SQL注入测试点
1486. 数组异或操作
[guaranteed research] - sort out and share the problems existing in the previous school reexamination interview
554. Brick wall
740. 删除并获得点数
Games101 graphics p12 notes (geometry3)
全国职业院校技能大赛网络安全B模块 “web安全之综合渗透测试”
Redis内存模型讲解
APP 页面秒开优化方面总结~
随机推荐
Kubernetes Service 负载均衡实现机制
LeetCode 1260 二维网格迁移[数组] HERODING的LeetCode之路
王者荣耀商城异地多活架构设计(架构实战营 模块七作业)
有没有完全自主的国产化数据库技术
kubelet工作原理
How project managers do a good job in "boss" projects
vscode setting.json
1011. 在 D 天内送达包裹的能力
BCG grid control sets color separately
"Cloud primitives kubernetes" deeply analyzes the principle of pod in kubernetes
Typescript函数扩展使用
Gameframework - Preface
How to do well in test management?
Splunk HEC opens 8088 port
Principal component analysis and the use of SPSS ----- notes
Monitor Deep Learning Training Progress
Scala (II) IO stream read file and save file
My SQL is OK. Why is it still so slow? MySQL locking rules
[interview: concurrent Article 19: multithreading: Park & unpark]
Shell 脚本特殊变量列表