您可以利用现有的xs:nonNegativeInteger类型来代替创建自己的简单类型来表示以0开头的整数.我将举一个例子.
SpThread
您可以使用@XmlSchemaType批注指定在XML模式中为字段/属性生成的类型.
package forum11667335;
import javax.xml.bind.annotation.XmlSchemaType;
public class SpThread {
private int durTime;
@XmlSchemaType(name="nonNegativeInteger")
public int getDurTime() {
return durTime;
}
public void setDurTime(int durTime) {
this.durTime = durTime;
}
}
演示
您可以在JAXBContext上使用generateSchema方法来生成XML模式:
package forum11667335;
import java.io.IOException;
import javax.xml.bind.*;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(SpThread.class);
jc.generateSchema(new SchemaOutputResolver() {
@Override
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
StreamResult result = new StreamResult(System.out);
result.setSystemId(suggestedFileName);
return result;
}
});
}
}
产量
下面是生成的XML模式.