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

    spring Thymeleaf 中文乱码

    时间:2016-03-19 19:17:20      阅读:21      评论:0      收藏:0      [点我收藏+]

    标签:

    前言:

    项目用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>
  • 相关阅读:
    hdu 4027 Can you answer these queries?
    hdu 4041 Eliminate Witches!
    hdu 4036 Rolling Hongshu
    pku 2828 Buy Tickets
    hdu 4016 Magic Bitwise And Operation
    pku2886 Who Gets the Most Candies?(线段树+反素数打表)
    hdu 4039 The Social Network
    hdu 4023 Game
    苹果官方指南:Cocoa框架(2)(非原创)
    cocos2d 中 CCNode and CCAction
  • 原文地址:https://www.cnblogs.com/hua0129/p/5411629.html
Copyright © 2011-2022 走看看