File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed
Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ AnnotationValidate基于Hibernate-Validator实现基于注解简化相关的代
3737```
3838
3939
40- ### 示列代码
40+ ### 示列代码-1,常规类方法
4141
4242``` java
4343
@@ -72,6 +72,45 @@ public class Test {
7272
7373```
7474
75+ ### 示列代码-2,基于接口开发
76+
77+ ``` java
78+
79+ import javax.validation.constraints.NotBlank ;
80+ /**
81+ * 基于接口开发必须在接口上实现注解,否者会有异常
82+ * @author lk
83+ * @version 1.0
84+ * @date 2020/11/5 17:25
85+ */
86+ public interface TestI {
87+ public Boolean roleMeunsList (@NotBlank String id );
88+ }
89+
90+ ```
91+
92+ ``` java
93+
94+ import com.linkkou.annotationvalidate.Validated ;
95+ import javax.validation.constraints.NotBlank ;
96+ /**
97+ * 测试
98+ */
99+ public class Test implements TestI {
100+
101+ /**
102+ * 用于方法上面。校验输入参数是否合理
103+ */
104+ @Validated
105+ @Override
106+ public Boolean roleMeunsList (@NotBlank String id ) {
107+ return true ;
108+ }
109+
110+ }
111+
112+ ```
113+
75114# 原理
76115
77116 JSR 269: Pluggable Annotation Processing API (https://www.jcp.org/en/jsr/detail?id=269 ) 。
@@ -82,4 +121,5 @@ public class Test {
82121#注意事项
83122
84123 + 编译不生效,先查看一下是否开启了注解编译。无论是IDEA、Eclipse都必须开启注解编译,关于如何开启自行搜索。
124+ + 基于接口的实现类,接口上必须有校验注解。否者校验会异常。
85125
You can’t perform that action at this time.
0 commit comments