開(kāi)源俱樂(lè)部

          開(kāi)源框架

          在Strut中,實(shí)現(xiàn)table中復(fù)制一行的功能
          line[j]是要復(fù)制的一行,Action中可以獲取到要復(fù)制的行的ID.
          因?yàn)閘ine[j]中有很多屬性,要是一個(gè)一個(gè)的屬性去get,然后set的話,代碼量會(huì)
          很大,而且會(huì)出現(xiàn)很多冗余代碼。
          這是我要復(fù)制出來(lái)的一行
          if (j == rowId && !line[j].getNewRecord()) {
               rowList.add(line[j]);
               //將這一行全部復(fù)制
              }
          現(xiàn)在要使得其中的某幾個(gè)屬性復(fù)制出來(lái)為空
          則需要一個(gè)一個(gè)的set,get.
          if (j == rowId && !line[j].getNewRecord()) {
              CreateDeliveryLineRow  cdlr = new CreateDeliveryLineRow  ();
              if(line[j].getMfgLot() != null){
                   cdlr.setMfgLot = null;
             }
          。。。。。。
               rowList.add(cdlr);
               //將這一行全部復(fù)制
              }

          以下是比較好的解決方案:
          利用apache的common類中的BeanUtils來(lái)實(shí)現(xiàn)對(duì)象屬性的復(fù)制
          if (j == rowId && !line[j].getNewRecord()) {
               
                 
                 CreateDeliveryLineRow row = new CreateDeliveryLineRow();
                 BeanUtils.copyProperties(row,line[j]);   //復(fù)制出對(duì)象line[j],將其屬性賦予row
                 row.setQuantity(null);                                     //在row中輕松的實(shí)現(xiàn)對(duì)某幾個(gè)屬性的控制
                 row.setMfgLot(null);
                 row.setMiniQuantity(null);
                 row.setBoxQuantity(null);
                rowList.add(row);
                //rowList.add(cdr);
              }
          ===================================================
          CreateDeliveryForm getForm = (CreateDeliveryForm) form;
          。。。。。。
          CreateDeliveryLineRow[] line = getForm.getLine();
          if (line != null && line instanceof CreateDeliveryLineRow[]) {
             int size = line.length;

             for (int j = 0; j < size; j++) {
              if (!line[j].getNewRecord() && !line[j+1].getNewRecord()) {
               if (line[j].getBoxQuantity() == 0L) {
                line[j].setBoxQuantity(null);
               }
               if (line[j].getMiniQuantity() == 0L) {
                line[j].setMiniQuantity(null);
               }
               if (line[j].getQuantity() == 0D) {
                line[j].setQuantity(null);
               }
               rowList.add(line[j]);
              }
              if (j == rowId && !line[j].getNewRecord()) {
               
                 
                 CreateDeliveryLineRow row = new CreateDeliveryLineRow();
                 BeanUtils.copyProperties(row,line[j]);
                 row.setQuantity(null);
                 row.setMfgLot(null);
                 row.setMiniQuantity(null);
                 row.setBoxQuantity(null);
                 rowList.add(row);
                //rowList.add(cdr);
              }

             }
            }

          。。。。。。
          request.setAttribute("results", rowList);
          主站蜘蛛池模板: 柯坪县| 安岳县| 依安县| 乡宁县| 上思县| 临高县| 南岸区| 镇安县| 咸宁市| 灌南县| 佛教| 阆中市| 玉林市| 大港区| 大姚县| 赣榆县| 合川市| 呼玛县| 固始县| 科技| 临清市| 灌阳县| 曲水县| 屏东县| 石屏县| 淮北市| 无棣县| 惠水县| 会宁县| 寿阳县| 灵石县| 珲春市| 新化县| 宜城市| 莲花县| 东港市| 定结县| 焦作市| 绍兴县| 定襄县| 和顺县|