日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java参数注解pam_java – 使用xmlelement defaultvalue注释指定默认值的简单方法

發(fā)布時間:2025/3/19 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java参数注解pam_java – 使用xmlelement defaultvalue注释指定默认值的简单方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

我通過JAXB有一個簡單的pojo注釋類:

public class MyPojo

implements Serializable

{

private final static long serialVersionUID = 1234L;

@XmlElement(name = "Type",required = true,defaultValue = "none")

@NotNull

protected SeismicDataAcquisitionSystemType type;

@XmlElement(name = "IpAddress",required = true)

@NotNull

@Pattern(regexp = "((1?[0-9]?[0-9]|2[0-4]|[0-9]|25[0-5]).){3}(1?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])")

protected String ipAddress;

@XmlElement(name = "SealServerTcpPort",defaultValue = "1477")

@NotNull

protected int sealServerTcpPort;

@XmlElement(name = "PamServerTcpPort",defaultValue = "1485")

@NotNull

protected int pamServerTcpPort;

/**

* Obtient la valeur de la propriété type.

*

* @return

* possible object is

* {@link SeismicDataAcquisitionSystemType }

*

*/

public SeismicDataAcquisitionSystemType getType() {

return type;

}

/**

* Définit la valeur de la propriété type.

*

* @param value

* allowed object is

* {@link SeismicDataAcquisitionSystemType }

*

*/

public void setType(SeismicDataAcquisitionSystemType value) {

this.type = value;

}

public boolean isSetType() {

return (this.type!= null);

}

/**

* Obtient la valeur de la propriété ipAddress.

*

* @return

* possible object is

* {@link String }

*

*/

public String getIpAddress() {

return ipAddress;

}

/**

* Définit la valeur de la propriété ipAddress.

*

* @param value

* allowed object is

* {@link String }

*

*/

public void setIpAddress(String value) {

this.ipAddress = value;

}

public boolean isSetIpAddress() {

return (this.ipAddress!= null);

}

/**

* Obtient la valeur de la propriété sealServerTcpPort.

*

*/

public int getSealServerTcpPort() {

return sealServerTcpPort;

}

/**

* Définit la valeur de la propriété sealServerTcpPort.

*

*/

public void setSealServerTcpPort(int value) {

this.sealServerTcpPort = value;

}

public boolean isSetSealServerTcpPort() {

return true;

}

/**

* Obtient la valeur de la propriété pamServerTcpPort.

*

*/

public int getPamServerTcpPort() {

return pamServerTcpPort;

}

/**

* Définit la valeur de la propriété pamServerTcpPort.

*

*/

public void setPamServerTcpPort(int value) {

this.pamServerTcpPort = value;

}

}

我嘗試用默認值初始化我的pojo

像那樣

MyPojo myPojo = new MyPojo();

myPojo.getPamServerTcpPort(); // return 0

setDefaultValues(myPojo); // assign attributes with annotated default values

myPojo.getPamServerTcpPort(); // return 1485

我正在使用方法setDefaultValues(MyPojo loMyPojo)嘗試programmaticaly,該方法使用java.lang.annotation API和java.lang.reflect API解析類,但我的代碼很難看,并且不能使用我自己的枚舉默認值

我不得不提到我無法修改原始類MyPojo,因為它本身是通過JAX解析XSD而生成的

任何的想法?

總結

以上是生活随笔為你收集整理的java参数注解pam_java – 使用xmlelement defaultvalue注释指定默认值的简单方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。