三、spring_boot整合JDBC
-
创建maven工程
-
更改工程jdk版本
<properties> <!-- java版本 --> <java.version>1.8</java.version> <!-- 编译时的编码 --> <maven.compiler.encoding>UTF-8</maven.compiler.encoding> </properties> <build> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${maven.compiler.encoding}</encoding> </configuration> </plugin> </plugins> </build>
-
引入spring boot 父类
<!-- 引入父类更好的规范各个依赖的version --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.0.RELEASE</version> </parent>
-
引入依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency>
-
添加数据源,新增application.yml
spring: datasource: url: jdbc:mysql://192.168.128.11:3306/j815?useUnicode=true&characterEncoding=utf-8 username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver
-
JdbcTemplate