customerdaoimpl.java

来自「该系统的主要功能是」· Java 代码 · 共 42 行

JAVA
42
字号
package com.laoniu.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.laoniu.bean.Customer;


import com.laoniu.common.HibernateSessionFactory;

import com.laoniu.dao.ICustomerDao;


public class CustomerDaoImpl implements ICustomerDao {
	
	public Customer findCustomerByName(String name) throws Exception {
		Session session=HibernateSessionFactory.getSession();
		Query query=session.createQuery("from Customer where name=?");
		query.setString(0, name);
		List list = query.list();
		if(list.size()>0)
			return (Customer)list.get(0);
		return null;
	}

	public void saveOrupdateCustomer(Customer customer) throws Exception {
		Session session=HibernateSessionFactory.getSession();
		session.saveOrUpdate(customer);  
	}
	public Customer findCustomerById(Long id) throws Exception 
	{
		Session session=HibernateSessionFactory.getSession();
		String hql="from Customer where id=?";
		Query query=session.createQuery(hql);
		query.setLong(0,id);
		return (Customer)query.list().get(0);
	}
}

⌨️ 快捷键说明

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