customerserviceimpl.java

来自「一个J2EE 做的 网上图书销售管理系统」· Java 代码 · 共 76 行

JAVA
76
字号
package com.briup.service.imp;

import com.briup.bean.RegisterForm;
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.FcustomerDao);
	
	public RegisterForm login(String name, String password)
			throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			RegisterForm 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(RegisterForm customer) throws CustomerServiceException {
		// TODO Auto-generated method stub
		HibernateTransaction ht = new HibernateTransaction();
		try {
			ht.beginTransaction();
			System.out.println(customer.getName()+"&&&&");
			RegisterForm 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(RegisterForm 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 + =
减小字号Ctrl + -
显示快捷键?