週報描述
- 繼續問卷調查系統答卷頁面的開發
- 完成各種題型答案的入庫
- 完成答卷詳情頁面的開發,從數據庫中查詢問卷答案並展示
下週計劃
週報筆記
-
FASTJSON常用操作:
//轉爲JSONObject String t; JSONObject jsonObject = new JSONObject(t); JSONObject jsonObject = JSONObject.parseObject(t); //解析數據 JSONObject jsonData = jsonObject.getJSONObject("data"); String jsonWeather = jsonData.getString("weather"); //解析數組 JSONArray jsonDaily =jsonData.getJSONArray("daily"); for (int i=0;i<jsonDaily.length();i++) JSONObject partDaily = jsonDaily.getJSONObject(i); //String轉爲Map Map maps = (Map)JSON.parse(jsonString); Map maps = (Map)JSONObject.parse(jsonString); Map maps = JSON.parseObject(jsonString, Map.class); Map maps = JSONObject.parseObject(jsonString, Map.class); Map maps = JSON.parseObject(jsonString); //List轉json List<T> obj String jsonStr = JSON.toJSONString(obj); //json轉換爲List<T> List<T> object = (List<T>)JSONArray.parseArray(jsonStr, model); //JSONObject轉String String StrObject = JSONObject.toJSONString(model);
-
生成UUID(去除橫槓):
SQL生成UUID:select replace(uuid(),'-','') from dual
JAVA生成UUID:
String uuid = UUID.randomUUID().toString().replaceAll("-","");
-
java字符串分割String.split()
public String[] split(String regex, int limit)
split() 方法根據匹配給定的正則表達式來拆分字符串。
注意: . 、 | 和 ***** 等轉義字符,必須得加 \。
注意:多個分隔符,可以用 | 作爲連字符。String[] aa = "aaa|bbb|ccc".split("\\|"); String[] aa = "aaa|bbb|ccc".split("\\*");
-
replace()和replaceAll()的區別
replace的參數是char和CharSequence,即可以支持字符的替換,也支持字符串的替換(CharSequence即字符串序列的意思,說白了也就是字符串);
replaceAll的參數是regex,即基於規則表達式的替換,比如:可以通過replaceAll("\\d", "*")
把一個字符串所有的數字字符都換成星號;
replaceAll支持正則表達式,因此會對參數進行解析(兩個參數均是),如replaceAll("\\d", "*")
,而replace則不會,replace("\d","*")就是替換"\d"的字符串,而不會解析爲正則。 -
String和Int互相轉換
String轉Int:s="10"; int i; 第一種方法:i=Integer.parseInt(s);//默認十進制 第二種方法:i=Integer.valueOf(s).intValue();`
Int轉String:
int i=10; String s=""; 第一種方法:s=i+""; 第二種方法:s=String.valueOf(i); 第三種方法:s=Integer.toString(i)
-
創建一個類型爲int的List時,用List報錯
List泛型裏面只能用對象類型,int是基本數據類型,只能用Integer;
List是接口,需要實現類ArrayList或者LinkedList,不能new List;List<Integer> toAns = new ArrayList<>();