Thymeleaf是否有类似JSP标签的东西?

同步

我的意思不是taglibs,而是使用JSP标签执行以下操作:

ChildPage.jsp

<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>

<t:layout>
    <jsp:attribute name="head">
        <link href="css/custom.css" type="text/css" rel="stylesheet"/>
    </jsp:attribute>
    <jsp:attribute name="scripts">
        <script src="js/custom.js"></script>
    </jsp:attribute>
    <jsp:body>
        <p>This is from the child page</p>
    </jsp:body>
</t:layout>

layout.tag

<%@ tag description="Layout template" pageEncoding="UTF-8" %>
<%@ attribute name="head" fragment="true" %>
<%@ attribute name="scripts" fragment="true" %>
<!DOCTYPE html>
<html lang="en">
    <head>
        <link href="css/main.css" type="text/css" rel="stylesheet"/>
        <jsp:invoke fragment="head"/>
    </head>
    <body>
        <div id="body">
            <p>This is from the parent or "layout"</p>
            <jsp:doBody/>
        </div>
        <div id="footer">
            <script src="js/main.js"></script>
            <jsp:invoke fragment="scripts"/>
        </div>
    </body>
</html>

呈现时

<!DOCTYPE html>
<html lang="en">
    <head>
        <link href="css/main.css" type="text/css" rel="stylesheet"/>
        <link href="css/custom.css" type="text/css" rel="stylesheet"/>
    </head>
    <body>
        <div id="body">
            <p>This is from the parent or "layout"</p>
            <p>This is from the child page</p>
        </div>
        <div id="footer">
            <script src="js/main.js"></script>
            <script src="js/custom.js"></script>
        </div>
    </body>
</html>

这使我可以在布局页面和子页面中的JSP的标头部分中包含脚本。正文和页脚相同。

我已经阅读了Thymeleaf的文档/示例,但也许我不太了解,因为它看起来好像我无法做到。

我之所以“反转”似乎是一个简单的include的原因是,我拥有的每个页面都包含某些脚本和页眉节,但是我的子页面也具有要导入的脚本和要包含的样式表。

我能以某种方式实现吗?我做错了吗?

肯·贝科夫(Ken Bekov)

默认情况下,Thymeleaf使用所谓的包含样式布局这种方法的缺点在官方网站上有解释我建议您使用Thymeleaf布局方言这是创建Hierarchical-style布局的更为方便的方言

顺便说一句,在“布局方言”中,<head>标记的所有内容将自动合并。只是看一个例子

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Execl中是否有类似PSPP的值标签的东西?

来自分类Dev

是否有类似sudo的东西?

来自分类Dev

是否有类似jQuery的东西?

来自分类Dev

是否有类似@JsonIgnoreOtherProperties的东西?

来自分类Dev

rx中是否有类似ThrottleOrMax的东西?

来自分类Dev

VBA:是否有类似Abstract Class的东西?

来自分类Dev

是否有类似ServerSpec for Azure的东西

来自分类Dev

是否有类似button.isClicked()的东西?

来自分类Dev

是否有类似样式组的东西?

来自分类Dev

Django中是否有类似NSUserDefaults的东西?

来自分类Dev

是否有类似“用户定义的编码后备”之类的东西

来自分类Dev

是否有并发排序的字典或类似的东西?

来自分类Dev

红宝石中是否有类似“可调用”的东西?

来自分类Dev

Fsharp交互中是否有类似Python帮助功能的东西?

来自分类Dev

测试中是否有类似Expect_no_warnings()的东西?

来自分类Dev

是否有类似于ramda.js的lodash _.toArray的东西?

来自分类Dev

Angular Dart是否有类似jsfiddle.net的东西?

来自分类Dev

c ++ 11是否有类似quint8的东西?

来自分类Dev

R:是否有类似R的iPython Notebook(Jupyter)之类的东西?

来自分类Dev

Elixir的组合中是否有类似test_requires的东西?

来自分类Dev

SAML中是否有类似CAS代理票证的东西?

来自分类Dev

Python中是否有类似“ void lambda”的东西?

来自分类Dev

angularjs中是否有类似jQuery.active的东西?

来自分类Dev

是否有类似runDB的东西,但在Handler monad之外?

来自分类Dev

Symfony2-是否有实现类似jsf片段的东西?

来自分类Dev

是否有类似xargs的东西而不是使用参数传递数据?

来自分类Dev

laravelel elecuent中是否有类似belongsToThrow()之类的东西

来自分类Dev

Dart在Python中是否有类似`defaultdict`的东西?

来自分类Dev

Qt / QML中是否有类似ICommand的东西?

Related 相关文章

  1. 1

    Execl中是否有类似PSPP的值标签的东西?

  2. 2

    是否有类似sudo的东西?

  3. 3

    是否有类似jQuery的东西?

  4. 4

    是否有类似@JsonIgnoreOtherProperties的东西?

  5. 5

    rx中是否有类似ThrottleOrMax的东西?

  6. 6

    VBA:是否有类似Abstract Class的东西?

  7. 7

    是否有类似ServerSpec for Azure的东西

  8. 8

    是否有类似button.isClicked()的东西?

  9. 9

    是否有类似样式组的东西?

  10. 10

    Django中是否有类似NSUserDefaults的东西?

  11. 11

    是否有类似“用户定义的编码后备”之类的东西

  12. 12

    是否有并发排序的字典或类似的东西?

  13. 13

    红宝石中是否有类似“可调用”的东西?

  14. 14

    Fsharp交互中是否有类似Python帮助功能的东西?

  15. 15

    测试中是否有类似Expect_no_warnings()的东西?

  16. 16

    是否有类似于ramda.js的lodash _.toArray的东西?

  17. 17

    Angular Dart是否有类似jsfiddle.net的东西?

  18. 18

    c ++ 11是否有类似quint8的东西?

  19. 19

    R:是否有类似R的iPython Notebook(Jupyter)之类的东西?

  20. 20

    Elixir的组合中是否有类似test_requires的东西?

  21. 21

    SAML中是否有类似CAS代理票证的东西?

  22. 22

    Python中是否有类似“ void lambda”的东西?

  23. 23

    angularjs中是否有类似jQuery.active的东西?

  24. 24

    是否有类似runDB的东西,但在Handler monad之外?

  25. 25

    Symfony2-是否有实现类似jsf片段的东西?

  26. 26

    是否有类似xargs的东西而不是使用参数传递数据?

  27. 27

    laravelel elecuent中是否有类似belongsToThrow()之类的东西

  28. 28

    Dart在Python中是否有类似`defaultdict`的东西?

  29. 29

    Qt / QML中是否有类似ICommand的东西?

热门标签

归档