標籤:war com nsa pac blog 資料 find abs extends
| ylbtech-Java-java-com-util-common-service:CrudService.java |
1、
package com.shineyoo.manager.util.common.service;import java.util.Collection;import java.util.List;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.transaction.annotation.Transactional;import com.shineyoo.manager.util.common.persistence.CrudDao;import com.shineyoo.manager.util.common.persistence.DataEntity;import com.shineyoo.manager.util.common.persistence.Page;/** * Service基類 * @author * @version 2014-05-16 */@Transactional(readOnly = true)public abstract class CrudService<D extends CrudDao<T>, T extends DataEntity<T>> extends BaseService { /** * 持久層對象 */ @Autowired protected D dao; /** * 擷取單條資料 * @param id * @return */ public T get(String id) { return dao.get(id); } /** * 擷取單條資料 * @param entity * @return */ public T get(T entity) { return dao.get(entity); } /** * 擷取單條資料 * @param entity * @return */ public T getNew(T entity) { return dao.getNew(entity); } /** * 查詢列表資料 * @param entity * @return */ public List<T> findList(T entity) { return dao.findList(entity); } /** * 查詢列表資料 * @param entity * @return */ public List<T> findAllList(T entity) { return dao.findAllList(entity); } /** * 查詢分頁資料 * @param page 分頁對象 * @param entity * @return */ public Page<T> findPage(Page<T> page, T entity) { entity.setPage(page); page.setList(dao.findList(entity)); return page; } /** * 查詢分頁資料 * @param page 分頁對象 * @param entity * @return */ public Page<T> findPageOver(Page<T> page, T entity) { entity.setPage(page); page.setList(dao.findListOver(entity)); return page; } /** * 查詢沒有通過審核的分頁資料 * @param page 分頁對象 * @param entity * @return */ public Page<T> findPageByStatus(Page<T> page, T entity) { entity.setPage(page); page.setList(dao.findListByStatus(entity)); return page; } /** * 儲存資料(插入或更新) * @param entity */ @Transactional(readOnly = false) public void save(T entity) { if (entity.getIsNewRecord()){ entity.preInsert(); entity.setDelFlag("0"); dao.insert(entity); }else{ entity.preUpdate(); dao.update(entity); } } /** * 刪除資料 * @param entity */ @Transactional(readOnly = false) public void delete(T entity) { dao.delete(entity); } /** * 邏輯刪除資料 * @param entity */ @Transactional(readOnly = false) public void deleteByLogic(T entity) { dao.deleteByLogic(entity); } /** * 刪除全部資料 * @param entitys */ @Transactional(readOnly = false) public void deleteAll(Collection<T> entitys) { for (T entity : entitys) { dao.delete(entity); } } /** * 擷取單條資料 * @param propertyName * @return */ public T findUniqueByProperty(String propertyName, Object value){ return dao.findUniqueByProperty(propertyName, value); }}2、
|
ylbtech 出處:http://ylbtech.cnblogs.com/ 本文著作權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文串連,否則保留追究法律責任的權利。 |
Java-java-com-util-common-service:CrudService.java