編程小知識(shí)【java-0009】java常用開發(fā)庫(kù)-Spring工具類
內(nèi)置Resource類型
org.springframework.core.io.UrlResource:訪問網(wǎng)絡(luò)資源
org.springframework.core.io.ClassPathResource:訪問類路徑下資源
org.springframework.core.io.FileSystemResource:訪問文件系統(tǒng)資源
org.springframework.web.context.support.ServletContextResource:訪問相關(guān)Web應(yīng)用程序根目錄中的相對(duì)路徑
org.springframework.core.io.InputStreamResource:輸入流的Resource實(shí)現(xiàn)類,一般在沒有特定的資源實(shí)現(xiàn)的時(shí)候使用
org.springframework.core.io.ByteArrayResource:字節(jié)數(shù)組的Resource實(shí)現(xiàn)類
org.springframework.core.io.support.EncodedResource :就是Resource加上encoding, 可以認(rèn)為是有編碼的資源。當(dāng)您使用 Resource 實(shí)現(xiàn)類加載文件資源時(shí),它默認(rèn)采用操作系統(tǒng)的編碼格式。如果文件資源采用了特殊的編碼格式(如 UTF-8),則在讀取資源內(nèi)容時(shí)必須事先通過 EncodedResource 指定編碼格式,否則將會(huì)產(chǎn)生中文亂碼的問題。
org.springframework.core.io.VfsResource:在jboss里經(jīng)常用到, 相應(yīng)還有 工具類 VfsUtils
org.springframework.util.ResourceUtils:它支持“classpath:”和“file:”的地址前綴,它能夠從指定的地址加載文件資源,常用方法:getFile()
常用工具類
org.springframework.util.Assert:斷言工具類,通常用于數(shù)據(jù)合法性檢查
org.springframework.web.context.support.WebApplicationContextUtils:獲取spring應(yīng)用的上下文,即 WebApplicationContext 對(duì)象
org.springframework.web.bind.ServletRequestUtils:web請(qǐng)求工具類,主要功能是用來從請(qǐng)求中解析被綁定的參數(shù)
org.springframework.util.FileCopyUtils:文件的拷貝處理,提供了許多一步式的靜態(tài)操作方法,能夠?qū)⑽募?nèi)容拷貝到一個(gè)目標(biāo) byte[]、String 甚至一個(gè)輸出流或輸出文件中
org.springframework.core.io.support.PropertiesLoaderUtils:允許您直接通過基于類路徑的文件地址加載屬性資源
org.springframework.util.StringUtils:字符串工具類
org.springframework.util.CollectionUtils:集合工具類
org.springframework.util.NumberUtils:處理數(shù)字工具類
org.springframework.util.SerializationUtils:對(duì)象序列化與反序列化
org.springframework.util.DigestUtils:MD5加密
org.springframework.util.PatternMatchUtils:處理簡(jiǎn)單的匹配
org.springframework.util.PropertyPlaceholderHelper:處理占位符的替換
org.springframework.util.ReflectionUtils:反射常用工具方法. 有 findField, setField, getField, findMethod, invokeMethod等有用的方法