zoukankan      html  css  js  c++  java
  • BaseMapper和继承

    在三层结构中,controller层,service层,dao层,其中dao层负责和数据库交互,dao层对应着mapper.xml,而通过代码生成的dao层,仔细观察会发现,方法都是差不多的,具有共性,那就把这些相同的方法提取出来形成BaseMapper,之后的dao层只需要继承它即可,这样就会减少大量的代码冗余了。

    BaseMapper接口如下:

    public interface BaseMapper<T, S> {
        int countByExample(S example);
    
        int deleteByExample(S example);
    
        int deleteByPrimaryKey(Integer pid);
    
        int insert(T record);
    
        int insertSelective(T record);
    
        List<T> selectByExample(S example);
    
        T selectByPrimaryKey(Integer pid);
    
        int updateByExampleSelective(@Param("record") T record, @Param("example") S example);
    
        int updateByExample(@Param("record") T record, @Param("example") S example);
    
        int updateByPrimaryKeySelective(T record);
    
        int updateByPrimaryKey(T record);
    
        int save(List<T> req);
    
        int delete(List<T> req);
    
        int update(T req);
    }
    

    在dao层中继承该BaseMapper,如下:

    public interface PcNLatBluepayNotifyMapper<T, S> extends BaseMapper<T, S> {}
    
  • 相关阅读:
    课程总结
    课程总结
    十四周实验报告&&课程总结
    记事本代码
    第十三周课程总结
    第十二周课程报告
    PTA实验 链表拼接 (20point(s))
    课程总结
    第十四周课程总结&实验报告
    第十三周课程总结
  • 原文地址:https://www.cnblogs.com/jasonboren/p/14338605.html
Copyright © 2011-2022 走看看