我正在使用JAX-WS实现java-first Web服务,并尝试使用它@SchemaValidation来验证webMethod参数中所需的元素.这是我如何声明我的必需属性;
@XmlElement(required=true) 完美映射我的wsdl模式(minOccur不再是0),但schemaValidation不验证传递的null元素.
@XmlElement(required=true, nillable=false)
public String getClubName() {
return clubName;
}
Run Code Online (Sandbox Code Playgroud)
任何使用我的API的客户端都可以传递null元素.我无法使用JAXB来防止这种情况.
另一方面,bean验证的工作原理如下.但不适用于String字段
@Column(name = "FOUNDATION_YEAR", nullable = false)
private Integer foundationYear; //schemaValidation validates
@Column(name = "CLUB_NAME", length=100, nullable = false)
private String clubName; //schemaValidation does not validate
Run Code Online (Sandbox Code Playgroud)
如何使用schemaValidation来验证字符串值?一种方法是设置限制,但在使用java-first Web服务时不能这样做
<xsd:simpleType name="NotEmptyString">
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)
相关文章;