个人实习周报2019-11-04

周报描述

  1. 继续问卷调查系统答卷页面的开发
  2. 完成各种题型答案的入库
  3. 完成答卷详情页面的开发,从数据库中查询问卷答案并展示

下周计划

周报笔记

  1. 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);
    
  2. 生成UUID(去除横杠):
    SQL生成UUID:

    select replace(uuid(),'-','') from dual
    

    JAVA生成UUID:

    String uuid = UUID.randomUUID().toString().replaceAll("-","");
    
  3. java字符串分割String.split()

    public String[] split(String regex, int limit)
    

    split() 方法根据匹配给定的正则表达式来拆分字符串。
    注意: .| 和 ***** 等转义字符,必须得加 \
    注意:多个分隔符,可以用 | 作为连字符。

    String[] aa = "aaa|bbb|ccc".split("\\|");
    String[] aa = "aaa|bbb|ccc".split("\\*");
    
  4. replace()和replaceAll()的区别
    replace的参数是char和CharSequence,即可以支持字符的替换,也支持字符串的替换(CharSequence即字符串序列的意思,说白了也就是字符串);
    replaceAll的参数是regex,即基于规则表达式的替换,比如:可以通过replaceAll("\\d", "*")把一个字符串所有的数字字符都换成星号;
    replaceAll支持正则表达式,因此会对参数进行解析(两个参数均是),如replaceAll("\\d", "*"),而replace则不会,replace("\d","*")就是替换"\d"的字符串,而不会解析为正则。

  5. 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)
    
  6. 创建一个类型为int的List时,用List报错
    List泛型里面只能用对象类型,int是基本数据类型,只能用Integer;
    List是接口,需要实现类ArrayList或者LinkedList,不能new List;

    List<Integer> toAns = new ArrayList<>();
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章