将Java Date对象映射到XML Schema日期时间格式 [英] Mapping Java Date Object to XML Schema datetime format
本文介绍了将Java Date对象映射到XML Schema日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在将Java数据类型映射到标准Schema Date数据类型时遇到了一些问题。
I am having some problem mapping my Java Data Type to standard Schema Date data type.
我有一个简单的类,我这样注释。期间实例变量是Java Date对象类型。
I have a simple class that I annotated like this. The period instance variable is of Java Date object type.
@XmlAccessorType(value = XmlAccessType.NONE)
public class Chart {
@XmlElement
private double amount;
@XmlElement
private double amountDue;
@XmlElement
private Date period;
//constructor getters and setters
}
这是我的Web服务
@WebService
public class ChartFacade {
@WebMethod
public Chart getChart() throws ParseException {
SimpleDateFormat df = new SimpleDateFormat("yyyy-mm-dd");
Chart chart = new Chart(20.0,20.5, df.parse("2001-01-01"));
return chart;
}
}
我的问题是它以格式返回日期数据不符合我的期望。
My problem is it returns the date data in a format not according to what I am expecting.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getChartResponse xmlns:ns2="http://ss.ugbu.oracle.com/">
<return>
<amount>20.0</amount>
<amountDue>20.5</amountDue>
**<period>2001-01-01T00:01:00+08:00</period>**
</return>
</ns2:getChartResponse>
</S:Body>
</S:Envelope>
我希望像这样返回期间元素
I wanted the period element to be returned like this
<period>2001-01-01</period>
有什么办法可以达到这个目的吗?
Is there any way I can achieve this?
推荐答案
您可以执行以下操作来控制架构类型:
You can do the following to control the schema type:
@XmlElement
@XmlSchemaType(name="date")
private Date period;
更多信息:
- http://bdoughan.blogspot.com/2011/01/jaxb-and-datetime-properties.html
这篇关于将Java Date对象映射到XML Schema日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文