zoukankan      html  css  js  c++  java
  • tester

    public class Tester {
    /**
    * @param args
    */
    public static void main(String[] args) {

    List<DbEntity> dbList= new ArrayList<DbEntity>();

    DbEntity db1 = new DbEntity();
    db1.setKey("key1");
    db1.setShohinServiceCd("code1");
    db1.setCol2("col20");
    db1.setCol3("col30");
    db1.setDelFlg("0");
    dbList.add(db1);

    DbEntity db2 = new DbEntity();
    db2.setKey("key1");
    db2.setShohinServiceCd("code2");
    db2.setCol2("col20");
    db2.setCol3("col30");
    db2.setDelFlg("0");
    dbList.add(db2);

    DbEntity db3 = new DbEntity();
    db3.setKey("key1");
    db3.setShohinServiceCd("code3");
    db3.setCol2("col20");
    db3.setCol3("col30");
    db3.setDelFlg("1");
    dbList.add(db3);

    DbEntity db4 = new DbEntity();
    db4.setKey("key1");
    db4.setShohinServiceCd("code4");
    db4.setCol2("col20");
    db4.setCol3("col30");
    db4.setDelFlg("0");
    dbList.add(db4);

    DbEntity db5 = new DbEntity();
    db5.setKey("key1");
    db5.setShohinServiceCd("code5");
    db5.setCol2("col20");
    db5.setCol3("col30");
    db5.setDelFlg("1");
    dbList.add(db5);

    DbEntity db6 = new DbEntity();
    db6.setKey("key2");
    db6.setShohinServiceCd("code1");
    db6.setCol2("col21");
    db6.setCol3("col31");
    db6.setDelFlg("0");
    dbList.add(db6);

    FormEntity form = new FormEntity();
    form.setKey("key1");
    form.setCol2("col22");
    form.setCol3("col32");
    List<ShohinServiceEntity> shohinServiceList = new ArrayList<ShohinServiceEntity>();
    ShohinServiceEntity entity1 = new ShohinServiceEntity();
    entity1.setShohinServiceCd("code1");
    entity1.setShohinServiceName("name1");

    ShohinServiceEntity entity4 = new ShohinServiceEntity();
    entity4.setShohinServiceCd("code4");
    entity4.setShohinServiceName("name4");

    ShohinServiceEntity entity5 = new ShohinServiceEntity();
    entity5.setShohinServiceCd("code5");
    entity5.setShohinServiceName("name5");

    ShohinServiceEntity entity6 = new ShohinServiceEntity();
    entity6.setShohinServiceCd("code6");
    entity6.setShohinServiceName("name6");

    shohinServiceList.add(entity1);
    shohinServiceList.add(entity4);
    shohinServiceList.add(entity5);
    shohinServiceList.add(entity6);

    form.setShohinService(shohinServiceList);

    List<DbEntity> newDb = mergeList(dbList, form);

    for(DbEntity dbEntity : newDb){
    System.out.print(dbEntity.getKey()+" ");
    System.out.print(dbEntity.getShohinServiceCd()+" ");
    System.out.print(dbEntity.getCol2()+" ");
    System.out.print(dbEntity.getCol3()+" ");
    System.out.println(dbEntity.getDelFlg()+" ");
    }
    }

    private static List<DbEntity> mergeList(List<DbEntity> dbList, FormEntity form) {
    boolean IfDbisInForm = false;//判断db中的数据是否在form内
    for (DbEntity dbItem : dbList) {
    IfDbisInForm=false;//flag在每次进循环时都要置为false
    //判断key是否相等,若相等才进行处理
    if(dbItem.getKey()==form.getKey()) {
    for (ShohinServiceEntity formItem : form.getShohinService()) {
    //判断db中商品code是否在form中存在,若存在则flag置为0且col2col3进行赋值,若不在则将flag置为1
    if(dbItem.getShohinServiceCd().equals(formItem.getShohinServiceCd()) ) {
    dbItem.setDelFlg("0");
    dbItem.setCol2(form.getCol2());
    dbItem.setCol3(form.getCol3());
    IfDbisInForm=true;
    }
    }
    if(!IfDbisInForm) {
    dbItem.setDelFlg("1");
    }
    }
    }

    //将form中存在的数据且db中没有的数据加入到db中
    boolean IfFormisInDb = false;//判断form中的数据是否在db内
    for (ShohinServiceEntity formItem : form.getShohinService()) {
    IfFormisInDb = false;//flag在每次进循环时都要置为false
    for (DbEntity dbItem : dbList) {
    if(formItem.getShohinServiceCd().equals(dbItem.getShohinServiceCd())) {
    IfFormisInDb = true;
    }
    }
    if(!IfFormisInDb) {
    DbEntity tempDb = new DbEntity();
    tempDb.setKey(form.getKey());
    tempDb.setShohinServiceCd(formItem.getShohinServiceCd());
    tempDb.setCol2(form.getCol2());
    tempDb.setCol3(form.getCol3());
    tempDb.setKey("0");
    }
    }
    return dbList;

    }
    }

  • 相关阅读:
    ORACLE【0】:基本操作
    ORACLE【3】:分区表以及分区索引
    ORACLE【2】:锁机制及解锁
    log4j学习一:解决系统日志错位问题
    使用一个非堵塞的socket用于接收http请求
    Python中文转换报错 'ascii' codec can't decode byte 0xe8 in position
    首次使用Redis记录【3】
    xsi:schemaLocation有何作用
    【转】【redis】3.Spring 集成注解 redis 项目配置使用
    maven仓库地址
  • 原文地址:https://www.cnblogs.com/xiaohou666zy/p/15390892.html
Copyright © 2011-2022 走看看