当我们实现某个接口时,都需要对入参数进行校验。例如下面的代码
public String queryValueByKey(String parmTemplateCode, String conditionName, String conditionKey, String resultName) {
checkNotNull(parmTemplateCode, "parmTemplateCode not null");
checkNotNull(conditionName, "conditionName not null");
checkNotNull(conditionKey, "conditionKey not null");
checkNotNull(resultName, "resultName not null");
}
问题:
我觉得这样还是太繁琐以及冗余,是否可以通过自定义注解的方式校验入参,例如queryValueByKey(@ValidString String parmTemplateCode) 或者其他更简洁优雅的方式。
请教各位高手,有例子的话更好,谢谢!
谢谢各位的回答,我觉得此篇博客的方案更符合我的预期。
使用SPRING AOP验证方法参数是否合法