从Spring RestController返回意外和不需要的div元素

时间:2016-11-17 12:26:05

标签: spring spring-boot spring-restcontroller

我从Spring RestController方法返回以下类的对象实例。

package x

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@XmlRootElement(name = "invoices")
public class Invoices implements Serializable {

    private Info info;

    private Set<Customer> customers = new HashSet<>();

    private List<Invoice> invoices = new ArrayList<>();

    public Info getInfo() {
        return info;
    }

    public void setInfo(Info info) {
        this.info = info;
    }

    @XmlElement(name = "customer")
    public Set<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(Set<Customer> customers) {
        this.customers = customers;
    }

    @XmlElement(name = "invoice")
    public List<Invoice> getInvoices() {
        return invoices;
    }

    public void setInvoices(List<Invoice> invoices) {
        this.invoices = invoices;
    }
}

Controller方法具有签名;

  @RequestMapping(value = "/invoice", method = RequestMethod.GET, produces = "application/xml; charset=UTF-8")

这会在顶部元素上返回一个带有意外div元素和名为slick_uniqueid的属性的XML。我该怎么摆脱这个,它来自哪里?

<invoices slick-uniqueid="3">
<div>
<a id="slick_uniqueid" />
</div>

1 个答案:

答案 0 :(得分:2)

我自己找到了答案。来自服务器的原始响应不包括此属性,也不包括额外元素。它在浏览器中显示XML时会略微修改XML。如果我查看源代码,那么属性和元素就不存在了。无论是。奇怪。

之前我从未注意到这一点