标签:public lombok ping res date 控制器 getname 展示 ret
## 正常
{
"id": 14,
"name": "张三",
"sex": "男"
}
## 姓名不能为空
{
"code": -1,
"message": "姓名不能为空",
"data": null
}
## 性别不能为空
{
"code": -1,
"message": "性别不能为空",
"data": null
}
// 实体类
@Data
@Validated
public class StudentVo {
private Integer id;
@NotNull(message = "姓名不能为空")
private String name;
@NotNull(message = "性别不能为空")
private String sex;
}
// 控制器
@RestController
@RequestMapping("/stu")
public class StudentController {
@PostMapping("/getUser")
public StudentVo studentVo(@Valid @RequestBody StudentVo studentVo) {
StudentVo studentVo1 = new StudentVo();
studentVo1.setId(studentVo.getId());
studentVo1.setName(studentVo.getName());
studentVo1.setSex(studentVo.getSex());
return studentVo1;
}
}
标签:public lombok ping res date 控制器 getname 展示 ret
原文地址:https://www.cnblogs.com/Twittery/p/14818301.html