如何在 Spring Tiles 2.2 + Spring 4 中重用 put-list-attributes 变量?

How to reuse put-list-attributes variables in Spring Tiles 2.2 + Spring 4?

我正在使用 Spring 4 MVC、Apache Tiles 2.2.2 和 Spring Roo 开发一个网络应用程序来生成一些样板代码。我的 views.xml(我有 tiles 配置)文件如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
    <definition extends="form" name="check/readCheck">
        <put-attribute name="body" value="/WEB-INF/views/check/readCheck.jspx" />
        <put-list-attribute name="cssList" cascade="true" >
            <add-attribute value="/resources/css/bootstrap.min.css" />
            <add-attribute value="/resources/css/font-awesome.min.css" />
            <add-attribute value="/resources/css/ionicons.min.css" />
            <add-attribute value="/resources/css/AdminLTE.css" />
            <add-attribute value="/resources/css/daterangepicker/daterangepicker-bs3.css" />
            <add-attribute value="/resources/css/datetimepicker/datepicker3.css" />
            <add-attribute value="/resources/css/iCheck/all.css" />
            <add-attribute value="/resources/css/colorpicker/bootstrap-colorpicker.min.css" />
            <add-attribute value="/resources/css/timepicker/bootstrap-timepicker.min.css" />
        </put-list-attribute>   
    </definition>

    <definition extends="form" name="check/createCheck">
        <put-attribute name="body" value="/WEB-INF/views/check/createCheck.jspx" /> 
        <put-list-attribute name="cssList" cascade="true" >
            <add-attribute value="/resources/css/bootstrap.min.css" />
            <add-attribute value="/resources/css/font-awesome.min.css" />
            <add-attribute value="/resources/css/ionicons.min.css" />
            <add-attribute value="/resources/css/AdminLTE.css" />
            <add-attribute value="/resources/css/daterangepicker/daterangepicker-bs3.css" />
            <add-attribute value="/resources/css/datetimepicker/datepicker3.css" />
            <add-attribute value="/resources/css/iCheck/all.css" />
            <add-attribute value="/resources/css/colorpicker/bootstrap-colorpicker.min.css" />
            <add-attribute value="/resources/css/timepicker/bootstrap-timepicker.min.css" />
        </put-list-attribute>   
    </definition>
</tiles-definitions>

如您所见,我重复了 put-list-attribute 部分两次。

我想知道的是是否有一种方法可以定义一次依赖项并根据需要尽可能多地引用它们?

我找到了这个 link:the ultimate view — Tiles-3 但我看不清楚这些模式是否对我有帮助。

如有任何意见,我们将不胜感激。谢谢!

您必须创建一个默认模板,然后按如下方式扩展您的模板:

<tiles-definitions>   
    <definition name="app.base" template="/WEB-INF/templates/default.jsp">
        <put-attribute name="title" value="Not Found" />
        <put-attribute name="header" value="/WEB-INF/templates/header.jsp" />
        <put-attribute name="navbar" value="/WEB-INF/templates/navbar.jsp" />
        <put-attribute name="body" value="/WEB-INF/templates/body.jsp" />
        <put-attribute name="footer" value="/WEB-INF/templates/footer.jsp" />
        <put-list-attribute name="stylesheets">
              <add-attribute value="/static/css/bootstrap.css" />           
        </put-list-attribute>
        <put-list-attribute name="javascripts">
              <add-attribute value="/static/public/js/bootstrap.js" />
        </put-list-attribute>   
    </definition>
    <definition name="yourpage" extends="app.base">
        <put-attribute name="title" value="Your Page" />
        <put-attribute name="body" value="/WEB-INF/tiles/yourpage.jsp" />
        <put-list-attribute name="javascripts" inherit="true">
              <add-attribute value="/static/protected/js/newjavascript.js" />
        </put-list-attribute>
    </definition>
</tiles-definitions>