失效链接处理 |
Spring实战(第6版)英文原版 PDF 下载
转载自:
http://java.python222.com/article/1054
用户下载说明:
电子版仅供预览,下载后24小时内务必删除,支持正版,喜欢的请购买正版书籍:
https://product.dangdang.com/11456511540.html
相关截图: ![]() 资料内容:
3.1.2 Working with JdbcTemplate
Before you can start using JdbcTemplate, you need to add it to your project classpath.
You can do this easily by adding Spring Boot’s JDBC starter dependency to the build
as follows:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
You’re also going to need a database where your data will be stored. For development
purposes, an embedded database will be just fine. I favor the H2 embedded database,
so I’ve added the following dependency to the build:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
By default, the database name is randomly generated. But that makes it hard to deter
mine the database URL if, for some reason, you need to connect to the database using
the H2 console (which Spring Boot DevTools enables at http:/ /localhost:8080/h2-
console). So, it’s a good idea to pin down the database name by setting a couple of
properties in application.properties, as shown next:
spring.datasource.generate-unique-name=false
spring.datasource.name=tacocloud
Or, if you prefer, rename application.properties to application.yml and add the prop
erties in YAML format like so:
spring:
datasource:
generate-unique-name: false
name: tacocloud
The choice between properties file format and YAML format is up to you. Spring Boot
is happy to work with either. Given the structure and increased readability of YAML,
we’ll use YAML for configuration properties throughout the rest of the book.
|