自訂jstl fn函數fns

來源:互聯網
上載者:User

標籤:返回   ons   bbb   oca   緩衝   func   .com   inf   www   

1、引入函式宣告:

jsp頁面需要引入自訂fns函式宣告:

<%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %> (自訂的tld檔案位於/WEB-INF/tlds/fns.tld)一般需要C標籤配合使用,同時引入C標籤聲明:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

 

 

2、fns.tld代碼,仿照jstl的fn函數fn.tld的書寫格式:

 

<?xml version="1.0" encoding="UTF-8" ?><taglib xmlns="http://java.sun.com/xml/ns/j2ee"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"  version="2.0">      <description>JSTL 1.1 functions library</description>  <display-name>JSTL functions sys</display-name>  <tlib-version>1.1</tlib-version>  <short-name>fns</short-name>  <uri>http://java.sun.com/jsp/jstl/functionss</uri>   經過測試,uri標籤中可以沒有空格 <!-- 返回指定對象 -->  <function>    <description>根據編碼擷取使用者物件</description>    <name>getUserById</name>    <function-class>com.aaa.bbb.ccc.sys.utils.UserUtils</function-class>    <function-signature>com.aaa.bbb.ccc.sys.entity.User get(java.lang.String)</function-signature>    <example>${fns:getUserById(id)}</example>    </function>     <!-- 返回OBJECT -->  <function>    <description>擷取目前使用者緩衝</description>    <name>getCache</name>    <function-class>com.aaa.bbb.ccc.sys.utils.UserUtils</function-class>    <function-signature>java.lang.Object getCache(java.lang.String, java.lang.Object)</function-signature>    <example>${fns:getCache(cacheName, defaultValue)}</example>    </function>     <!-- 多個參數 -->  <function>    <description>擷取字典值</description>    <name>getDictValue</name>    <function-class>com.aaa.bbb.ccc.sys.utils.DictUtils</function-class>    <function-signature>java.lang.String getDictValue(java.lang.String, java.lang.String, java.lang.String)</function-signature>    <example>${fns:getDictValue(label, type, defaultValue)}</example>    </function>   <!-- 返回List -->  <function>    <description>擷取字典對象列表</description>    <name>getDictList</name>    <function-class>com.aaa.bbb.ccc.sys.utils.DictUtils</function-class>    <function-signature>java.util.List getDictList(java.lang.String)</function-signature>    <example>${fns:getDictList(type)}</example>    </function>    <!-- JsonMapper -->  <function>    <description>對象轉換JSON字串</description>    <name>toJson</name>    <function-class>com.aaa.bbb.cccc.JsonMapper</function-class>    <function-signature>java.lang.String toJsonString(java.lang.Object)</function-signature>    <example>${fns:toJson(object)}</example>    </function>  </taglib>

 

 

 

 

轉自:http://blog.csdn.net/javaloveiphone/article/details/50216569

自訂jstl fn函數fns

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.