对封装的再次理解(容器)

如下:

这两天做一个功能,一个页面有多个同样的对象(List),进入页面需要遍历list,但是这个list中还有一个list,不是同一张表,一个是另一个的子表,单个对象的保存搞定了,但是遍历时对'对象'的封装没有思绪,根本没往这块想,折腾了好久;

后来想到了容器,不就是一个大箱子里面套了另一个小箱子吗?很常见,但是从来没有往这里想过;

解决方法,在大对象里面再加一个属性,该属性对应的就是小对象的list,在大对象里面set进去就可以了,在页面进行双重遍历即可;相关代码如下:

大对象实体类:

public class CrmCounterguaranteeProWithBLOBs extends CrmCounterguaranteePro
{
    @Getter
    @Setter
    private String otherinfo;

    @Getter
    @Setter
    private String remarks;
    
    @Getter
    @Setter
    public List<CrmReveOwners> reveOwners;//封装的小对象
}

数据关联

// "房产",(2),
List<CounterGuaranteeInfo> houses = new ArrayList<CounterGuaranteeInfo>();
//查询抵押反担保共有人、所有人信息
if (null != info && null != info.getGuaranteeInfo()) 
{
    CrmReveOwnersExample dyExample =new CrmReveOwnersExample();
    dyExample.createCriteria().andProjidEqualTo(info.getGuaranteeInfo().getProjid()).andFaserialidEqualTo(info.getGuaranteeInfo().getFaserialid());
    listhousesOwners = crmReveOwnersDao.selectByExample(dyExample);
}
//封装共有人信息到对象
if (null != listhousesOwners && listhousesOwners.size()>0) 
{
    info.getGuaranteeInfo().setReveOwners(listhousesOwners);                    }
houses.add(info);
result.put("houseReveInfos" + revetype, houses);//返回到页面的数据

在页面遍历显示:

<!-- 房屋抵押 -->
<s:if test="!#request.guarantees.houseReveInfos1.isEmpty">
<s:iterator value="#request.guarantees.houseReveInfos1" var="house" status="sts">
<tr>  
      <td  style="text-align:center;">
         <img  src="<s:url value="/css/themes/icons/updown.png" />"   style="cursor:pointer" onclick="showDiv('housebz<s:property value="#sts.count"/>')"/>
      </td>
      
      <td style="text-align:center;">抵押-房产</td>
      
      <td style="text-align:center;">
            <s:if test='#house.exInfo.customerType == "1"'><s:property value="#house.exInfo.legal.name"/></s:if>       
            <s:elseif test='#house.exInfo.customerType == "2"'><s:property value="#house.exInfo.person.name"/></s:elseif>
      </td>
      
      <td style="text-align:center;">           
          <s:property value="#house.guaranteeInfo.rrightlid"/>
      </td>
      
      <td style="text-align:center;">           
          <s:property value="#house.guaranteeInfo.originalvalue"/>
      </td>
      
      <td style="text-align:center;">           
          <s:property value="#house.guaranteeInfo.hypovalue"/>
      </td>
      
       <td  style="text-align:center;">
        <img  src="<s:url value="/css/themes/icons/pencil.png" />"  alt="编辑数据" 
        style="cursor:pointer"
        onclick="openInnerWinByOwnerShip('edit','','<s:property value="projid"/>','<s:property value="customerid"/>',
                                '1','2','<s:property value="#house.guaranteeInfo.faserialid" />','deposit_guarantee')"/>
       
        <img  src="<s:url value="/css/themes/icons/cancel.png" />"  alt="删除数据" 
         style="cursor:pointer"
        onclick="delGuaranteeInfo('<s:property value="projid"/>','<s:property value="customerid"/>',
                                '1','2','<s:property value="#house.guaranteeInfo.faserialid" />')"/>&nbsp;
        </td>
 </tr>
 <tr>
 <td colspan="7">
 <div id="housebz<s:property value="#sts.count"/>"  style="display:none">
     <table cellspacing=0 cellpadding=0 border=0 width="80%" class="reporttable border1">
     <tr>   
          <td width="20%" class="td_left"><s:if test="#request.guarantees.houseReveInfos1.size>1"><div style="float:left;margin-left:10px;">(<s:property value="#sts.count"/>)</div></s:if>姓名:房屋名称:</td>
          <td align="left" width="30%">
               <s:property value="#house.guaranteeInfo.rrightname"/></td>
          <td width="20%" class="td_left">权证编号:</td>
          <td align="left" width="30%">           
              <s:property value="#house.guaranteeInfo.rrightlid"/>
          </td>
     </tr>
    ........
    <tr>
          <td width="20%" class="td_left">
              <s:if test="#house.guaranteeInfo.owner == 1 || #house.guaranteeInfo.owner == 0">
                    是否存在共有人:
              </s:if>
              <s:else>
                    所有/共有人:
              </s:else>
          </td>
          <td align="left">
              <s:if test="#house.guaranteeInfo.owner == 1 || #house.guaranteeInfo.owner == 0">
                  <dict:message dictTypeId="BMS_COMM_YESNO" value="%{#house.guaranteeInfo.owner}"/>
              </s:if>
              <s:else>
                  <s:property value="#house.guaranteeInfo.owner"/>                                      
              </s:else>
          </td>
         <td width="20%" class="td_left">是否与项目关联:</td>
          <td align="left" >
                <dict:message dictTypeId="IS_LINK_PROJ" value="%{#house.guaranteeInfo.islinkproj}"/>
          </td>
    </tr>

    <s:if test="#house.guaranteeInfo.owner == 1 && !#house.guaranteeInfo.reveOwners.isEmpty ">
        <tr  id="ownersMsg" > 
            <td width="20%" class="td_left">所有/共有人:</td>
            <td align="left"  colspan="3"  >
                <s:if test="#house.guaranteeInfo. == 1 
                <table class="report_table border1" style="width:100%" id="revepersonid">
                    <tr class="tr_title">           
                        <td  style="width:10px;text-align:center;">类型</td>    
                        <td  style="width:20px;text-align:center;">姓名</td>
                        <td  style="width:30%;text-align:center;" >身份证</td>  
                        <td  style="width:10%;text-align:center;" >性别</td>  
                        <td  style="width:15%;text-align:center;" >电话</td>      
                        <td  style="width:15%;text-align:center;" >与借款人关系</td>      
                    </tr>
                    <s:iterator value="#house.guaranteeInfo.reveOwners" var="dyOwners" status="stus">
                        <tr >  
                            <td style="text-align:center;">
                                <dict:message dictTypeId="BMS_COUSTOMER_TYPE" value="%{ownertype}"/>
                            </td>
                            <td style="text-align:center;">
                                <s:property value="ownersname"/>
                            </td>
                            <td style="text-align:center;">
                                <s:property value="owneridcode"/>
                            </td>
                            <td style="text-align:center;">
                                <s:property value="ownersex"/>
                            </td> 
                            <td style="text-align:center;">
                                <s:property value="linktel"/>
                            </td>
                            <td style="text-align:center;">
                                <dict:message dictTypeId="BMS_FAMILY_MEMBERS_RELA" value="%{relation}"/>
                            </td>
                        </tr>
                    </s:iterator>
                </table>
            </td>
        </tr>
    </s:if>

end;

 

posted @ 2019-09-06 12:02  xh_Blog  阅读(364)  评论(0编辑  收藏  举报