zoukankan      html  css  js  c++  java
  • spring Thymeleaf 中文乱码

    前言:

    项目用springmvc+Thymeleaf ,但是发现html中的所有中文都乱码。

    但是自己的html的编码确定已经是UTF-8,在web.xml文件里面也添加了CharacterEncodingFilter,还是没有解决。

    在网上搜了好久,网上的说法是为ThymeleafViewResolver添加characterEncoding的属性,但是自己尝试之后还是没有解决。

    解决办法:

    同时为ServletContextTemplateResolver和ThymeleafViewResolver添加characterEncoding=UTF-8的属性。代码如下。(重要部分红色标出了)、

    <!-- 前端的渲染魔板引擎thymeleaf-->
        <bean id="templateResolver"
              class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
            <property name="prefix" value="/pages/"/>
            <property name="suffix" value=".html"/>
            <!-- 设置thymeleaf可以解析html的mode-->
            <property name="templateMode" value="LEGACYHTML5"/>
            <property name="cacheable" value="false"/>

        <!--这里要设置编码 --> <property name="characterEncoding" value="UTF-8"/> </bean> <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine"> <property name="templateResolver" ref="templateResolver"/> </bean> <!-- 配置引擎的viewResoler--> <bean class="org.thymeleaf.spring3.view.ThymeleafViewResolver"> <property name="templateEngine" ref="templateEngine"/>
          <!--这里要设置编码 -->
         <property name="characterEncoding" value="UTF-8"/>
        </bean>
  • 相关阅读:
    CTF-pwn-tips-zh_CN
    Linux 内核中 offset_of 和 container_of 宏的实现
    glibc2.26 -- tcache (2)
    glibc2.26 -- tcache (1)
    漏洞复现 -- 条件竞争 -- TOCTOU
    Linux 内核源码分析 -- read
    ospf lsa 4是不可替代的
    MPLS_Lab_3_AToM
    配置多链路捆绑PPP
    OSPF在转换LSA 5时的转发地址抑制 cyrus
  • 原文地址:https://www.cnblogs.com/weishenhong/p/5295886.html
Copyright © 2011-2022 走看看