Interface Mapper<T,​I extends Serializable>

  • Type Parameters:
    T - 实体类类型
    I - 主键类型
    All Superinterfaces:
    BaseMapper<T,​I>, CursorMapper<T,​Example<T>>, io.mybatis.provider.EntityInfoMapper<T>, EntityMapper<T,​I>, ExampleMapper<T,​Example<T>>

    public interface Mapper<T,​I extends Serializable>
    extends BaseMapper<T,​I>
    自定义 Mapper 示例,这个 Mapper 基于主键自增重写了 insert 方法,主要用作示例

    当你使用 Oracle 或其他数据库时,insert 重写时也可以使用 @SelectKey 注解对主键进行定制

    Author:
    liuzh
    • Method Detail

      • insert

        @Lang(io.mybatis.provider.Caching.class)
        @Options(useGeneratedKeys=true,
                 keyProperty="id")
        @InsertProvider(type=EntityProvider.class,
                        method="insert")
        int insert​(T entity)
        保存实体,默认主键自增,并且名称为 id

        这个方法是个示例,你可以在自己的接口中使用相同的方式覆盖父接口中的配置

        Specified by:
        insert in interface EntityMapper<T,​I extends Serializable>
        Parameters:
        entity - 实体类
        Returns:
        1成功,0失败
      • insertSelective

        @Lang(io.mybatis.provider.Caching.class)
        @Options(useGeneratedKeys=true,
                 keyProperty="id")
        @InsertProvider(type=EntityProvider.class,
                        method="insertSelective")
        int insertSelective​(T entity)
        保存实体中不为空的字段,默认主键自增,并且名称为 id

        这个方法是个示例,你可以在自己的接口中使用相同的方式覆盖父接口中的配置

        Specified by:
        insertSelective in interface EntityMapper<T,​I extends Serializable>
        Parameters:
        entity - 实体类
        Returns:
        1成功,0失败