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;
}
}
解决方案 »
- web项目可访问到界面,但是程序不运行
- 急救啊一用structs开启就出这种错误
- 如果是forward,struts2里怎么判断不出session里的对象是null
- 导入fmt标签出错
- 关于Hibenate中设置Oracle的递增主键问题
- 数据库(象sql server ,oralce,db2等等)都有日期字段,这些字段的数据可不可以统一转化为java.sql.Date呢?
- org.apache.commons.fileupload 应用时FORM 怎么提得非文件的值?
- 使用xerces验证XML的问题(xml.xsd import Schema)
- CMP 的问题
- JBuilder7Weblogic7整和开发CMP时编辑问题???急用!!急用!!
- springMVC 框架 注解注入问题
- 请问如何在界面输入一些公式,然后转成sql查询数据
XwxcAdoptDetall dad= (XwxcAdoptDetall) object[1];
XwxcMagArticle dma2 = new XwxcMagArticle();
BeanUtils.copyProperties(dma, dma2);
dma2.setDad(dad);
dlist.add(dma2);
没有看出这个解决了重复的问题。你只是为了存进去的XwxcMagArticle 不是相同的引用,这样有什么特别的做用吗?
我刚开始的理解是不想要重复的数据。
没有看出这个解决了重复的问题。你只是为了存进去的XwxcMagArticle 不是相同的引用,这样有什么特别的做用吗?
我刚开始的理解是不想要重复的数据。
XwxcMagArticle dma= (XwxcMagArticle) object[0];存在相同的对象,但是
3
4
5
6
XwxcMagArticle dma= (XwxcMagArticle) object[0];
XwxcAdoptDetall dad= (XwxcAdoptDetall) object[1];不相同