java ssh de 项目一般都是三层实现的,需要根据这里给你一个模板代码,用hibernate一般一HQL足够用,复杂的多表查询需要Sql的话用回调,
这个是例子
@Override
public List
// TODO Auto-generated method stub
return (List
new HibernateCallback() {
public Object doInHibernate(Session session)
throws HibernateException {
try {
//Query q=session.createQuery(hql);
Criteria cri= session.createCriteria(Lizi.class);
System.out.println(hql);
List q= cri.add(Restrictions.sqlRestriction(hql)).list();
return q;
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
throw e;
}
}
}
);
}
---下面是一般的模板
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
public class GL_JBBDAOImpl extends HibernateDaoSupport implements GL_JBBDAO {
private static final Log log = LogFactory.getLog(GL_JBBDAOImpl.class);
public void save(GL_JBB transientInstance) {
log.debug("saving GL_JBB instance");
try {
getHibernateTemplate().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(GL_JBB persistentInstance) {
log.debug("deleting GL_JBB instance");
try {
getHibernateTemplate().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public GL_JBB findById(java.lang.String id) {
log.debug("getting GL_JBB instance with id: " + id);
try {
GL_JBB instance = (GL_JBB) getHibernateTemplate().get(
"com.zljy.basisset.entity.GL_JBB", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding GL_JBB instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from GL_JBB as model where model."
+ propertyName + "= ?";
return getHibernateTemplate().find(queryString, value);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public void attachDirty(GL_JBB instance) {
log.debug("attaching dirty GL_JBB instance");
try {
getHibernateTemplate().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public static GL_JBBDAOImpl getFromApplicationContext(ApplicationContext ctx) {
return (GL_JBBDAOImpl) ctx.getBean("GL_JBBDAO");
}
如果使用ssh的话就简单多啦~~直接使用hibernate提供的方法对数据库进行增删改查
让dao层继承HibernateDaoSupport,然后可以用getHibernateTemplate().delete();删
getHibernateTemplate().load();查
getHibernateTemplate().save();增
getHibernateTemplate().updata();改
对应的应该有
TCustContact这个实体类
TCustContactDao这个类,这个类extends HibernateDaoSupport
然后在TCustContactDao里就可以得到session执行hql了
public List
return getSession().createQuery(“from TCustContact”).list();
}
要看你的SSH框架怎么搭的,还有你的VO怎么建的,如果VO是用工具反转,并且会用HibernateDaoSupport的话,这个就很简单了,直接用继承HIbernateDaoSupport,调用父类的getHibernateTemplate()的增删改查方法就可以了,查询用Hibernate的HQL就可以了
可以依靠Baiduhi告诉我们
有机会能够处理你所遇到的工作
具体的要求也能够告诉我们
ES:\\810FD8D7B65CE4C8727227D6015CFBD3