Spring boot 和 mybatis-plus基础整合

环境

  • springboot版本 :1.5.15.RELEASE
  • Mybatis-plus版本:2.2.0

整合步骤

  1. POM.xml(部分)
<!-- Mybatis Plus -->
<dependency>
  <groupId>com.baomidou</groupId>
  <artifactId>mybatis-plus-boot-starter</artifactId>
  <version>2.2.0</version>
</dependency>
<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.15.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>
  1. 编写application.yml配置文件
    注意,具体配置参考:Mybatis-plus文档
    application.yml部分代码:
mybatis-plus:
  mapper-locations: classpath:/mapper/*Mapper.xml
  typeAliasesPackage: com.spz.pi.web.platform.entity
  global-config:
    id-type: 2
    field-strategy: 0
    db-column-underline: true
    refresh-mapper: true #是否动态刷新mapper,生产环境不建议使用
  configuration:
    map-underscore-to-camel-case: true
    cache-enabled: true
  check-config-location: true
  1. 编写Java config类

此类是用于配置mapper类路径,暂时不清楚如何在application中配置mapper类路径。
如果全部配置都在Java config中编写,则会有一个问题:配置mapper的xml文件路径时,Java config方式只能一个文件一个文件的路径写,无法直接写*.xml导入多个文件。

  • MybatisPlusConfig.java*代码:
package com.spz.pi.web.platform.config;

import com.baomidou.mybatisplus.entity.GlobalConfiguration;
import com.baomidou.mybatisplus.spring.MybatisSqlSessionFactoryBean;
import com.baomidou.mybatisplus.spring.boot.starter.MybatisPlusAutoConfiguration;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableTransactionManagement
@Configuration
@MapperScan("com.spz.pi.web.platform.mapper*")
public class MybatisPlusConfig {
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值