Service基本功能封装
import com.iloosen.imall.commons.util.BusinessException;import org.springframework.transaction.annotation.Transactional;import java.io.Serializable;import java.util.List;@Transactional(readOnly = true)public abstract class BaseEntityManager <E,PK extends Serializable>{//private Log log = LogFactory.getLog(getClass());protected abstract EntityDao<E,PK> getEntityDao();@Transactional(readOnly=true) public E getById(PK id) throws BusinessException {return getEntityDao().getById(id);}@Transactional(readOnly=true)public List<E> findAll() throws BusinessException {return getEntityDao().findAll();}/** 根据id检查是否插入或是更新数据 */@Transactionalpublic void saveOrUpdate(E entity) throws BusinessException {getEntityDao().saveOrUpdate(entity);}/** 插入数据 */@Transactionalpublic void save(E entity) throws BusinessException {getEntityDao().save(entity);}@Transactionalpublic void removeById(PK id) throws BusinessException {getEntityDao().deleteById(id);}@Transactionalpublic void update(E entity) throws BusinessException {getEntityDao().update(entity);}@Transactional(readOnly=true)public boolean isUnique(E entity, String[] uniquePropertyNames) {return getEntityDao().isUnique(entity, uniquePropertyNames);}@Transactionalpublic void flush() {getEntityDao().flush();}@Transactional(readOnly=true)public void refresh(BaseEntity entity) {getEntityDao().refresh(entity);}}