【发布时间】:2021-04-01 13:57:59
【问题描述】:
我正在使用 Spring Web 服务连接到安全 url 并发送 SOAP 请求。 wsdl 中将特定字段定义为:
我使用genjaxb从wsdl生成类,所以这个字段生成为:
...
* <element name="collectionDay" type="{http://www.w3.org/2001/XMLSchema}int"/>
...
protected int collectionDay;
...
/**
* Gets the value of the collectionDay property.
*
*/
public int getCollectionDay() {
return collectionDay;
}
/**
* Sets the value of the collectionDay property.
*
*/
public void setCollectionDay(int value) {
this.collectionDay = value;
}
...
问题是主机期望任何一位数天(1 日到 9 日)被发送为: "<collectionDay>03</collectionDay>"(以 0 开头)
如果我可以将其转换为字符串很容易,但是 Spring 根据生成的类在未知的某处生成请求,因此该字段需要 int,但生成的字段为:
"<collectionDay>3</collectionDay>" (没有前导零)
此时我看到的唯一选择是将 WSDL 保存在本地并手动将字段类型更改为字符串,以便使用修改后的字段类型生成 java 类。该网址托管在银行,因此他们不可能进行任何更改。
【问题讨论】:
-
是的,没有办法通过保持一个整数来添加前导零。正如你所说,你必须在那里使用字符串。对不起:(
标签: java spring string integer wsdl