Thymeleaf:使用th:attr时对西里尔符号进行html编码

时间:2018-10-01 11:20:05

标签: encoding thymeleaf

我使用百里香th:attr标签来解析xml。示例:

<erp th:attr="IS_START_MONTH=false,ITYPE_ID=${itypeId},NAME=${unitName},P_ID=${pcode},START_DATE=${startDate},CORRELATION_TOKEN=${correlationId}">

但是当我查看输出时,发现以下结果:

<erp IS_START_MONTH="false" ITYPE_ID="VP" FZ_ID="294" NAME="&#x41e;&#x442;&#x434;&#x435;&#x43b; &#x43d;&#x430;&#x434;&#x437;&#x43e;&#x440;&#x43d;&#x43e;&#x439; &#x434;&#x435;&#x44f;&#x442;&#x435;&#x43b;&#x44c;&#x43d;&#x43e;&#x441;&#x442;&#x438; &#x438; &#x43f;&#x440;&#x43e;&#x444;&#x438;&#x43b;&#x430;&#x43a;&#x442;&#x438;&#x447;&#x435;&#x441;&#x43a;&#x43e;&#x439; &#x440;&#x430;&#x431;&#x43e;&#x442;&#x44b; &#x43f;&#x43e; &#x420;&#x43e;&#x441;&#x442;&#x43e;&#x432;&#x441;&#x43a;&#x43e;&#x43c;&#x443;, &#x411;&#x43e;&#x440;&#x438;&#x441;&#x43e;&#x433;&#x43b;&#x435;&#x431;&#x441;&#x43a;&#x43e;&#x43c;&#x443; &#x438; &#x413;&#x430;&#x432;&#x440;&#x438;&#x43b;&#x43e;&#x432;-&#x42f;&#x43c;&#x441;&#x43a;&#x43e;&#x43c;&#x443; &#x440;&#x430;&#x439;&#x43e;&#x43d;&#x430;&#x43c; &#x42f;&#x440;&#x43e;&#x441;&#x43b;&#x430;&#x432;&#x441;&#x43a;&#x43e;&#x439; &#x43e;&#x431;&#x43b;&#x430;&#x441;&#x442;&#x438;" START_DATE="26-09-2018" CORRELATION_TOKEN="3b765361-e586-417d-aba0-ca49d2ec7ea2">

因此所有替换的西里尔字母值都变为html转义。

我使用此百里香叶配置:

    @Bean
    ITemplateResolver xmlTemplateResolver() {
        ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
        templateResolver.setResolvablePatterns(Collections.singleton("xml/*"));
        templateResolver.setPrefix("/templates/");
        templateResolver.setSuffix(".xml");
        templateResolver.setTemplateMode("XML");
        templateResolver.setCharacterEncoding("UTF-8");
        templateResolver.setCacheable(false);
        return templateResolver;
    }

0 个答案:

没有答案