spring-mvc - 如何在 spring 中使用磁贴在单独的 html 文件中添加 css 文件

标签 spring-mvc tiles

我想创建单独的 css 文件并想使用它,而不是再次复制 css 文件。

使用这种方法,我可以通过调用它来重用 cssfilecommon.html,如果我想要一些其他需要的 css,我可以将它添加到单独的页面中并只为该页面调用

<tiles:insertAttribute name="cssfilecommon" /> - common css file

<tiles:insertAttribute name="pagespecific" /> - some other css file

——

我们可以这样做吗,如果有人尝试过,请告诉我..

布局文件
<!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>

titles-def.xml 文件
<?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>
titles-def.xml文件:
<definition name="home" template="basiclayout/layout" >
    <put-attribute name="cssfilecommon" value="bout/cssfilecommon"/>
    <put-attribute name="pagespecific" value="bout/pagespecific"/>
    ...
</definition>

注意 ignore attribute的用法:

If this attribute is set to true, and the attribute specified by the name does not exist, simply return without writing anything. The default value is false, which will cause a runtime exception to be thrown.



但是,正如我所看到的,您正在使用 Thymeleaf,它可能还不支持它:#17

关于spring-mvc - 如何在 spring 中使用磁贴在单独的 html 文件中添加 css 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21987201/

相关文章:

c# - 如何(垂直)放置不同高度的 WrapPanel 项目?

spring-mvc - Spring Boot Rest 服务更改属性

java - Spring文件上传内部服务器错误

c++ - OpenGL 平铺/ block 传输/裁剪

javascript - 纯 HTML + JavaScript 客户端模板

iphone - 使用CATiledLayer,渲染时图 block 之间的细线,使用ImageMagick生成的图 block

eclipse - 如何在 eclipse 中将 ReactJs 与 Spring MVC 集成

java - 如何查看 CrudRepository 传递的 findByUsername 的结果

java - 在 Spring 测试中插入后回滚

google-maps-api-3 - 谷歌地图混合和空中瓷砖丢失