//删除一个
public void deleteByInfoId(final String infoId) {
try {
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "delete "+getClazz().getName()+" where infoId = :infoId";
Query query = session.createQuery(hql);
query.setParameter("infoId", infoId);
return query.executeUpdate();
}
});
} catch (org.springframework.dao.DataAccessException e) {
// TODO Auto-generated catch block
throw new DataAccessException(e.getMessage(),e);
}
}
==============================================
批量删除
public void deleteExhibitionShowList(final List<String> list) {
// TODO Auto-generated method stub
try {
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "delete "+getClazz().getName()+" where showId in(:ids)";
Query query = session.createQuery(hql);
query.setParameterList("ids", list);
return query.executeUpdate();
}
});
} catch (org.springframework.dao.DataAccessException e) {
// TODO Auto-generated catch block
throw new DataAccessException(e.getMessage(),e);
}
}
//批量更新 日期
public void update(final List<String> list, final String state) {
// TODO Auto-generated method stub
try {
this.getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
String hql = "update "+getClazz().getName()+" set approveStateId = :state where showApplyId in(:ids)";
Query query = session.createQuery(hql);
query.setParameter("state", state);
query.setParameterList("ids", list);
return query.executeUpdate();
}
});
} catch (org.springframework.dao.DataAccessException e) {
// TODO Auto-generated catch block
throw new DataAccessException(e.getMessage(),e);
}
}
//分页查找
public WebPage getExhibitionShowList(Map map) {
// TODO Auto-generated method stub
StringBuffer count = new StringBuffer("select count(*) from "+this.getClazz().getName());
StringBuffer hql = new StringBuffer("from "+this.getClazz().getName());
StringBuffer where = new StringBuffer(" where 1=1 ");
List params = null;
int start = -1;
int limit = 0;
if(map != null){
params = new ArrayList();
if(map.get("exhibitionId") != null && !"".equals(map.get("exhibitionId"))){
where.append(" and exhibitionId = ? ");
params.add(map.get("exhibitionId"));
}
if(map.get("showName") != null && !"".equals(map.get("showName"))){
where.append(" and showName like ? ");
params.add("%"+map.get("showName")+"%");
}
if(dateStart!=null && !"".equals(dateStart)) {
hql.append(" and np.createDate >= ? ");
Date dateStartd=null;
try {
dateStartd=new SimpleDateFormat("yyyy-MM-dd").parse(dateStart);
} catch (Exception e) {
// TODO: handle exception
}
params.add(dateStartd);
}
if(dateEnd!=null && !"".equals(dateEnd)) {
hql.append(" and np.createDate < ? ");
Date dateEndd=null;
try {
dateEndd=new SimpleDateFormat("yyyy-MM-dd").parse(dateEnd);
} catch (Exception e) {
// TODO: handle exception
}
Calendar calendar=Calendar.getInstance();
calendar.clear();
calendar.setTime(dateEndd);
calendar.set(Calendar.DAY_OF_MONTH,calendar.get(Calendar.DAY_OF_MONTH)+1);//让日期加1
params.add(calendar.getTime());
}
if(map.get("start") != null){
start = (Integer) map.get("start");
}
if(map.get("limit") != null){
limit = (Integer) map.get("limit");
}
count.append(where);
hql.append(where);
if(this.getOrderMap() == null){
hql.append(" order by entryDate desc");
}
else{
Map orderMap = this.getOrderMap();
hql.append(" order by "+orderMap.get("sort")+" "+orderMap.get("dir"));
}
}
if(params != null){
return this.findByPage(count.toString(), hql.toString(), params.toArray(), start, limit);
}
else{
return this.findByPage(count.toString(), hql.toString(), null, start, limit);
}
}
daoImpl
最新推荐文章于 2024-01-05 18:02:50 发布