package com.withub.admgr.dao.xwxc;import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.springframework.stereotype.Component;import com.withub.admgr.core.dao.HibernateDao;
import com.withub.admgr.core.orm.query.Page;
import com.withub.admgr.entities.xwxc.XwxcAdoptDetall;
import com.withub.admgr.entities.xwxc.XwxcMagArticle;
import com.withub.admgr.entities.xwxc.XwxcSearchInfo;@Component
public class XwxcDao extends HibernateDao<XwxcMagArticle, Integer>{
public Page<XwxcMagArticle> getList(Page<XwxcMagArticle> page,XwxcSearchInfo search){

String hql = "from XwxcMagArticle dma,XwxcAdoptDetall dad where dad.aid=dma.id";
Map<String,Object> map = new HashMap<String, Object>();


if(search.getAuthor()!=null && !"".equals(search.getAuthor())){
hql+=" and dma.author like :author";
map.put("author", "%"+search.getAuthor()+"%");
}

if(search.getTjr()!=null && !"".equals(search.getTjr())){
hql+=" and dma.tjr like :tjr";
map.put("tjr", "%"+search.getTjr()+"%");
}

if(search.getTjr2()!=null && !"".equals(search.getTjr2())){
hql+=" and dma.tjr2 like :tjr2";
map.put("tjr2", "%"+search.getTjr2()+"%");
}

if(search.getTitle()!=null && !"".equals(search.getTitle())){
hql+=" and dma.title like :title";
map.put("title", "%"+search.getTitle()+"%");
}

if(search.getBegintime()!=null && !"".equals(search.getBegintime())){
hql+=" and dma.sendtime >=:begintime";
map.put("begintime", search.getBegintime());
}

if(search.getEndtime()!=null && !"".equals(search.getEndtime())){
hql+=" and dma.sendtime <=:endtime";
map.put("endtime", search.getEndtime());
}
if(search.getStyleid()!=null){
hql+=" and dma.styleid =:styleid";
map.put("styleid", search.getStyleid());
}
if(search.getImportantinfo()!=null){
hql+=" and dma.importantinfo =:importantinfo";
map.put("importantinfo", search.getImportantinfo());
}
if(search.getTimeliness()!=null){
hql+=" and dma.timeliness =:timeliness";
map.put("timeliness", search.getTimeliness());
}
if(search.getCybegintime()!=null && !"".equals(search.getCybegintime())){
hql+=" and dad.adopttime >=:cybegintime";
map.put("cybegintime", search.getCybegintime());
}
if(search.getCyendtime()!=null && !"".equals(search.getCyendtime())){
hql+=" and dad.adopttime <=:cyendtime";
map.put("cyendtime", search.getCyendtime());
}
long count = countHqlResult(hql, map);
page.setTotalCount(count);
List list = createQuery(hql,map).setFirstResult((page.getPageNo()-1)*page.getPageSize()).setMaxResults(page.getPageSize()).list();
List<XwxcMagArticle> dlist = new ArrayList<XwxcMagArticle>();
for (int i = 0; i < list.size(); i++) {
Object[] object = (Object[]) list.get(i);

XwxcMagArticle dma= (XwxcMagArticle) object[0];
XwxcAdoptDetall dad= (XwxcAdoptDetall) object[1];
dma.setDad(dad);
dlist.add(dma);
}
page.setResult(dlist);
return page;
}

public Long countHqlResult(String hql){
return  (Long) createQuery("select count(1) "+hql).uniqueResult();
}

public List<XwxcMagArticle> getByIds(Integer[] ids){
List<XwxcMagArticle> list = getSession().createQuery("select bean from XwxcMagArticle bean where bean.id in (:ids)").setParameterList("ids", ids).list();
return list;
} public boolean inner_bsxx(Integer[] ids) {
Integer result  = getSession().createQuery("update XwxcMagArticle set state=1 where  id in (:ids)").setParameterList("ids", ids).executeUpdate();
System.out.println("result="+result);
if(result>0){
return true;
}
return false;

}

解决方案 »

  1.   

    找到解決辦法了!!!修改80-83行XwxcMagArticle dma= (XwxcMagArticle) object[0];
    XwxcAdoptDetall dad= (XwxcAdoptDetall) object[1];
    XwxcMagArticle dma2 = new XwxcMagArticle();
    BeanUtils.copyProperties(dma, dma2);
    dma2.setDad(dad);
    dlist.add(dma2);
      

  2.   


    没有看出这个解决了重复的问题。你只是为了存进去的XwxcMagArticle 不是相同的引用,这样有什么特别的做用吗? 
    我刚开始的理解是不想要重复的数据。
      

  3.   


    没有看出这个解决了重复的问题。你只是为了存进去的XwxcMagArticle 不是相同的引用,这样有什么特别的做用吗? 
    我刚开始的理解是不想要重复的数据。
    XwxcMagArticle dma= (XwxcMagArticle) object[0];存在相同的对象,但是
    3
    4
    5
    6
    XwxcMagArticle dma= (XwxcMagArticle) object[0];
    XwxcAdoptDetall dad= (XwxcAdoptDetall) object[1];不相同