我是百里香的新手,我尝试创建一个模板.我的问题是这段代码:
码
<h1 th:text="${header.title}" >
title
<small th:text="${header.subtitle}" >Subtitle</small>
</h1>
Run Code Online (Sandbox Code Playgroud)
我想得到这个输出:
<h1> TITLE <small> SUBTITLE</small> </h1>
Run Code Online (Sandbox Code Playgroud)
但这是真正的输出:
<h1> TITLE </h1>
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做它不会删除"小"里面的东西?
提前致谢.
我正在使用Spring MVC 3.2和Thymeleaf模板引擎构建应用程序.我是Thymeleaf的初学者.
我有一切正常工作,包括Thymeleaf,但我想知道是否有人知道如何对控制器执行简单的Ajax请求的简单明了的结果,并且结果只渲染模板(片段)的一部分.
我的应用程序配置了所有内容(Spring 3.2,spring-security,thymeleaf,...)并按预期工作.现在我想做Ajax请求(使用jQuery非常简单,但我不想使用是因为Thymeleaf在其教程中,第11章:渲染模板片段(链接)提到它可以用片段完成.
目前我在我的控制器中
@RequestMapping("/dimensionMenuList")
public String showDimensionMenuList(Model model) {
Collection<ArticleDimensionVO> articleDimensions;
try {
articleDimensions = articleService.getArticleDimension(ArticleTypeVO.ARTICLE_TYPE);
} catch (DataAccessException e) {
// TODO: return ERROR
throw new RuntimeException();
}
model.addAttribute("dimensions", articleDimensions);
return "/admin/index :: dimensionMenuList";
}
Run Code Online (Sandbox Code Playgroud)
我希望替换<ul></ul>菜单项的视图部分:
<ul th:fragment="dimensionMenuList" class="dropdown-menu">
<li th:unless="${#lists.isEmpty(dimensions)}" th:each="dimension : ${dimensions}">
<a href="#" th:text="${dimension.dimension}"></a>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
任何线索都非常感谢.特别是如果我不必包含任何更多的框架.对于Java Web应用程序来说已经太多了.
我正在使用Spring 3和Thymeleaf制作一些网页,我迷失了如何显示这样的消息:
welcome.message =你好{0},欢迎!
然后使用thymeleaf标记内的用户名替换{0}:
<h1 th:text="#{welcome.message}">Welcome Placeholder</h1>
Run Code Online (Sandbox Code Playgroud)
我甚至不确定{0}是否是捆绑消息的正确语法.
我有一个文本使用百里香叶呈现三种不同的颜色.
所以我到目前为止测试该值的代码是:
th:if="${evaluation} > 50"
th:if="${evaluation} < 30"
Run Code Online (Sandbox Code Playgroud)
这很有效.
但第三个测试是针对这两者之间的值.所以我尝试过:
th:if="(${evaluation} < 49) ∧ (${evaluation} > 29)"
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,我在解析时遇到了这个错误:
org.thymeleaf.exceptions.TemplateProcessingException: Could not parse as expression: "(${evaluation} < 49) ∧ (${evaluation} > 29)" (/property.html:41)
Run Code Online (Sandbox Code Playgroud)
当然,这些行在标签之间,因为前两个正常工作.
也许操作数和操作数不正确,但百里香叶的文档并没有真正明确这些操作数.
欢迎所有想法!
更新:我从百万富翁论坛得到了答案.做到这一点的方法是:
th:if="${evaluation < 49 and evaluation > 29}"
Run Code Online (Sandbox Code Playgroud)
问题解决了!
我试图了解如何遍历Thymeleaf中的Map中的所有条目.我有一个由Thymeleaf处理的域对象,其中包含一个Map.
如何循环键并获取值?
谢谢.
我是百里香的新手,正在将jsp的网页转换为百里香.我有这样的支柱标签
<c:set var="someVariable" value="${someValue}"/>
Run Code Online (Sandbox Code Playgroud)
哪个变量可以在jsp中的任何地方使用.在百里香叶有这样的替代品吗?
我是Java/Spring/Thymeleaf的新手,所以请关注我目前的理解水平.我确实审查了这个类似的问题,但无法解决我的问题.
我想要一个简化的日期而不是长日期格式.
// DateTimeFormat annotation on the method that's calling the DB to get date.
@DateTimeFormat(pattern="dd-MMM-YYYY")
public Date getReleaseDate() {
return releaseDate;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<table>
<tr th:each="sprint : ${sprints}">
<td th:text="${sprint.name}"></td>
<td th:text="${sprint.releaseDate}"></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
电流输出
sprint1 2016-10-04 14:10:42.183
Run Code Online (Sandbox Code Playgroud) 将表单发布回控制器时,我遇到了很多困难,控制器应该只包含用户可以编辑的对象的arraylist.
表单正确加载,但是当它发布时,它似乎永远不会发布任何内容.
这是我的表格:
<form action="#" th:action="@{/query/submitQuery}" th:object="${clientList}" method="post">
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>Select</th>
<th>Client ID</th>
<th>IP Addresss</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr th:each="currentClient, stat : ${clientList}">
<td><input type="checkbox" th:checked="${currentClient.selected}" /></td>
<td th:text="${currentClient.getClientID()}" ></td>
<td th:text="${currentClient.getIpAddress()}"></td>
<td th:text="${currentClient.getDescription()}" ></td>
</tr>
</tbody>
</table>
<button type="submit" value="submit" class="btn btn-success">Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
以上工作正常,它正确加载列表.但是,当我POST时,它返回一个空对象(大小为0).我相信这是由于缺乏th:field,但无论如何这里是控制器POST方法:
...
private List<ClientWithSelection> allClientsWithSelection = new ArrayList<ClientWithSelection>();
//GET method
...
model.addAttribute("clientList", allClientsWithSelection)
....
//POST method
@RequestMapping(value="/submitQuery", method = RequestMethod.POST)
public String processQuery(@ModelAttribute(value="clientList") ArrayList clientList, Model model){
//clientList== …Run Code Online (Sandbox Code Playgroud) 我在一个中型Web应用程序中使用全栈Thymeleaf(spring mvc,security,layout dialect,webflow).
好的..现在我们在html模板中放了这么多代码,包含未包含在生成的HTML文件中的源代码注释会很不错.
我们如何实现这一目标?
我是第一次与Thymeleaf合作,我需要澄清模板.如果我正确理解文档,我可以在我的页面中包含一个模板 - 或者只是一个片段.例如,我可以这样写:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="template/layout :: header">
</head>
<body>
Hello world
<div th:include="template/layout :: footer"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但我想要的实际上是使用模板的相反方式:不是在页面中包含模板片段,我想在我的模板中包含页面,类似于:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
...
</head>
<body>
<div id="my-template-header">...</div>
<div id="the-content">
<!-- include here the content of the current page visited by the user -->
???
</div>
<div id="my-template-footer">...</div>
</body>
Run Code Online (Sandbox Code Playgroud)
换句话说,有没有办法在Thymeleaf中拥有等效的Sitemesh装饰器标签?
谢谢
thymeleaf ×10
java ×6
spring ×5
spring-mvc ×5
html ×2
spring-boot ×2
ajax ×1
jsp ×1
jstl ×1
templates ×1