📄 managemyinfodao.java
字号:
package com.shunshi.ssh.dao;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.shunshi.ssh.entity.AllInfo;
import com.shunshi.ssh.entity.Messe;
public class ManageMyInfoDao extends HibernateDaoSupport implements IManageMyInfoDao {
public void save(AllInfo transientInstance) {
try {
getHibernateTemplate().saveOrUpdate(transientInstance);
} catch (RuntimeException re) {
throw re;
}
}
public void delete(AllInfo persistentInstance) {
try {
getHibernateTemplate().delete(persistentInstance);
} catch (RuntimeException re) {
throw re;
}
}
public AllInfo findById(Long id) {
String hql="from AllInfo info where info.id=:id";
return (AllInfo)getHibernateTemplate().findByNamedParam(hql,"id",id).get(0);
}
public void update(AllInfo instance) {
try {
getHibernateTemplate().update(instance);
} catch (RuntimeException re) {
throw re;
}
}
public List findByUserId(final long id,final int startRow,final int maxRowNum) {
List infos=(List)getHibernateTemplate().execute(new HibernateCallback(){
public Object doInHibernate(Session session)
throws HibernateException, SQLException {
Query query=session.createQuery("select infos from AllInfo infos where infos.userId=:id");
query.setLong("id",id);
query.setMaxResults(maxRowNum);
query.setFirstResult(startRow);
List infos=new ArrayList();
List allInfo=query.list();
for(int i=0;i<allInfo.size();i++){
AllInfo info=(AllInfo)allInfo.get(i);
Map map=new HashMap();
map.put("name",info.getName());
map.put("type", info.getType());
map.put("userId", info.getUserId());
map.put("classType", info.getClassType());
map.put("bid",info.getBid());
map.put("id", info.getId());
infos.add(map);
}
return infos;
}
});
return infos;
}
public Long getTotalRowsByUserId(Long uid) {
try {
String queryString = "select count(*) from AllInfo info where info.userId=?";
return (Long)getHibernateTemplate().find(queryString,uid).get(0);
} catch (RuntimeException re) {
throw re;
}
}
public void deleteObject(Object object) {
try {
getHibernateTemplate().delete(object);
} catch (RuntimeException re) {
throw re;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -