UserDaoImpl

package com.huaweisymantec.rmc.core.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.huaweisymantec.rmc.core.dao.UserDao;
import com.huaweisymantec.rmc.core.domain.User;
import com.huaweisymantec.rmc.core.utils.GenericDao;

@Component("ud")
public class UserDaoImpl implements UserDao {

private GenericDao gd;
private HibernateTemplate ht;

// 检查用户是否存在
public boolean checkUserExistByName(String username) {
List<User> users = ht.find("from User u where u.username='" + username+ "'");

if (users != null && users.size() > 0) {
return true;
}

else {
return false;
}

}

public GenericDao getGd() {
return gd;
}

public HibernateTemplate getHt() {
return ht;
}

// 增加用户
public void saveUser(User u) {

gd.add(u);
}

@Resource
public void setGd(GenericDao gd) {
this.gd = gd;
}

@Resource
public void setHt(HibernateTemplate ht) {
this.ht = ht;
}


//更改用户
public void updateUser(User user) {
//gd.update(user);
ht.update(user);

}
//根据用户名得到用户

public User getUserByName(String username) {
List<User> users = ht.find("from User u where u.username='" + username+ "'");
return users.get(0);

}
//删除用户
public void delUser(User u) {

ht.delete(u);

}


}

你可能感兴趣的:(DAO,orm)