SpringBoot整合Mybatis访问数据库和阿里巴巴数据源
1、pom文件加入依赖
<!--加入mybatis依赖--> <!--引入satrter--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.2</version> </dependency> <!--mysql的jdbc驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!--引入第三方数据源--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.8</version> </dependency>
2、application.properties配置文件
#===============================数据库相关====================================== #数据库驱动(可以自动识别) #spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/databaseName?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC spring.datasource.username=username spring.datasource.password=password #修改数据源(com.zaxxer.hikari.HikariDataSource) spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
useUnicode=true&characterEncoding=UTF-8:防止中文乱码serverTimezone=UTC:设置时间,UTC是世界标准时间未设置时间报数据库连接错误:The server time zone value ‘?й???????‘ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration
3、添加mapper扫描
@MapperScan("mapper包路径")
4、开发mapper
相关推荐
xiuyangsong 2020-11-16
Nishinoshou 2020-11-09
jimgreatly 2020-09-01
dongxurr 2020-08-18
Dullonjiang 2020-08-15
Dullonjiang 2020-08-11
Dullonjiang 2020-08-09
dongxurr 2020-08-08
yunzhonmghe 2020-08-07
jimgreatly 2020-08-03
Dullonjiang 2020-07-30
jimgreatly 2020-07-27
liqiancao 2020-07-26
xiuyangsong 2020-07-26
dongxurr 2020-07-26
mcvsyy 2020-07-26
helloxusir 2020-07-25
牧场SZShepherd 2020-07-20