Spring mvc 如何在spring中使用tiles将css文件添加到单独的html文件中
我想创建单独的css文件并想使用它,而不是再次复制css文件 使用这个方法,我可以通过调用cssfilecommon.html来重用它,而且如果我需要其他css,我可以将它添加到单独的页面中,并且只调用该页面Spring mvc 如何在spring中使用tiles将css文件添加到单独的html文件中,spring-mvc,tiles,Spring Mvc,Tiles,我想创建单独的css文件并想使用它,而不是再次复制css文件 使用这个方法,我可以通过调用cssfilecommon.html来重用它,而且如果我需要其他css,我可以将它添加到单独的页面中,并且只调用该页面 <tiles:insertAttribute name="cssfilecommon" /> - common css file <tiles:insertAttribute name="pagespecific" /> - some other css file
<tiles:insertAttribute name="cssfilecommon" /> - common css file
<tiles:insertAttribute name="pagespecific" /> - some other css file
-通用css文件
-其他css文件
--
我们可以这样做吗?如果有人试过,请告诉我
布局文件
<!DOCTYPE html>
<html xmlns:tiles="http://www.thymeleaf.org">
<head>
**<tiles:insertAttribute name="cssfile" />**
</head>
<body>
<div tiles:include="header">Header Block</div>
<div tiles:substituteby="body">Body Block</div>
<div tiles:substituteby="footer">Footer Block</div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="home" template="basiclayout/layout" >
<put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
<put-attribute name="header" value="bout/header"/>
<put-attribute name="menu" value="bout/Menu"/>
<put-attribute name="footer" value="bout/footer"/>
</definition>
****
头块
人体模块
页脚块
titles-def.xml文件
<!DOCTYPE html>
<html xmlns:tiles="http://www.thymeleaf.org">
<head>
**<tiles:insertAttribute name="cssfile" />**
</head>
<body>
<div tiles:include="header">Header Block</div>
<div tiles:substituteby="body">Body Block</div>
<div tiles:substituteby="footer">Footer Block</div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://struts.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="home" template="basiclayout/layout" >
<put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
<put-attribute name="header" value="bout/header"/>
<put-attribute name="menu" value="bout/Menu"/>
<put-attribute name="footer" value="bout/footer"/>
</definition>
--
cssfilecommon.html
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link href="css/jquery-ui-1.10.3.custom.css" th:href="@{css/jquery-ui-1.10.3.custom.css}" rel="stylesheet" type="text/css" />
<link href="css/ui.jqgrid.css" th:href="@{css/ui.jsd.css}" rel="stylesheet" type="text/css"/>
是的,使用普通瓷砖,您可以执行以下操作: 布局文件:
<head>
<tiles:insertAttribute name="cssfilecommon" />
<tiles:insertAttribute name="pagespecific" ignore="true" />
</head>
请注意以下用法:
如果此属性设置为true,并且
名称不存在,只需返回而不写入任何内容。这个
默认值为false,这将导致运行时异常被忽略
扔
但是,正如我看到的,您正在使用Thymeleaf,它可能还不支持它:另一个聪明的建议,您可以在
tiles def.xml
中声明一个列表,在这个列表中,您可以简单地将您需要的所有css文件推送到您的站点中,如下所示:
<put-list-attribute name="jsList" cascade="true">
<add-attribute value="/Project/basic/css/basic.css" />
<add-attribute value="/Project/case2/css/example2.js" />
<add-attribute value="/Project/special/css/example3.css" />
</put-list-attribute>
在此之后,在jsp文件中,您可以使用以下内容轻松地迭代列表(您需要jstl标记库):
...
...
我知道这和@Slava Semushin说的一样,但我希望你知道你可以使用列表
例如,如果您使用jqxwidgets,您需要为元素绑定特殊的javascript,如果您不需要每个站点的所有javascript,那么您可以根据以下建议处理这种情况