# ssh框架怎样对数据库做修改、添加操作?[未登录] 回复 更多评论
2007-05-30 11:54 by
1.具体的Action里不会写!!
DAO接口
*****************
package com.linkingstar.bis.common.dao;
import java.util.List;
import com.linkingstar.bis.common.model.UserPO;
/**
*
* 用户数据表的DAO接口
*
*/
public interface IUserDAO {
UserPO get(String userId);
void save(UserPO userPO);
void update(UserPO userPO);
void remove(UserPO userPO);
List findAll();
List findAll2(String usercode);
List findODD(String usercode);
}
*****************
DAO
*****************
package com.linkingstar.bis.common.dao;
import java.util.ArrayList;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.linkingstar.bis.common.model.UserPO;
import com.linkingstar.bis.common.dao.IUserDAO;
/**
*
* 用户数据表的DAO实现类
*
*/
public class UserDAOImpl extends HibernateDaoSupport implements IUserDAO {
private String LOAD_BY_ALL = "from UserPO userPO";
private String LOAD_BY_ODD = "from UserPO userPO where userPO.usercode=?";
public UserDAOImpl() {
super();
}
public UserPO get(String userId) {
try{
return (UserPO) this.getHibernateTemplate().get(UserPO.class,userId);
}catch(Exception ex){
ex.printStackTrace();
return null;
}
}
public void save(UserPO userPO) {
try {
this.getHibernateTemplate().save(userPO);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void update(UserPO userPO) {
try {
this.getHibernateTemplate().update(userPO);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void remove(UserPO userPO) {
try {
this.getHibernateTemplate().delete(userPO);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public List findAll() {
try{
return this.getHibernateTemplate().find(LOAD_BY_ALL);
}catch(Exception ex){
ex.printStackTrace();
return new ArrayList();
}
}
public List findODD(String usercode) {
try{
this.getHibernateTemplate().find(LOAD_BY_ODD,usercode);
}catch(Exception ex){
ex.printStackTrace();
return new ArrayList();
}
}
public List findAll2(String usercode) {
try{
String s="改 前 查询 ";
System.out.println(s);
return this.getHibernateTemplate().find(LOAD_BY_ALL);
}catch(Exception ex){
ex.printStackTrace();
return new ArrayList();
}
}
}
********************
2.BO
BO接口
*************
package com.linkingstar.bis.common.service;
import java.util.List;
import com.linkingstar.bis.common.model.UserPO;
/**
*
* 用户数据表的BO接口
*
*/
public interface IUserService {
public UserPO get(String userId);
public void save(UserPO userPO);
public void update(UserPO userPO);
public void remove(UserPO userPO);
List findAll();
List findAll2(String usercode);
List findODD(String usercode);
}
***********
BO
***********
package com.linkingstar.bis.common.service;
import java.util.List;
import com.linkingstar.bis.common.dao.IUserDAO;
import com.linkingstar.bis.common.model.UserPO;
/**
*
* 用户数据表的BO实现类
*
*/
public class UserServiceImpl implements IUserService{
private IUserDAO userDAO;
public IUserDAO getUserDAO(){
return this.userDAO;
}
public void setUserDAO(IUserDAO userDAO){
this.userDAO = userDAO;
}
/**
*
*/
public UserServiceImpl() {
super();
}
/**
*
*/
public UserPO get(String userId) {
return this.getUserDAO().get(userId);
}
public void save(UserPO userPO) {
this.getUserDAO().save(userPO);
}
public void update(UserPO userPO) {
this.getUserDAO().update(userPO);
}
public void remove(UserPO userPO) {
this.getUserDAO().remove(userPO);
}
public List findAll() {
this.getUserDAO().findAll();
return this.getUserDAO().findAll();
}
public List findAll2(String usercode) {
this.getUserDAO().findAll2(usercode);
return this.getUserDAO().findAll2(usercode);
}
public List findODD(String usercode){
this.getUserDAO().findODD(usercode);
return this.getUserDAO().findODD(usercode);
}
}
********
# re: 请教一个hibernate组合查询的问题,谢谢! 回复 更多评论
2007-06-07 11:26 by
Hibernate对多表联合查询还不健全,现有的方法很不方便
建议你用spring的jdbcTemplate查询。