基础Hibernator-Validator不介绍,自行百度
先献上楼主之前的service层代码,是不是很无奈,这么多类似的判断;头痛!!!
解放双手Hibernator-Validator JSR303校验
public ObjectRestResponse<AgentTrustor> add(@RequestBody @Validated(AgentTrustor.ID.class) AgentTrustor agentTrustor) throws BaseException
很多人controller是不是这么用的!捕获异常返回前端;low
但这个解决不了我service的if,虽然jdk8也有if的判断方法,但是不爽;
然后新代码来了:直接复制到自己的项目里面:这个校验工具支持springboot1.4.x以后版本,超过springboot2.0,会更加简单;不过这样写也很好了!
/**
* @Author Cloud Bai
* @create 2019/10/28 1:08
* @description TODO
*/
imp