Spring Boot应用中Messages资源信息在Thymeleaf中的显示错误问题
来源:互联网 发布:线切割控制器手动编程 编辑:程序博客网 时间:2024/05/28 11:29
引言: Thymeleaf是Spring Boot中使用的一种后台的模板技术,在Spring Boot中碰到了在页面上无法访问messages中信息的问题,本文将描述其分析过程以及如何解决该问题。
1. 环境介绍
Spring Boot 1.4.0, Thymeleaf的模板技术后台使用。
使用基于messages的存放信息,比如中文情况下使用messages_zh_CN.properties来存放信息。
2. 问题以及错误描述
在Thymeleaf页面中使用#{message_key}来直接从messages中读取信息。 测试中页面报出来的错误信息如下:
??menu.top.client.service.text_zh_CN??其中使用的messages.properties定义了如下信息:
menu.top.client.service.text=\u8054\u7CFB\u5BA2\u670D但是却无法正确的显示出来,那问题出在哪里呢?
3. 页面代码分析
页面的代码如下:
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>Hello World!</title> </head> <body> <h1 th:inline="text">Hello.v.2</h1> <p th:text="${hello}"></p> <p th:text="#{menu.top.client.service.text}">test message property</p> </body></html>分析器中<p>中使用的th:text应该没有问题。
4. messages文件的位置
如果页面是正确的话,查看messages的靖是否正确, 指定basename的路径,经过分析其为正确的。
spring.messages.basename=i18n/messages5. 打开thymeleaf的调试模式
spring.thymeleaf.cache=false关闭其cache设置,可以直接使用其修改的template,不再缓存。
6. 重新启动之后, 可以正常显示
在写blog的过程中,重启之后,可以正常显示了, 问题忽然之久就消失了,难道是缓存的问题,不得而知,期待下一次碰到之后,补齐本文剩余的原因内容。
0 0
- Spring Boot应用中Messages资源信息在Thymeleaf中的显示错误问题
- Spring Boot+thymeleaf 静态资源上下文的问题
- Spring boot 中使用 Thymeleaf
- spring-boot中引入thymeleaf
- 关于在spring boot中使用默认的 thymeleaf模板
- Spring boot遇到的thymeleaf一些问题
- 在Spring Boot中输出REST资源
- 在Spring Boot中输出REST资源
- Spring-boot中thymeleaf模板使用小结
- spring-cloud-starter-feign 组件在spring boot中的应用:访问Oauth2资源服务器的资源接口
- (五)Spring Boot配置静态资源访问,整合Thymeleaf模板
- [spring-boot] thymeleaf 热交换
- Spring Boot + Gradle + Thymeleaf
- spring boot 整合 thymeleaf
- spring boot vue Thymeleaf
- spring boot thymeleaf 用法
- Spring Boot使用Thymeleaf
- Spring-Boot thymeleaf异常
- ZooKeeper 实现分布式锁
- 通过Ajax获取另一个页面的div值赋值到本页面中
- block,inline和inline-block概念和区别
- 使用Picasso加载图片的内存优化实践
- 我的第一篇博客
- Spring Boot应用中Messages资源信息在Thymeleaf中的显示错误问题
- sprintf、strcpy和memcpy的区别
- java类执行顺序
- 查看MYSQL版本的几种方法
- 二两橙子的前端之路--简单算法的实现
- Java并发编程之volatile关键字的理解
- 查看MYSQL版本的几种方法
- Opencv图像识别从零到精通(36)----DFT离散傅里叶变换
- Java 程序员必须收藏的资源大全