注解:实现事务配置

1.配置事务作用策略不再在applicationContext.xml配置文件中设置,而是在EmpBizImpl类中通过注解的方式实现(切面、切入点的配置不再需要)


		
			
		
		
		
	
		
		

2.EmpBizImpl类

//数据库查询:@Transactional(readOnly=true)
//数据库update:@Transactional(propagation=Propagation.REQUIRED,rollbackFor={SQLException.class})
package biz.impl;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import biz.EmpBiz;
import dao.DeptDao;
import dao.EmpDao;
import entity.Emp;

@Service("empBiz")
public class EmpBizImpl implements EmpBiz {
	@Autowired
	@Qualifier("edi")
	private EmpDao edi;
	private DeptDao deptDao;

	public EmpBizImpl() {
		super();
	}

	public EmpDao getEdi() {
		return edi;
	}

	public void setEdi(EmpDao edi, DeptDao deptDao) {
		this.edi = edi;
		this.deptDao = deptDao;
	}

	public EmpBizImpl(EmpDao edi) {
		super();
		this.edi = edi;
	}

	@Override
	@Transactional(readOnly=true)
	public List findAllEmp() {

		return edi.findAllEmp();
	}

	@Override
	@Transactional(readOnly=true)
	public List findEmpByCondition(Emp e) {
		// TODO Auto-generated method stub
		return edi.findEmpByCondition(e);
	}

	@Override	
	@Transactional(readOnly=true)
	public List findEmpByNameParam(Emp e) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional(readOnly=true)
	public List findEmpByExemple(Emp e) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional(readOnly=true)
	public Emp findEmpById(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor={SQLException.class})
	public int addEmp(Emp e) {

		return edi.addEmp(e);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor={SQLException.class})
	public void modifyEmp(Emp e) {
		edi.modify(e);

	}

	@Override
	@Transactional(readOnly=true)
	public List findEmpbyPage(int pageNo, int pageSize) {
		// TODO Auto-generated method stub
		return edi.findEmpByPage(pageNo, pageSize);
	}

	@Override
	@Transactional(propagation=Propagation.REQUIRED,rollbackFor={SQLException.class})
	public void updateBatchEmpSal(double sal) {
		edi.updateBatchEmpSal(sal);

	}
}

注解:实现事务配置_第1张图片

你可能感兴趣的:(SSH)