SpringBoot整合mybatis的基本配置

Springboot整合mybatis

添加依赖pom.xml

<!-- mybatis 集成 -->
 <dependency>
 	<groupId>org.mybatis.spring.boot</groupId>
 	<artifactId>mybatis-spring-boot-starter</artifactId>
 	<version>2.1.1</version>
 </dependency>
 <!-- mysql 驱动 -->
 <dependency>
 	<groupId>mysql</groupId>
 	<artifactId>mysql-connector-java</artifactId>
 </dependency>
 <!-- c3p0 数据源 -->
 <dependency>
 	<groupId>com.mchange</groupId>
 	<artifactId>c3p0</artifactId>
 	<version>0.9.5.5</version>
 </dependency>

添加整合配置application.yml

注意空格与及缩进这些都会影响数据的读取

## 数据源配置
spring:
  datasource: # 数据库的数据配置
    type: com.mchange.v2.c3p0.ComboPooledDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    # url不用换行,由于数据太长了这里换行了
    url: jdbc:mysql://localhost:3306/ppl?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false
    username: root
    password: 123456
## mybatis 配置
mybatis:
  mapper-locations: classpath:/mappers/*.xml # 扫描mybatis的实现dao接口*.xml文件
  type-aliases-package: com.ppl.springboot.entity #实体类取别名
  configuration:
  ## 下划线转驼峰配置
    map-underscore-to-camel-case: true
## 显示dao 执⾏sql语句
logging:
  level:
   com.ppl.springboot.dao: debug # 改成你的dao接口文件所在包路径可以打印出sql语句

项目启动入口

需要在主程序中添加扫描dao层实现接口

@SpringBootApplication
@MapperScan("com.ppl.springboot.dao")
public class Starter{
    public static void main(String[] args) {
        SpringApplication.run(Starter.class);
    }
}
  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值