Spring的一些常用工具類

2021-06-21 11:56:28 字數 2083 閱讀 5573

出處:

1) 請求工具類org.springframework.web.bind.servletrequestutils

//取請求引數的整數值:

public static integer getintparameter(servletrequest request,string name)

public static int getintparameter(servletrequest request,string name, int defaultval) -->單個值

public static int getintparameters(servletrequest request,string name) -->陣列

還有譬如long、float、double、boolean、string的相關處理方法。

2) 字串工具類 org.springframework.util.stringutils

首字母大寫: public static string capitalize(string str)

首字母小寫:public static string uncapitalize(string str)

判斷字串是否為null或empty: public static boolean haslength(stringstr)

判斷字串是否為非空白字串(即至少包含乙個非空格的字串):public static booleanhastext(string str)

獲取檔名:public static string getfilename(string path) 如e.g."mypath/myfile.txt" -> "myfile.txt"

獲取副檔名:public static string getfilenameextension(string path)如"mypath/myfile.txt" -> "txt"

還有譬如陣列轉集合、集合轉陣列、路徑處理、字串分離成陣列、陣列或集合合併為字串、陣列合併、向陣列新增元素等。

3) 物件序列化與反序列化org.springframework.util.serializationutils

public static byte serialize(object object)

public static object deserialize(byte bytes)

4) 數字處理 org.springframework.util.numberutils

字串轉換為number並格式化,包括具體的number實現類,如long、integer、double,字串支援16進製制字串,並且會自動去除字串中的空格:

publicstatic tparsenumber(string text, classtargetclass)

publicstatic tparsenumber(string text, classtargetclass,numberformatnumberformat)

各種number中的轉換,如long專為integer,自動處理數字溢位(丟擲異常):

public static t convertnumbertotargetcla

ss(number number,classtargetclass)

5) 檔案複製 org.springframework.util.filecopyutils

流與流之間、流到字串、位元組陣列到流等的複製

6) 目錄複製 

org.springframework.util.filesystemutils

遞迴複製、刪除乙個目錄

7)md5加密 

org.springframework.util.digestutils

位元組陣列的md5加密 public staticstring md5digestashex(byte bytes)

常用工具類

本講內容 常用工具類 陸續更新 author administrator public static context context public void oncreate public static context getcontext 2 提供所有activity呼叫 基類 author ad...

常用工具類

reflectionutils objectutils public static void main string args 判斷兩個陣列是否相等 system.out.println arrays.equals arr,arr true 列印陣列 string s1 arrays.tostrin...

常用工具(一)

1 鏈結 2 說明 可以通過此工具 將時間戳轉為具體時間點,也可以將具體時間點轉為時間戳 3 效果 1 鏈結 2 說明 當你有一串很亂的json串不可讀時,可通過此工具得到一串工整的json串,便於閱讀 3 效果 1 鏈結 2 說明 通過此工具,你可以進行gbk碼 ascii碼 unicode碼和中...