我有一个简单的spring-boot应用程序与soap webservice:
https://spring.io/guides/gs/producing-web-service/
在xsd中我添加了自定义bigdecimal类型(money type) .
<xs:complexType name="country">
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="population" type="xs:int" />
<xs:element name="capital" type="xs:string" />
<xs:element name="currency" type="tns:currency" />
<xs:element name="value1" type="xs:decimal" />
<xs:element name="value2" type="tns:money" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="money">
<xs:restriction base="xs:decimal">
<xs:fractionDigits value="2" />
</xs:restriction>
</xs:simpleType>
CountryRepository类:
Country spain = new Country();
spain.setName("Spain");
spain.setCapital("Madrid");
spain.setCurrency(Currency.EUR);
spain.setPopulation(46704314);
spain.setValue1(new BigDecimal(1.2));
spain.setValue2(new BigDecimal(2.1));
countries.add(spain);
请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gs="http://spring.io/guides/gs-producing-web-service">
<soapenv:Header/>
<soapenv:Body>
<gs:getCountryRequest>
<gs:name>Spain</gs:name>
</gs:getCountryRequest>
</soapenv:Body>
</soapenv:Envelope>
响应:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:getCountryResponse xmlns:ns2="http://spring.io/guides/gs-producing-web-service">
<ns2:country>
<ns2:name>Spain</ns2:name>
<ns2:population>46704314</ns2:population>
<ns2:capital>Madrid</ns2:capital>
<ns2:currency>EUR</ns2:currency>
<ns2:value1>1.1999999999999999555910790149937383830547332763671875</ns2:value1>
<ns2:value2>2.100000000000000088817841970012523233890533447265625</ns2:value2>
</ns2:country>
</ns2:getCountryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
如何修复十进制输出?我想拥有 :
<ns2:value2>2.10</ns2:value2>