sun*_*ark 8 spring-mvc jaxb hibernate-validator bean-validation
我使用JAXB(行家-JAXB2-插件)生成从架构域对象(请求响应&)
我想为几个属性添加验证(NOTNULL /空).我想有自定义Bean验证,应用程序是一个REST服务,我使用的是Spring 3和JSR 303,但我不认为我可以使用JSR 303验证对象,因为它是从模式生成的.
有人可以给我一个关于如何完成这件事的正确方向的推动.
对于 NotNull/Empty 验证,您可以在架构中使用 jaxb 限制
这是一个例子:
<xsd:simpleType name="NotEmptyString">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)
或者您可以使用正则表达式模式:
<xsd:simpleType name="DirType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[LR]*"/>
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)
注意:简单类型不保证其自己的类定义。使用 Java 自己的 java.lang.String,并且不会检查长度限制,除非您通过setEventHandler()请求。
更多信息http://jaxb.java.net/tutorial/section_3_3-Validation.html#Validation