我正在尝试使用“www.example.com“jar对REST请求进行验证hibernate-validator-5.1.3.final。我可以为外部bean进行验证,但不能为内部bean进行验证。因此,任何人都可以帮助我进行验证。提前感谢。
通过 Postman 请求
{
"employeeDetails": [{
"employeeId": "123456",
"dept" : 101,
"salary" : 30000,
"status":"active"
}]
}
pom.xml文件
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.3.Final</version>
</dependency>
控制器
@RequestMapping(method = RequestMethod.POST, value = "/addEmployee", headers = "Accept=application/json")
public @ResponseBody void addEmployee(
@RequestHeader @Valid @RequestBody AddEmployeeBean requestBean,
HttpServletRequest httpRequest) {.....}
外部Bean -添加员工Bean
public class AddEmployeeBean {
@Valid
private EmployeeBean employeeBean;
@NotEmpty
private List<EmployeeBean> employeeDetails;
|
|
getter- setter
}
内部Bean -员工Bean
public class EmployeeBean {
@NotEmpty
private String employeeId;
@NumberFormat(style = Style.NUMBER)
private long dept;
@NumberFormat(style = Style.NUMBER)
private long salary;
@NotEmpty
private String status;
|
|
getter- setter
}
1条答案
按热度按时间uxhixvfz1#
请检查this以获得问题的解决方案。希望它能有所帮助。