显示Unicode字符

时间:2019-03-14 18:54:06

标签: spring-boot thymeleaf

我将弹簧靴2与百里香3一起使用。 我尝试显示一个Unicode字符

HAL_NVIC_EnableIRQ()

我收到此错误

  

发生意外错误(类型=内部服务器错误,   状态= 500)。评估SpringEL表达式的异常:“ specialTry?☑   :''“

我尝试过

<div th:utext="${specialTry ? &#x2611; : ''}"></div>

仅显示#

2 个答案:

答案 0 :(得分:0)

确保应为characterEncodingtemplateResolver显式设置属性ThymeleafViewResolver

<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
    ...
    <property name="characterEncoding" value="UTF-8"/>
    ...
</bean>

<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    ...
    <property name="characterEncoding" value="UTF-8"/>
    ...
</bean>

JAVA注释代码:

@Bean
public ThymeleafViewResolver thymeleafViewResolver() {
    ThymeleafViewResolver resolver = new ThymeleafViewResolver();
    resolver.setTemplateEngine(templateEngine());
    resolver.setCharacterEncoding("UTF-8");
    return resolver;
}

http://forum.thymeleaf.org/UTF8-charset-problem-td3608879.html

答案 1 :(得分:0)

我认为您所缺少的是unicode部分周围的单引号

<div th:utext="${specialTry ? '&#x2611;' : ''}"></div>