MISBoot低代码开发平台

Mapper持久层

一、 概述

1.作用

数据访问层接口

2.位置

src\main\java\cn\ewsd\xxxx\mapper\YyyyMapper.java

3.命名方式

首字母大写,驼峰命名,如:YyyyMapper.java

4.继承

继承tk.mybatis.mapper.common.Mapper类

5.通用方法
    查询数据方法

    方法:List select(T record);
    说明:根据实体中的属性值进行查询,查询条件使用等号

    方法:T selectByPrimaryKey(Object key);
    说明:根据主键字段进行查询,方法参数必须包含完整的主键属性,查询条件使用等号

    方法:List selectAll();
    说明:查询全部结果,select(null)方法能达到同样的效果

    方法:T selectOne(T record);
    说明:根据实体中的属性进行查询,只能有一个返回值,有多个结果是抛出异常,查询条件使用等号

    方法:int selectCount(T record);
    说明:根据实体中的属性查询总数,查询条件使用等号
                
    插入数据方法

    方法:int insert(T record);
    说明:保存一个实体,null的属性也会保存,不会使用数据库默认值

    方法:int insertSelective(T record);
    说明:保存一个实体,null的属性不会保存,会使用数据库默认值
                
    更新数据方法

    方法:int updateByPrimaryKey(T record);
    说明:根据主键更新实体全部字段,null值会被更新

    方法:int updateByPrimaryKeySelective(T record);
    说明:根据主键更新属性不为null的值
                
    删除数据方法

    方法:int delete(T record);
    说明:根据实体属性作为条件进行删除,查询条件使用等号

    方法:int deleteByPrimaryKey(Object key);
    说明:根据主键字段进行删除,方法参数必须包含完整的主键属性
                
    Example方法

    方法:List selectByExample(Object example);
    说明:根据Example条件进行查询
    重点:这个查询支持通过Example类指定查询列,通过selectProperties方法指定查询列

    方法:int selectCountByExample(Object example);
    说明:根据Example条件进行查询总数

    方法:int updateByExample(@Param("record") T record, @Param("example") Object example);
    说明:根据Example条件更新实体record包含的全部属性,null值会被更新

    方法:int updateByExampleSelective(@Param("record") T record, @Param("example") Object example);
    说明:根据Example条件更新实体record包含的不是null的属性值

    方法:int deleteByExample(Object example);
    说明:根据Example条件删除数据
                
6.自定义方法
自定义方法
    List getPageSet(@Param("filterSort") String filterSort);  //获得分页集数据

    HashMap getDetailByUuid(String uuid);  //通过uuid获得详细数据

    Integer save(SampleDatagrid sampleDatagrid);  //保存数据

    Integer update(SampleDatagrid sampleDatagrid);  //更新数据

    Integer deleteByUuid(String uuid);  //通过uuid删除数据

    List> getList();  //获得列表数据

    List> getListByLike(String userNameId);  //通过包含用户名获得列表数据

    List getListBySearializeParam(String userNameId, String password); //通过#{0},#{1}参数形式获得列表数据

    List getListByEntityParam(SampleDatagrid sampleDatagrid); //通过实体参数名获得列表数据
                

二、示例代码

用户Mapper
    public interface SysUserBaseMapper extends tk.mybatis.mapper.common.Mapper {

        List getPageSet(@Param("filterSort") String filterSort,@Param("userNameId")String userNameId);     //获取分页集

        int executeSave(SysUserBase var1);     //保存数据

        int executeSave(Map var1);     //保存map集合数据

        int executeUpdate(SysUserBase var1);     //修改数据

        int executeUpdate(Map var1);     //修改数据

        int executeDelete(Object var1);     //删除数据

        int executeDelete(Map var1);     //删除数据

        int executeDeleteBatch(Object[] var1);     //删除数据

        SysUserBase queryObject(Object var1);    //查询数据

        List queryList(Map var1);     //查询数据

        List queryList(Object var1);     //查询数据

        int queryTotal(Map var1);     //查询统计数据

    }
                
文档更新时间: 2019-11-20 12:40 作者:佐佑时代