zoukankan      html  css  js  c++  java
  • 批量插入工具

    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);
    }
    }

  • 相关阅读:
    WebApi 接口参数:传参详解
    WebApi 身份认证解决方案:Basic基础认证
    EF 底层封装方法(供参考)
    接口和抽象类的区别
    EF Code First 连接MySql
    EntityFramework Code-First—领域类配置之DataAnnotations
    驱动基本框架和与ring3通信
    必备理论知识
    通过远程代码注入实现不死进程
    PE文件中插入程序
  • 原文地址:https://www.cnblogs.com/cw828/p/11050735.html
Copyright © 2011-2022 走看看