[[spring]]
[[MyBatis]]
SpringBoot
yml配置
配置顺序:properties > yml > yaml
数组数据子啊数据书写位置的下方使用减号作为数据开始符号,每行输写一个数据,减号与数据间空格分隔
1 2 3 4
| likes: - test - 测试 - 123
|
yml读取
采用注解形式即可,如果是数组里某个可以读取的时候加上下标即可
自动装配
1 2 3 4 5 6 7 8 9
| @Component @ConfigurationProperties(prefix = "enterprise") public class Book { private String name; private int age; private String[] subject;
set和get方法 }
|
多环境启动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| spring: profiles: active: t3
---
server: port: 80
enterprise: name: haog age: 20 subject: - test - 测试 - 用例
spring: profiles: t1
spring: config: activate: on-profile: t1 ---
server: port: 81 spring: profiles: t2 ---
server: port: 82 spring: profiles: t3
|
也可以在properties中选择环境
1
| spring.profiles.active=t3
|
整合mybatis
1 2 3 4 5
| @Mapper public interface UserDao { @Select("SELECT * from bookta where title = #{title}") public User getTitle(String title); }
|
1 2 3 4 5 6 7 8
| spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://localhost:3306/bookta?serverTimezone=UTC username: root password: csh20011103
type: com.alibaba.druid.pool.DruidDataSource
|
druid数据源:
1 2 3 4 5
| <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.16</version> </dependency>
|