如果您想了解Thymeleaf不在某些语言环境中呈现消息内的变量的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析IntelliJ中的Thymeleaf无法解析变量、java+thymeleaf
如果您想了解Thymeleaf不在某些语言环境中呈现消息内的变量的知识,那么本篇文章将是您的不二之选。同时我们将深入剖析IntelliJ 中的 Thymeleaf 无法解析变量、java+thymeleaf-layout-dialect+thymeleaf 的使用、org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties的实例源码、spring boot使用thymeleaf跳转页面实例代码my thymeleaf indexpage的各个方面,并给出实际的案例分析,希望能帮助到您!
本文目录一览:- Thymeleaf不在某些语言环境中呈现消息内的变量
- IntelliJ 中的 Thymeleaf 无法解析变量
- java+thymeleaf-layout-dialect+thymeleaf 的使用
- org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties的实例源码
- spring boot使用thymeleaf跳转页面实例代码my thymeleaf indexpage
Thymeleaf不在某些语言环境中呈现消息内的变量
我的messages.properties
文件中有一个键的文本,其中包含变量:
some.key=You''ll need to pay {0} {1} in order to continue.
我在应用程序支持的两种语言环境中都有它:messages.properties
英语和messages_tr.properties
土耳其语(默认值Locale
)。
因此,当我使用土耳其语区域设置呈现页面时,此方法有效:
我得到:
Some Turkish words 10 USD some other Turkish words.
因此,{0} {1}
将替换为金额和货币。但是当我用英语渲染页面时却没有:
You''ll need to pay {0} {1} in order to continue.
我究竟做错了什么?谢谢。
答案1
小编典典看起来问题出在单引号中。
从这里:
单引号用于表示消息格式中将不格式化的部分。单引号本身必须通过使用两个单引号(’‘)进行转义
因此,您在messages.properties中的消息应为:
You''''ll need to pay {0} {1} in order to continue.
IntelliJ 中的 Thymeleaf 无法解析变量
如何解决IntelliJ 中的 Thymeleaf 无法解析变量?
我正在 IntelliJ 上使用 Spring Boot 和 Thymeleaf 编写一个简短的 Web 表单应用程序,但似乎在 HTML 文件中,模型中的所有字段都无法解析。这是我的代码:
这是样板酒店的代码:
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
private String nomHotel;
private String ville;
private String description;
private String image;
@OnetoMany (mappedBy = "hotel",fetch = FetchType.LAZY,cascade = CascadeType.ALL)
List<voyageOrg> vo;
@OnetoMany (mappedBy = "hotels",cascade = CascadeType.ALL)
List<reservation> res;
}
控制器类:
@Controller
public class HotelController {
@Autowired
private HotelService hotelService;
@GetMapping("/listHotel")
public String listHotel(){
return "hotels";
}
public String hotel (Model model){
model.addAttribute("listHotel",hotelService.getAllHotels());
return "hotels";
}
}
查看文件:
<tbody>
<tr th:each="hotel:${listHotel}"></tr>
<td th:text="${hotel.nomHotel}"></td>
<td th:text="${hotel.ville}"></td>
</tbody>
listHotel
、hotel
、nomHotel
、ville
用红色下划线标有“无法解析”。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
java+thymeleaf-layout-dialect+thymeleaf 的使用

一,添加 pom.xml 文件依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
<version>2.4.1</version>
</dependency>
二,如下两个文件代码
index.html 引用模板文件,PS:(layout:decorate="testlayout/layout", 这个必须注意,模板文件的地址)
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{testlayout/layout}">
<head lang="en">
<title>Search</title>
</head>
<body>
<div class="row" layout:fragment="content">
<h4 class="indigo-text center">中间部分e</h4>
</div>
</body>
</html>
模板文件
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no" />
<title>Insert title here</title>
</head>
<body>
<div>
<div th:replace="/testlayout/test::nav"></div>
</div>
<section layout:fragment="content">
<p>Page content goes here</p>
</section>
<div>
尾部
</div>
</body>
</html>
test.html 导航文件代码,PS:<div th:replace="/testlayout/test::nav"></div > 注意这个地址,不能写错,我的文件都是在 testlayout 这个文件目录下的
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="nav">
<nav>
<ul class="columnbar">
<li><a href="/#">首页</a></li>
<li><a href="/#">首页</a></li>
<li><a href="/#">首页</a></li>
<li><a href="/#">首页</a></li>
<li><a href="/#">首页</a></li>
</ul>
</nav>
</div>
</body>
</html>
org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties的实例源码
/** * Instantiates a new Cas protocol view. * * @param templateName the template name * @param applicationContext the application context * @param templateEngine the template engine * @param properties the properties */ public CasProtocolView(final String templateName,final ApplicationContext applicationContext,final SpringTemplateEngine templateEngine,final ThymeleafProperties properties) { super(templateName); setApplicationContext(applicationContext); setTemplateEngine(templateEngine); setCharacterEncoding(properties.getEncoding().displayName()); setLocale(Locale.getDefault()); }
public ThymeLeafConfigurer(SpringTemplateEngine springTemplateEngine,OghamCommonTemplateProperties templateProperties,OghamEmailProperties emailProperties,OghamSmsProperties smsProperties,ThymeleafProperties springProperties) { super(); this.springTemplateEngine = springTemplateEngine; this.templateProperties = templateProperties; this.emailProperties = emailProperties; this.smsProperties = smsProperties; this.springProperties = springProperties; }
spring boot使用thymeleaf跳转页面实例代码my thymeleaf indexpage
本篇文章主要介绍了spring boot使用thymeleaf跳转页面,实例介绍了thymeleaf的原理和介绍,有兴趣的可以了解一下。
前言
在学习springboot 之后想结合着html做个小demo,无奈一直没掌握窍门,在多番的搜索和尝试下终于找到了配置的方法,使用thymeleaf做事前端页面模板,不能使用纯html.
thymeleaf介绍
Thymeleaf是面向Web和独立环境的现代服务器端Java模板引擎。
Thymeleaf的主要目标是为您的开发工作流程带来优雅的自然模板 - 可以在浏览器中正确显示HTML,还可以作为静态原型工作,从而在开发团队中进行更强大的协作。
使用Spring Framework的模块,与您最喜爱的工具进行大量集成,以及插入自己的功能的能力,Thymeleaf是现代HTML5 JVM Web开发的理想选择,尽管它可以做的更多。
实战
项目结构
thymeleaf pom依赖
org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-thymeleaf
模板页面
注意使用模板作为页面时候必须要把模板页面放在templates文件夹下
index.html
demo
my thymeleaf indexpage
更多详情controller
@Controller public class PageController { @RequestMapping("/page") public String page3(Model model){ model.addAttribute("userName","张三"); return "hello"; } @RequestMapping("info/more") public String page2(){ return "hello2"; } @RequestMapping("sys/index") public String page(){ return "sys/index"; } }
测试
点击更多详情
项目源码: github地址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持小编。
关于Thymeleaf不在某些语言环境中呈现消息内的变量的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于IntelliJ 中的 Thymeleaf 无法解析变量、java+thymeleaf-layout-dialect+thymeleaf 的使用、org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties的实例源码、spring boot使用thymeleaf跳转页面实例代码my thymeleaf indexpage的相关知识,请在本站寻找。
本文标签: