Java资源分享网 - 专业的Java学习网站 学Java,上Java资源分享网
Spring实战(第6版)英文原版 PDF 下载
匿名网友发布于:2024-03-13 11:22:16
(侵权举报)
(假如点击没反应,多刷新两次就OK!)

Spring实战(第6版)英文原版 PDF 下载 图1

 

 

 

资料内容:

 

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.