我正在使用Spring 4 MVC,Apache Tiles 2.2.2和Spring Roo开发一个web-app来生成一些样板代码。我有我的views.xml(我有tile配置)文件,如下所示:
<?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 部分。
我想知道的是如果有一种方法可以定义依赖关系并根据需要引用它们吗?
我找到了这个链接:the ultimate view — Tiles-3但我无法清楚地看到这些模式是否对我有帮助。
任何意见将不胜感激。谢谢!
答案 0 :(得分:2)
您必须创建默认模板,然后按以下方式扩展模板:
<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>