停止转换<到<,>到>和&到&在春季控制器响应

时间:2015-04-29 06:43:23

标签: java xml spring spring-mvc jaxb2

我正在尝试生成一个小的xml。这个xml应该有一个CDATA。现在问题是我设法生成CDATA,但生成的xml具有<和>和&

我正在使用spring-mvc。我有兴趣在其中获得带有CDATA的正确xml。

示例xml如下:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer>
    <Active>1</Active>
    <AlertMessage></AlertMessage>
    <Currency>GBP</Currency>
    <CustomerNumber>123</CustomerNumber>
    <Forename>AD</Forename>
    <balancetoallow>
        <balance saving="10" spend="9990" type="2">
            <value>\&lt;![CDATA[$100 off on two  purchase of jeans XYZ Brand.]]\&gt;</value>
        </balance>
    </balancetoallow>
    <Surname>CD</Surname>
</Customer>

我还覆盖了其中一个转换器。

<mvc:annotation-driven>
        <mvc:message-converters>
            <bean
                class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter">
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

P.S我正在为我的网络服务使用弹簧控制器。

这是模型类:

public class Balance{
    private String value;
    private String type;
    private String saving;
    private String spend;

    public String getValue() {
        return value;
    }
    @XmlJavaTypeAdapter(AdapterCDATA.class)
    public void setValue(String value) {
        this.value = value;
    }
    public String getType() {
        return type;
    }
    @XmlAttribute
    public void setType(String type) {
        this.type = type;
    }
    public String getSaving() {
        return saving;
    }
    @XmlAttribute
    public void setSaving(String saving) {
        this.saving = saving;
    }
    public String getSpend() {
        return spend;
    }
    @XmlAttribute
    public void setSpend(String spend) {
        this.spend = spend;
    }
}

这个班级再次成为另一个班级的一部分。

public class Balancetoallows {  
    private List<Balance> balancetoallow ;

    public List<Balance> getBalancetoallow () {
        return balancetoallow;
    }

    @XmlElement(name="balancetoallow ")
    public void setBalancetoallow (List<Balance > balancetoallow ) {
        this.balancetoallow= balancetoallow;
    }
}

这是本课程的一部分。 父类。

@XmlRootElement(name = "Customer")
public class Customer {

    private String surname ;
    private String forename;
    private BalanceToAllow balanceToAllow;
    private final String active="1";
    private final String currency = "GBP";
    private final String alertMessage="";


    public String getCustomerNumber() {
        return customerNumber;
    }

    @XmlElement(name="CustomerNumber")
    public void setCustomerNumber(String customerNumber) {
        this.customerNumber = customerNumber;
    }

    @XmlElement(name="Active")
    public String getActive() {
        return active;
    }
    @XmlElement(name="Currency")
    public String getCurrency() {
        return currency;
    }
    public String getSurname() {
        return surname;
    }
    @XmlElement(name="Surname")
    public void setSurname(String surname) {
        this.surname = surname;
    }
    public String getForename() {
        return forename;
    }
    @XmlElement(name="Forename")
    public void setForename(String forename) {
        this.forename = forename;
    }
    @XmlElement(name="AlertMessage")
    public String getAlertMessage() {
        return alertMessage;
    }
    public BalanceToAllow getBalanceToAllow() {
        return BalanceToAllow;
    }

    @XmlElement(name="balanceToAllow")
    public void setFuturePromotions(BalanceToAllow balanceToAllow) {
        this.balanceToAllow= balanceToAllow;
    }
}

感谢阅读。

0 个答案:

没有答案