Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 使用Thymeleaf扩展视图_Spring_Spring Mvc_Razor_Thymeleaf - Fatal编程技术网

Spring 使用Thymeleaf扩展视图

Spring 使用Thymeleaf扩展视图,spring,spring-mvc,razor,thymeleaf,Spring,Spring Mvc,Razor,Thymeleaf,是否可以扩展与thymeleaf的共享视图 我知道这是可以使用的,但这不是我想要的。 相反,我想要类似于.NET MVC的东西,比如@RenderBody()和另一个通过包含共享视图来扩展共享视图的视图。您可以使用扩展视图 布局页面 <html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> ... <body lay

是否可以扩展与thymeleaf的共享视图

我知道这是可以使用的,但这不是我想要的。 相反,我想要类似于.NET MVC的东西,比如@RenderBody()和另一个通过包含共享视图来扩展共享视图的视图。

您可以使用扩展视图

布局页面

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    ...
    <body layout:fragment="body">
      ...
    </body>
</html>
一个页面中可能有多个片段

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    ...
    <body>
      <div layout:fragment="content"></div>
      <footer layout:fragment="footer"></footer>
    </body>
</html>

...

我将使用Rythm而不是Thymeleaf。它速度更快,功能更丰富。Rythm是一个通用模板引擎,而Thymeleaf是一个XML/XHTML/HTML5模板引擎。Rythm可能更快,但现在渲染视图的成本可以忽略不计。Thymeleaf将为您提供更干净的模板和模板验证,从而提高生产率。但无论什么能让你的船漂浮:)我明白。顺便说一句,Rythm是由我的一位同事开发出来的。太棒了!!布局方言正是我需要的。我很高兴我不需要使用瓷砖。
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    ...
    <body>
      <div layout:fragment="content"></div>
      <footer layout:fragment="footer"></footer>
    </body>
</html>