编码字符集

2018-12-23 22:31 更新

Marshaller.JAXB_ENCODING

如果需要改输出XML的字符编码,可以添加属性JAXB_ENCODING

    @Test
    public void test2() throws JAXBException {
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
        marshaller.marshal(one, System.out);
    }

得到的结果:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<one>
    <name>Test one</name>
</one>

已经不再是默认的UTF-8

以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号