日期:2014-05-18  浏览次数:20637 次

List集合中包含相同對象,結果集造成後者值覆蓋前者對象

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[]&n