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

📄 customerserviceimpl.java

📁 非常经典的ssh整合实例
💻 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;
import com.briup.common.transaction.Transaction;

public class CustomerServiceImpl implements ICustomerService {
		
	public Customer login(String name, String password)
			throws CustomerServiceException {
		    Customer customer=null;
			Transaction tran=new HibernateTransaction();
			ICustomerDao customerDao=(ICustomerDao) BeanFactory.getBean(BeanFactory.CUSTOMERDAO);
			try{
				tran.beginTransaction();
				customer=customerDao.findCustomerByName(name);
				if(customer!=null){
						if(!customer.getPassword().equals(password)){
							customer=null;
						}
				}			
			   //提交事务
			   tran.commit();
		  }catch(Exception e){
			   e.printStackTrace();
			  //回滚事务
			   tran.rollback();
		}
		 return customer;		
	}

	public void register(Customer customer) throws CustomerServiceException {
		Transaction tran=new HibernateTransaction();
		ICustomerDao customerDao=(ICustomerDao) BeanFactory.getBean(BeanFactory.CUSTOMERDAO);
		try{
			tran.beginTransaction();
			Customer c=customerDao.findCustomerByName(customer.getName());
			if(c!=null)
				throw new CustomerServiceException("用户名已经存在!");
			customerDao.saveOrupdateCustomer(customer);
			tran.commit();
		}catch(Exception e){
			e.printStackTrace();
			tran.rollback();
			if(e instanceof CustomerServiceException){
				throw (CustomerServiceException)e;
			}else{
				throw new CustomerServiceException("注册用户失败!");
			}
		}
	}

	public void update(Customer customer) throws CustomerServiceException {
		Transaction tran=new HibernateTransaction();
		ICustomerDao customerDao=(ICustomerDao) BeanFactory.getBean(BeanFactory.CUSTOMERDAO);
		try{
			tran.beginTransaction();			
			customerDao.saveOrupdateCustomer(customer);
			tran.commit();
		}catch(Exception e){
			e.printStackTrace();
			tran.rollback();	
			if(e instanceof CustomerServiceException){
				throw (CustomerServiceException)e;
			}else{
				throw new CustomerServiceException("修改用户信息失败");
			}
			
			}
		}
	}


⌨️ 快捷键说明

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