Spring Boot学习第一季(DB交互)
来源:互联网 发布:初学室内设计的软件 编辑:程序博客网 时间:2024/06/05 03:17
Spring Boot学习第一季(DB交互)
Spring Boot 集成druid
druid有很多个配置选项,使用spring Boot 的配置文件可以方便的配置druid。
在application.yml配置文件中写上:
druid有很多个配置选项,使用spring Boot 的配置文件可以方便的配置druid。
在application.yml配置文件中写上:
spring: datasource: name: test url: jdbc:mysql://192.168.16.137:3306/test username: root password: # 使用druid数据源 type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver filters: stat maxActive: 20 initialSize: 1 maxWait: 60000 minIdle: 1 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: select 'x' testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true maxOpenPreparedStatements: 20
Spring Boot 集成MyBatis
Spring Boot 集成MyBatis有两种方式,一种简单的方式就是使用MyBatis官方提供的:
另外一种方式就是仍然用类似mybatis-spring
的配置方式,这种方式需要自己写一些代码,但是可以很方便的控制MyBatis的各项配置。
一、mybatis-spring-boot-starter方式
在pom.xml中添加依赖:
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.0.0</version></dependency
mybatis-spring-boot-starter
依赖树如下:在application.yml
中增加配置:
mybatis: mapperLocations: classpath:mapper/*.xml typeAliasesPackage: tk.mapper.model
除了上面常见的两项配置,还有:
- mybatis.config:mybatis-config.xml配置文件的路径
- mybatis.typeHandlersPackage:扫描typeHandlers的包
- mybatis.checkConfigLocation:检查配置文件是否存在
- mybatis.executorType:设置执行模式(
SIMPLE, REUSE, BATCH
),默认为SIMPLE
阅读全文
1 0
- Spring Boot学习第一季(DB交互)
- Spring boot学习(二)页面模板与MySQL交互
- Spring Boot学习笔记-创建第一个Spring Boot应用
- Spring Boot第一课
- 【Spring Boot】【第一波】 Spring Boot简介
- (2)Spring-boot学习 创建第一个应用程序
- SPRING-BOOT学习记录001-第一个例子
- SpringBoot学习笔记001--创建第一个spring boot应用
- Spring Boot学习之旅创建第一个工程
- (一) Spring Boot学习笔记之第一个Spring Boot程序HelloWorld
- Spring-Boot学习(2)-----Spring-Boot-web学习
- Spring Boot学习(一)
- Spring Boot学习(一)
- Spring Boot学习(一)
- spring boot 学习(一)
- Spring boot学习(1)
- Spring Boot学习(一)
- Spring boot学习(2)
- 笨方法学Python 习题 44: 继承(Inheritance) VS 合成(Composition)
- 小白笔记--------------------------leetcode 34. Search for a Range
- 1663: 字符识别?
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK
- 字符串操作总结
- Spring Boot学习第一季(DB交互)
- Servlet+JSP开发简单实例
- java.lang.ClassNotFoundException: org.apache.commons.io.output.DeferredFileOutputStr
- 远程连接MySQL出现host is not allowed to connect to this mysql server
- C#基础之匿名方法实例教程
- 云服务器 ECS弹性变配能力总览
- ZooKeeper之(四)配置与命令
- CI框架浅析(全篇)
- mybatis.xml文件中#与$符号的区别以及数学符号的处理