你在你的代码中的问题。它应该是布局:代替,而不是布局:片段
<div class="container">
<div layout:fragment="content">
我的版本代码的:在行家
Main.java
public static void main(String arg[]){
FileTemplateResolver templateResolver = new FileTemplateResolver();
// path to the files *.html
templateResolver.setPrefix("/home/user/desktop/");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
TemplateEngine templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
Context ctx = new Context();
String text = templateEngine.process("index", ctx);
// print html processed
System.out.println(text);
}
相关性:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring3</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
指数.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<h1>Index</h1>
<div th:replace="content :: fooName"> </div>
</body>
</html>
content.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<body>
<div th:fragment="fooName">
<a class="btn btn-primary" href="/posts/new">Add new post</a>
<a class="btn btn-primary" href="/posts/report">View post report</a>
</div>
</body>
</html>
输出功率为:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<h1>Index</h1>
<div>
<a class="btn btn-primary" href="/posts/new">Add new post</a>
<a class="btn btn-primary" href="/posts/report">View post report</a>
</div>
</body>
</html>
每做工精细
你能告诉你的代码和输出? – Troncador
我使用百里香,我从未尝试过这个问题。如果你显示(简要)你的代码,我可以测试它。 – Troncador
@Troncador我试着添加必要的代码。请让我知道如果这足以让你测试 – Albert