你在你的代碼中的問題。它應該是佈局:代替,而不是佈局:片段
<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