mybatis-plus&springboot

** 问题1:mybatis 读取不到 mapper映射文件。
如下:

** 如果引用 mybatis-plus 包

<dependency>
   <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus</artifactId>
    <version>3.1.0</version>
</dependency>

则需要配置
mybatis.mapper-locations=classpath:mapper/*.xml

** 引用 mybatis-plus-boot-starter 包

<dependency>
     <groupId>com.baomidou</groupId>
     <artifactId>mybatis-plus-boot-starter</artifactId>
     <version>3.1.0</version>
 </dependency>

则需要配置
mybatis-plus.mapper-locations=classpath:**/*Mapper.xml

另外如果mapper.xml中的表字段中有BLob等类型的字段,需要指明typeHandler="org.apache.ibatis.type.BlobTypeHandler" ,否则加载时会出问题

其他的一些配置:

#mybatis
mybatis-plus:
  mapper-locations: classpath:**/*Mapper.xml
  #实体扫描,多个package用逗号或者分号分隔
  typeAliasesPackage:  com.taikang.obs.model/entity
  global-config:
    # 数据库相关配置
    db-config:
      #主键类型  AUTO:"数据库ID自增", INPUT:"用户输入ID",ID_WORKER:"全局唯一ID (数字类型唯一ID)", UUID:"全局唯一ID UUID";
      id-type: auto
      #字段策略 IGNORED:"忽略判断",NOT_NULL:"非 NULL 判断"),NOT_EMPTY:"非空判断"
      field-strategy: not_empty
      #驼峰下划线转换
      column-underline: true
      #数据库大写下划线转换
      #capital-mode: true
      #逻辑删除配置
      logic-delete-value: 0
      logic-not-delete-value: 1
    #刷新mapper 调试神器
    refresh: true
  # 原生配置
  configuration:
    map-underscore-to-camel-case: true
    # 如果需要分页的话,需要将该值修改为false,否则的话会出现一定的问题
    cache-enabled: false

mybatis-plus主键生成策略(支持四种策略,3.2.*默认为主键生成策略为雪花算法),但是默认主键生成策略生成的id为64为长度,改长度的主键在web页面中会有问题(js中对于number类型的长度,只能支持53位),所以如果需要修改,可以重写主键生成策略(集成IkeyGenerator或者实现IdGenerator,后边这个需要的mp版本高)。
算法参考:https://www.cnblogs.com/nxzblogs/p/11848681.html

原文地址:https://www.cnblogs.com/nxzblogs/p/11973946.html