EL表達式運算符、經常使用函數詳解

運算符:java

1.算術運算符有五個:+、-、*或$、/或div、%或mod 
2.關係運算符有六個:==或eq、!=或ne、<或lt、>或gt、<=或le、>=或ge 
3.邏輯運算符有三個:&&或and、||或or、!或not 
4.其它運算符有三個:Empty運算符、條件運算符、()運算符 
例:${empty param.name}、${A?B:C}、${A*(B+C)}數組


el表達式用到的函數:jsp

使用時,需在頁面頂部加入:函數

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>spa

這行代碼。code

經常使用函數:orm

運用El表達式截取字符串/獲取list的長度(轉) ${fn:substring(wjcd.lrsj, 0, 16)}對象

使用functions函數來獲取list的長度     ${fn:length(list)}ip

函數名 函數說明 使用舉例 
fn:contains 判斷字符串是否包含另一個字符串 <c:if test="${fn:contains(name, searchString)}"> 
fn:containsIgnoreCase 判斷字符串是否包含另一個字符串(大小寫無關) <c:if test="${fn:containsIgnoreCase(name, searchString)}"> 
fn:endsWith 判斷字符串是否以另外字符串結束 <c:if test="${fn:endsWith(filename, ".txt")}"> 
fn:escapeXml 把一些字符轉成XML表示,例如 <字符應該轉爲&lt; ${fn:escapeXml(param:info)} 
fn:indexOf 子字符串在母字符串中出現的位置 ${fn:indexOf(name, "-")} 
fn:join 將數組中的數據聯合成一個新字符串,並使用指定字符格開 ${fn:join(array, ";")} 
fn:length 獲取字符串的長度,或者數組的大小 ${fn:length(shoppingCart.products)} 
fn:replace 替換字符串中指定的字符 ${fn:replace(text, "-", "&#149;")} 
fn:split 把字符串按照指定字符切分 ${fn:split(customerNames, ";")} 
fn:startsWith 判斷字符串是否以某個子串開始 <c:if test="${fn:startsWith(product.id, "100-")}"> 
fn:substring 獲取子串 ${fn:substring(zip, 6, -1)} 
fn:substringAfter 獲取從某個字符所在位置開始的子串 ${fn:substringAfter(zip, "-")} 
fn:substringBefore 獲取從開始到某個字符所在位置的子串 ${fn:substringBefore(zip, "-")} 
fn:toLowerCase 轉爲小寫 ${fn.toLowerCase(product.name)} 
fn:toUpperCase 轉爲大寫字符 ${fn.UpperCase(product.name)} 
fn:trim 去除字符串先後的空格 ${fn.trim(name)}字符串

函數描述

fn:contains(string, substring) 若是參數string中包含參數substring,返回truefn:containsIgnoreCase(string, substring) 若是參數string中包含參數substring(忽略大小寫),返回truefn:endsWith(string, suffix) 若是參數 string 以參數suffix結尾,返回truefn:escapeXml(string) 將有特殊意義的XML (和HTML)轉換爲對應的XML character entity code,並返回fn:indexOf(string, substring) 返回參數substring在參數string中第一次出現的位置fn:join(array, separator) 將一個給定的數組array用給定的間隔符separator串在一塊兒,組成一個新的字符串並返回。fn:length(item) 返回參數item中包含元素的數量。參數Item類型是數組、collection或者String。若是是String類型,返回值是String中的字符數。fn:replace(string, before, after) 返回一個String對象。用參數after字符串替換參數string中全部出現參數before字符串的地方,並返回替換後的結果fn:split(string, separator) 返回一個數組,以參數separator 爲分割符分割參數string,分割後的每一部分就是數組的一個元素fn:startsWith(string, prefix) 若是參數string以參數prefix開頭,返回truefn:substring(string, begin, end) 返回參數string部分字符串, 從參數begin開始到參數end位置,包括end位置的字符fn:substringAfter(string, substring) 返回參數substring在參數string中後面的那一部分字符串fn:substringBefore(string, substring) 返回參數substring在參數string中前面的那一部分字符串fn:toLowerCase(string) 將參數string全部的字符變爲小寫,並將其返回fn:toUpperCase(string) 將參數string全部的字符變爲大寫,並將其返回fn:trim(string) 去除參數string 首尾的空格,並將其返回

相關文章
相關標籤/搜索