• 批量插入工具


    public void insertBeach(Object obj) {

    Gson gsobj = new Gson();
    @SuppressWarnings("unchecked")
    Map<String, Object> jsonStringToMap = gsobj.fromJson(obj.toString(), HashMap.class);
    ii(reList(jsonStringToMap, Projects.class));
    }

    public <T> void ii(List<T> list) {
    if (list != null && !list.isEmpty()) {
    String simpleName = list.get(0).getClass().getSimpleName();

    simpleName = "com.cn.ag.data.dao.interf.sc." + simpleName + "Mapper.";

    insertList(simpleName,list);

    } else {
    System.out.println("刺激和为空 没有数据插入");
    }
    }

    public String getMapperName(Class clz) {
    String simpleName = clz.getSimpleName();
    return "com.cn.ag.data.dao.interf.sc." + simpleName + "Mapper.";
    }

    public <T> List<T> reList(Map<String, Object> map, Class<T> clazz) {

    List<Object> object = (List<Object>) map.get(clazz.getSimpleName().toLowerCase());

    if (object == null || object.isEmpty()) {
    return null;
    }

    List<T> lsit = new ArrayList<T>();
    try {
    for (Object t : object) {
    Object jsonToAnyObject = gm.jsonToAnyObject(JSON.toJSONString(t), clazz);
    lsit.add(clazz.cast(jsonToAnyObject));
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    System.out.println(lsit.toString());
    return lsit;
    }

    public <T> void insertList(String simpleName,List<T> list) {
    if (list.size() > 70) {
    insertMapperImpl.insertBeach(simpleName, list.subList(0, 70));

    insertList(simpleName,list.subList(70,list.size()));

    }else {
    insertMapperImpl.insertBeach(simpleName, list);
    }
    }

  • 相关阅读:
    nyoj 21三个水杯(BFS + 栈)
    hdu 4493 Tutor
    树的判断(poj nyoj hduoj)
    nyoj 228 士兵杀敌(五)
    poj 3468 A Simple Problem with Integers(线段树)
    hdu 2565 放大的X
    nyoj 528 找球号(三)(哈希)
    nyoj 138 找球号(二)(哈希)
    算法之搜索篇
    每日命令:(11)nl
  • 原文地址:https://www.cnblogs.com/cw828/p/11050735.html
Copyright © 2020-2023  润新知