随笔 -Hibernate Query查找


@Override
    public ArrayList<ContentExt> findListBaseContentExt(int ChannelId,
            int startPage ,int endPage) {
        String sql = " select contentext1_.content_id , contentext1_.title ,contentext1_.short_title , "+
        "contentext1_.description ,contentext1_.author ,contentext1_.origin , " +
        "contentext1_.origin_url , contentext1_.release_date ,contentext1_.media_path , "+
        "contentext1_.media_type , contentext1_.title_color ,contentext1_.is_bold , "+
        "contentext1_.title_img ,contentext1_.content_img ,contentext1_.type_img , " +
       " contentext1_.type_img118 ,contentext1_.type_img170 ,contentext1_.type_img900 ,"+
       " contentext1_.link ,contentext1_.tpl_content ,contentext1_.need_regenerate , "+
       " channel2_.channel_path "+
     "   from " +
      "  jc_content content0_  " +
  "  inner join "+
      "  jc_content_ext contentext1_  "+
       "     on content0_.content_id=contentext1_.content_id  " +
     " inner join " +
     "   jc_channel channel2_  "+
     "       on content0_.channel_id=channel2_.channel_id, " +
      "  jc_channel channel3_  " +
   " where " +
    "   ( " +
    "        channel2_.lft between channel3_.lft and channel3_.rgt " +
      " )  "+
      "  and content0_.site_id=channel3_.site_id  " +
     "   and channel3_.channel_id= " + ChannelId
        
       + "  and content0_.status=2 " +
   " order by " +
  " contentext1_.release_date desc limit " + startPage+","+endPage ;
        
        List<ContentExt> contextExtList = new ArrayList<ContentExt> ();
        Query query = getSession().createSQLQuery(sql);
        List list =  query.list();
        System.out.println(list.size());
         Iterator iter = list.iterator();
         SimpleDateFormat dateformat=new SimpleDateFormat("yyyyMMdd");
          
            while(iter.hasNext()){
                Object[] obj = (Object[])iter.next();
                ContentExt contentExt = new ContentExt();
                int id = (Integer)obj[0];
                String title=(String)obj[1];
                String short_title=(String)obj[2];
                String description=(String)obj[3];
                String author=(String)obj[4];
                String origin=(String)obj[5];
                String origin_url=(String)obj[6];
                Date release_date=(Date)obj[7];
                String media_path=(String)obj[8];
                String media_type=(String)obj[9];
                
                String title_color=(String)obj[10];
         //       String is_bold=(String)obj[11];
                String title_img=(String)obj[12];
                String content_img=(String)obj[13];
                String type_img=(String)obj[14];
                String type_img118=(String)obj[15];
                String type_img170=(String)obj[16];
                String type_img900=(String)obj[17];
                String link=(String)obj[18];
                String tpl_content=(String)obj[19];
          //      Boolean need_regenerate=(Boolean)obj[20];
                String channel_path=(String)obj[21];
                contentExt.setId(id);
                contentExt.setTitle(title);
                contentExt.setShortTitle(short_title);
                contentExt.setDescription(description);
                contentExt.setAuthor(author);
                contentExt.setOrigin(origin);
                contentExt.setOriginUrl(origin_url);
                contentExt.setReleaseDate(release_date);
                contentExt.setMediaPath(media_path);
                contentExt.setMediaType(media_type);
                contentExt.setTitleColor(channel_path); //channel_path
                contentExt.setTypeImg(type_img);
                String releaseDate=dateformat.format(release_date);
                contentExt.setLink(releaseDate); //日期
                contentExt.setTplContent(tpl_content);
          //      contentExt.setNeedRegenerate(need_regenerate);
                contextExtList.add(contentExt);
                System.out.println("id:"+id +";title:"+title +";release_date" +release_date);
            }   
        return  (ArrayList<ContentExt>) contextExtList;
    }  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。