我编写了一个 Spring Boot 应用程序来接受 Http 获取请求并发送 XML 响应作为输出。我需要通过 HTTP 获取以下 XML 作为输出
<response xmlns="">
<userId>235</userId>
<amount>345.0</amount>
</response>
我的 DTO 课程如下,
@XmlRootElement(name = "response")
public class CgPayment {
@XmlElement
private String userId;
@XmlElement
private double amount;
@XmlElement
public String getUserId() {
return userId;
}
@XmlElement
public void setUserId(String userId) {
this.userId = userId;
}
@XmlElement
public void setAmount(double amount) {
this.amount = amount;
}
@XmlElement
public double getAmount() {
return amount;
}
}
但我得到以下响应作为输出。
<CgPayment xmlns="">
<userId>235</userId>
<amount>345.0</amount>
</CgPayment>
如何更改根元素。响应类型为 APPLICATION_XML_VALUE