⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customerhibernatedao.java

📁 在线图书管理系统,所有框架struts2,hibernate,spring 希望有所帮助!
💻 JAVA
字号:
/**
 * 
 */
package com.ascent.dao.hibernate;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;

import com.ascent.bean.Customer;
import com.ascent.dao.ICustomerDAO;

public class CustomerHibernateDAO
    extends HibernateDaoSupport
    implements ICustomerDAO {
	
	private static final Logger LOGGER = LogManager.getLogger(CustomerHibernateDAO.class);
	
	private static final String LOAD_ALL = "from Customer cust order by cust.customerId desc";

	private static final String LOAD_BY_NAME = "from Customer cust where cust.custName = ? order by cust.customerId desc";


	/**
	 * 
	 */
	public CustomerHibernateDAO() {
		super();
	}
	
	/**
	 * 
	 * @param Customer
	 * @return Customer
	 */
	public Customer saveCustomer(Customer customer){
		try{
			this.getHibernateTemplate().save(customer);
			LOGGER.debug("保存用户信息到数据库成功!");
			return customer;
		}catch(Exception ex){
			LOGGER.error("保存用户信息到数据库失败!");
			ex.printStackTrace();
			return null;
		}
	}

	/**
	 * 
	 * @param id Integer
	 *            
	 * @return Customer
	 */
	public Customer getCustomer(Integer id){
		LOGGER.debug("根据用户ID得到用户信息!");
		return (Customer)this.getHibernateTemplate().get(Customer.class,id);
	}

	/**
	 * 
	 * @return List
	 */
	public List findCustomerAll(){
		try{
			LOGGER.debug("得到所有用户列表!");
			return this.getHibernateTemplate().find(LOAD_ALL);			
		}catch(Exception ex){
			LOGGER.error("获取所有用户列表失败!");
			return new ArrayList();
		}
	}

	/**
	 * 
	 * @param type String
	 *            
	 * @return List
	 */
	public List findCustomerByName(String name){
		try{
			LOGGER.debug("根据用户姓名得到用户信息!");
			return this.getHibernateTemplate().find(LOAD_BY_NAME,name);
		}catch(Exception ex){
			LOGGER.error("根据用户姓名获取用户信息失败!");
			ex.printStackTrace();
			return null;
		}
	}

	/**
	 * 
	 * @param Customer
	 *   
	 */
	public void removeCustomer(Customer customer){
		LOGGER.debug("从数据库中删除指定用户信息!");
		this.getHibernateTemplate().delete(customer);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -