/**
* @ClassName: GenericDao
* @Description: 全部自定義Dao的頂級接口, 封裝經常使用的增刪查改操做
* Entity : 表明數據庫中的表 映射的Java對象類型
* PK :表明對象的主鍵類型
* Page:分頁對象
* @author: yaozhenhua
* @date: 2019/3/20 11:08
*/
public interface GenericDao<Entity, PK, Page> {
/**
* 插入對象
*
* @param entity
* @author: yaozhenhua 2019/3/20 11:14
*/
int insertSelective(Entity entity);
/**
*更新對象
*
* @param entity
* @author: yaozhenhua 2019/3/20 11:16
*/
int updateSelectiveByPrimaryKey(Entity entity);
/**
*經過主鍵刪除對象
*
* @param id
* @author: yaozhenhua 2019/3/20 11:18
*/
int deleteByPrimaryKey(@Param(value = "id") PK id);
/**
*經過主鍵查詢對象
*
* @param id
* @author: yaozhenhua 2019/3/20 11:20
*/
Entity selectByPrimaryKey(@Param(value = "id") PK id);
/**
*查詢列表
*
* @param
* @author: yaozhenhua 2019/3/20 11:26
*/
List<Entity> listSelective();
/**
*分頁查詢列表
*
* @param page
* @author: yaozhenhua 2019/3/20 11:26
*/
List<Entity> listSelectiveByPage(Page page);
/**
*查詢個數
*
* @param
* @author: yaozhenhua 2019/3/20 11:28
*/
int countSelective();
}
/** * @ClassName: GenericService * @Description: 全部自定義Service的頂級接口, 封裝經常使用的增刪查改操做 * @author: yaozhenhua * @date: 2019/3/20 11:29 */public abstract class GenericService<Entity, PK, Page> { public abstract GenericDao<Entity, PK, Page> getDao(); /** *插入對象 * * @param entity * @author: yaozhenhua 2019/3/20 12:07 */ public int insert(Entity entity){ return getDao().insertSelective(entity); } /** *更新對象 * * @param entity * @author: yaozhenhua 2019/3/20 12:09 */ public int update(Entity entity){ return getDao().updateSelectiveByPrimaryKey(entity); } /** *刪除對象 * * @param id * @author: yaozhenhua 2019/3/20 12:10 */ public int delete(PK id){ return getDao().deleteByPrimaryKey(id); } /** *經過主鍵, 查詢對象 * * @param id * @author: yaozhenhua 2019/3/20 12:11 */ public Entity selectById(PK id){ return getDao().selectByPrimaryKey(id); } /** *查詢列表 * * @param * @author: yaozhenhua 2019/3/20 12:13 */ public List<Entity> listSelective(){ return getDao().listSelective(); } /** *查詢列表並分頁 * * @param page * @author: yaozhenhua 2019/3/20 12:14 */ public List<Entity> listSelectiveByPage(Page page){ return getDao().listSelectiveByPage(page); } /** *查詢個數 * * @param * @author: yaozhenhua 2019/3/20 12:15 */ public int countSelective(){ return getDao().countSelective(); }}