springboot常用專案結構與工具類

2021-10-02 10:02:15 字數 1977 閱讀 9036

一、常用的專案結構及說明

2、configs(放置通用的配置)、utils(放置通用的工具)、exceptions(放置自定義的異常型別和異常處理)、commons(放置一些通用的基礎類)

二、常用配置與工具

1、跨域配置

@configuration

public class corsconfig

}

2、restremplate請求配置

}3、正則校驗工具(常用的手機號、驗證碼格式校驗)

public class regexutils $";

pattern pattern = pattern.compile(regex);

matcher matcher = pattern.matcher(phonenum);

return matcher.matches();

}/**

* 驗證碼正則檢驗

*/public static boolean vercoderegex(string vercode) $";

pattern pattern = pattern.compile(regex);

matcher matcher = pattern.matcher(vercode);

return matcher.matches();}}

4、時間格式化與解析相關工具

public class timeutil 

/*** 解析標準時間格式引數為十三位時間戳

* @param time 標準格式時間

* @param sdf 時間格式

*/public static long parsetime(string time, ******dateformat sdf) throws parseexception catch (parseexception e)

}/**

* 格式化時間戳為標準格式時間

* @param timestamp 時間戳

* @param sdf 時間格式

*/public static string formattime(long timestamp, ******dateformat sdf)

}

5、字串處理相關工具

public class stringutil 

} else

}return false;

}/**

* 對單個字串進行去除空格操作

*/public static string trim(string str) else

}return null;}}

6、反射相關工具(在實際業務中我們返回給前端的物件往往包含許多null值,對於前端往往需要做很多判斷,使用反射我們能給一些欄位在返回的結果中設定預設值,減少前端的判斷)

public class reflectutil

} catch (illegalacces***ception e) }}

return t;

}/**

* 設定物件integer型別的屬性如果為null則全部轉換為0

*/public t updateint(t t)

} catch (illegalacces***ception e) }}

return t;}}

xcode常用專案模板

xcode常用的專案模板中,主要有以下幾類 開啟masterviewcontroller.swift檔案 override func tableview tableview uitableview,caneditrowatindexpath indexpath nsindexpath bool這個是...

常用專案js驗證

通過js驗證方法 方法 驗證是否為數字 demo var s 520 s.isnumber string.prototype.isnumber function 方法 驗證是否為中文 demo var s 動感 s.ischinese string.prototype.ischinese funct...

python 常用專案列表

專案名稱 作用numpy numpy numerical python 是 python 語言的乙個擴充套件程式庫,支援大量的維度陣列與矩陣運算,此外也針對陣列運算提供大量的數學函式庫。最牛的庫 matplotlib matplotlib 是 python 的繪相簿。它可與 numpy 一起使用,提...