现在我有2个对象,一个是热线单HotLineInfo,另一个是热线类别HotLineType,一对多关系
(1:N-----HotLineInfo:HotLineType),
         //这个是HotLineType实体类
private String hotlineTypeGuid;
private HotlineHotlineInfo hotlineHotlineInfo;
private String hotlineTypeId;
         //这个是HotLineInfo实体类
         private String hotlineInfoGuid;
private String hotlineId; //热线单号
//还有一些其他属性
private Set hotlineMaintenances = new HashSet(0);
private Set hotlineHotlineTypes = new HashSet(0);         页面上是<input type="checkbox" name="type" value="hotlineId">
                 <input type="checkbox" name="type" value="hotlineId">
                 <input type="checkbox" name="type" value="hotlineId">          //这里是Service层的DetachedCriteria 条件判断
          DetachedCriteria dc = DetachedCriteria.forClass(HotlineHotlineInfo.class);
          请问当type被选择后,如何将其添加为dc的条件,或者说如何查询出包涵某类别的
          热线单。

解决方案 »

  1.   

    <input type="checkbox" name="type" value="hotlineId"> 
                    <input type="checkbox" name="type" value="hotlineId"> 
                    <input type="checkbox" name="type" value="hotlineId"> 在通过struts 的时候你就应该能得到type的值是一个数组。
      

  2.   

    是的,可以拿到type的一个数组,我想问问在DetachedCriteria组装条件的时候怎么弄,望高手解题哇
      

  3.   


    楼主这个要求不需要用DetachedCriteria,这样就可以了:
    String hotlineTypeId = "xxxx";
    Criteria c1 = session.createCriteria(HotlineHotlineInfo.class);
    Criteria c2 = c1.createCriteria("hotlineHotlineTypes");
    c2.add(Restrictions.eq("hotlineTypeId", hotlineTypeId));
      

  4.   

    hotTypes 是的到的类别数组
    if(hotTypes!=null){
    String hotTypeId = hotTypes[0];
    if(hotTypes.length >=2){
    for(int i=1;i<hotTypes.length;i++){
    hotTypeId =hotTypeId+",'"+ hotTypes[i].trim()+"'";
    }
    }
    dc.add(Restrictions.sqlRestriction("exists (select null from dbo.Hotline_HotlineType where HotlineInfoGUID = this_ .HotlineInfoGUID and HotlineTypeID in ("+hotTypeId+"))"));
    }
    这样就可以了,呵呵