1. 程式人生 > >Springboot學習(十三) Mybatis-Plus在Springboot下用法詳解

Springboot學習(十三) Mybatis-Plus在Springboot下用法詳解

Mybatis-Plus在Springboot下用法詳解

1 加入依賴,以gradle工程為例

compile group: 'com.baomidou', name: 'mybatis-plus-boot-starter', version: "${mybatis_plus_boot_starter_version}"

compile group: 'org.apache.velocity', name: 'velocity-engine-core', version: "${velocity_engine_core_version}"

compile group: 'freemarker', name: 'freemarker', version: "${freemarkerVersion}"

compile group: 'org.projectlombok', name: 'lombok'



compile group: 'com.baomidou', name: 'kaptcha-spring-boot-starter', version: "${kaptchaVersion}"

compile group: 'com.alibaba', name: 'druid-spring-boot-starter', version: "${druidVersion}"

2 基本配置 資料來源使用druid連線Mysql,資料庫資訊配置檔案在application-dev.properties,Java配置在com.mybatis.plus.mybatisplususe.config包下

mybatis-plus:
  global-config:
  #主鍵型別  0:"資料庫ID自增", 1:"使用者輸入ID",2:"全域性唯一ID (數字型別唯一ID)", 3:"全域性唯一ID UUID";
id-type: 0
db-config:
  # 邏輯已刪除值(預設為 1)
  logic-delete-value: 1
  # 邏輯未刪除值(預設為 0)
  logic-not-delete-value: 0

#jackson配置
spring.jackson.serialization.indent_output: true
spring.http.converters.preferred-json-mapper: jackson
spring.jackson.date-format: yyyy-MM-dd HH:mm:ss
spring.jackson.joda-date-time-format: yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone: GMT+8

#logback.xml配置
logging.config=classpath: logback.xml


#kaptcha驗證碼配置
kaptcha:
  height: 50
  width: 200
  content:
length: 4
source: abcdefghjklmnopqrstuvwxyz23456789
space: 2
  font:
color: blue
name: Arial
size: 40
  background-color:
from: lightGray
to: white
  border:
enabled: true
color: black
thickness: 1

spring.profiles.active: dev

3 程式碼生成器

見MpGenerator類,修改其中引數,直接執行就可以生成Mapper、Service、Controller

4 各種查詢例子見UserController類