AdminHibernateImpl.java
上传用户:yunfeng252
上传日期:2022-07-23
资源大小:12403k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
Java
- package org.yufeng.dao.hibernate;
- import java.util.List;
- import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
- import org.yufeng.dao.IAdminDao;
- import org.yufeng.domains.Admin;
- import org.yufeng.utils.Tools;
- public class AdminHibernateImpl extends HibernateDaoSupport implements
- IAdminDao {
- public boolean validate(String username, String password) {
- boolean flag = false;
- String uname = username;
- String pass = Tools.md5(password);
- String sql = "From Admin where username='" + uname + "' and password='"
- + pass + "'";
- List list = this.getHibernateTemplate().find(sql);
- if (list.size() > 0) {
- flag = true;
- }
- return flag;
- }
- public List browseAdmin() {
- return this.getHibernateTemplate().find("From Admin a order by a.id");
- }
- public Admin loadAdmin(Integer id) {
- return (Admin) this.getHibernateTemplate().get(Admin.class, id);
- }
- public boolean delAdmin(Admin admin) {
- boolean flag = false;
- try {
- this.getHibernateTemplate().delete(admin);
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- public boolean addAdmin(Admin admin) {
- boolean flag = false;
- try {
- this.getHibernateTemplate().save(admin);
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- public boolean updateAdmin(Admin admin) {
- boolean flag = false;
- try {
- this.getHibernateTemplate().update(admin);
- flag = true;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return flag;
- }
- public Admin loadAdmin(String username) {
- Admin admin = new Admin();
- String sql = "From Admin where username='" + username + "'";
- List list = this.getHibernateTemplate().find(sql);
- if (list.size() == 0) {
- admin=null;
- }else{
- admin=(Admin)list.get(0);
- }
- return admin;
- }
- }