获取依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!-- 仓库地址 -->
<repositories>
<repository>
<id>github-maven-repo</id>
<url>https://raw.github.com/fanlychie/maven-repo/releases</url>
</repository>
</repositories>
<dependencies>
<!-- 声明依赖,版本信息参考:https://github.com/fanlychie/commons-jsp-tag/releases -->
<dependency>
<groupId>org.fanlychie</groupId>
<artifactId>commons-jsp-tag</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>

环境要求

JDK1.7 或以上版本

项目地址

https://github.com/fanlychie/commons-jsp-tag

引入标签库

1
<%@ taglib prefix="f" uri="http://fanlychie.org/tags/function" %>

resource 标签

此标签用于表示 web 项目中 webapp 目录下的资源文件。

1
2
3
4
5
6
7
8
// 脚本资源
<script src='<f:resource path="/statics/js/index.js"/>'></script>
// 样式资源
<link href='<f:resource path="/statics/css/index.css"/>' rel="stylesheet" type="text/css">
// 图片资源
<img src='<f:resource path="/statics/images/logo.png"/>' />

资源文件版本

默认每次服务重新启动时,资源标签输出一个新的版本,强制客户端刷新资源文件,避免客户端缓存旧版的文件资源。如要自行控制管理资源文件,可在 Spring 配置文件中添加如下代码:

1
2
<!-- 引入 p 命名空间 xmlns:p="http://www.springframework.org/schema/p" -->
<bean class="org.fanlychie.commons.jsp.tag.WebappResourceTagConfig" p:version="1.0"/>

url 标签

此标签用于表示链接地址,可以是 http 或 https 的绝对地址,也可以是相对于项目的相对地址:

1
2
3
4
5
// 绝对地址,输出 http://www.baidu.com
<f:url href="http://www.baidu.com" />
// 相对地址,输出 /项目名/user/home
<f:url href="/user/home" />

date 标签

此标签用于将 java.util.Date 对象转成字符串内容:

1
2
3
4
5
6
7
8
9
10
11
// 日期,输出 2017-01-26
<f:date value="${now}" type="date" />
// 时间,输出 01:41:41
<f:date value="${now}" type="time" />
// 日期时间,输出 2017-01-26 01:41:41
<f:date value="${now}" type="datetime" />
// 自定义模式串,输出 2017/01/26 01:41:41:236
<f:date value="${now}" pattern="yyyy/MM/dd HH:mm:ss:SSS" />