【问题标题】:Spring web service request format int with leading zero带有前导零的 Spring Web 服务请求格式 int
【发布时间】: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 日)被发送为: "&ltcollectionDay&gt03&lt/collectionDay&gt"(以 0 开头)

如果我可以将其转换为字符串很容易,但是 Spring 根据生成的类在未知的某处生成请求,因此该字段需要 int,但生成的字段为:

"&ltcollectionDay&gt3&lt/collectionDay&gt" (没有前导零)

此时我看到的唯一选择是将 WSDL 保存在本地并手动将字段类型更改为字符串,以便使用修改后的字段类型生成 java 类。该网址托管在银行,因此他们不可能进行任何更改。

【问题讨论】:

  • 是的,没有办法通过保持一个整数来添加前导零。正如你所说,你必须在那里使用字符串。对不起:(

标签: java spring string integer wsdl


【解决方案1】:

这里有答案:Can I zero-pad an integer in an XSD-generated class?

让一个终端系统来修复他们的东西是一件痛苦的事,而且通常不是一个选择。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 1970-01-01
    • 2023-01-18
    • 2014-12-14
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多