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

📄 customerserviceimpl.java

📁 网上售书电子商务网站
💻 JAVA
字号:
package com.briup.service.impl;

import com.briup.bean.Customer;
import com.briup.common.BeanFactory;
import com.briup.dao.ICustomerDao;
import com.briup.service.ICustomerService;
import com.briup.common.exception.CustomerServiceException;
import com.briup.common.transaction.HibernateTransaction;

public class CustomerServiceImpl implements ICustomerService {
	private ICustomerDao customerDao = 
				(ICustomerDao)BeanFactory.getBean(BeanFactory.CUSTOMERDAO);
	
	public Customer login(String name, String password)
			throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			Customer customer = customerDao.findCustomerByName(name);
			if(customer == null){
				throw new Exception("用户名不正确");
			}else if(!customer.getPassword().equals(password)){
				throw new Exception("密码不正确");
			}
			ht.commit();
			return customer;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ht.rollback();
			throw new CustomerServiceException(e.getMessage(),e);
		}
		
	}

	public void register(Customer customer) throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			Customer c = customerDao.findCustomerByName(customer.getName());
			if(c != null)
				throw new Exception("该用户名已经存在");
			customerDao.saveOrupdateCustomer(customer);
			ht.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ht.rollback();
			throw new CustomerServiceException(e.getMessage(),e);
		}
	}

	public void update(Customer customer) throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			customerDao.saveOrupdateCustomer(customer);
			ht.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			ht.rollback();
			throw new CustomerServiceException(e.getMessage(),e);
		}
	}

}

⌨️ 快捷键说明

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