本文共 2216 字,大约阅读时间需要 7 分钟。
#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等mybatis-plus: mapper-locations: classpath:/mapper/*Mapper.xml global-config: #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; id-type: 1 # Sequence序列接口实现类配置 key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
@Configuration@MapperScan("user.mapper")public class MybatisPlusConfigurer {}
@TableName("T_USER")@KeySequence(value = "SEQ_USER", clazz = Integer.class)public class User extends Model{ private static final long serialVersionUID = 1L; /** * 用户ID */ @TableId(value = "USER_ID", type = IdType.INPUT) private Integer userId;}
#mybaits-plus配置,修改主键类型,mapper.xml、type 别名等mybatis-plus: mapper-locations: classpath:/mapper/*Mapper.xml global-config: #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID"; id-type: 1 # Sequence序列接口实现类配置 key-generator: com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator
Mybatis Plus 3 已废除此配置,但是配置该属性也不会出错。建议不配置。源代码说明如下:
@Configuration@MapperScan("user.mapper")public class MybatisPlusConfigurer { /** * Sequence主键自增 * * @return 返回oracle自增类 * @author zhenggc * @date 2019/1/2 */ @Bean public OracleKeyGenerator oracleKeyGenerator(){ return new OracleKeyGenerator(); }}
@TableName("T_USER")@KeySequence(value = "SEQ_USER", clazz = Integer.class)public class User extends Model{ private static final long serialVersionUID = 1L; /** * 用户ID */ @TableId(value = "USER_ID", type = IdType.INPUT) private Integer userId;}
Mybatis Plus 2 :
key-generator: com.baomidou.mybatisplus.incrementer.OracleKeyGenerator
Mybatis Plus 3 :
key-generator: com.baomidou.mybatisplus.extension.incrementer.OracleKeyGenerator
并且 Mybatis Plus 3 无需配置该属性。
Mybatis Plus 2 不需要配置 OracleKeyGenerator 的 bean ,而 Mybatis Plus 3 需要配置 OracleKeyGenerator。
转载地址:http://bxyqa.baihongyu.com/