我正在使用Thymeleaf在SpringBoot应用程序上托管一个AngularJS项目,我需要AngularJS通过视图和路由从另一个网页中获取部分元素。
但是,我无法弄清楚如何制作它以便ThymeLeaf只提供section元素而不是整个HTML页面,同时仍允许我在开发时将网页视为自然模板。
所以在服务器中它存储为
<html>
<title>Don't keep this </title>
<body>
<section>
Keep this
</section>
</body>
</html>
但是当AngularJS读取页面时,Thymeleaf会将其读成:
<section>
Keep this
</section>
答案 0 :(得分:0)
是的,碎片非常简单。如果您的html文件如下所示:
<!-- whatever.html -->
<html>
<head>
<title>Don't keep this </title>
</head>
<body>
<section th:fragment="section">
Keep this
</section>
</body>
</html>
和你的控制器一样:
@RequestMapping(value = "whatever.html", method = RequestMethod.GET)
public String get() {
return "whatever :: section";
// Where the string 'whatever' resolves to the template, and section
// resolves to the text in th:fragment.
}
它将返回html
<section>
Keep this
</section>