之前写过spring data jpa 入门,Spring Boot 使用Jpa,很简单,也很方便,这里简单介绍一下。
spring data jpa 入门中已经介绍过jpa怎么玩,直接建立对应的类和包。
。
Spring Boot默认提供的jar是spring-boot-starter-data-jpa
,它提供了以下关键依赖。
在你的pom文件中直接配置就好。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Spring Boot 默认提供tomcat-jdbc
连接池,也可以通过spring.datasource.type
属性配置其他的连接池。这里使用默认的。application.properties
配置如下:
server.port=9091
# mysql
spring.datasource.url=jdbc:mysql://localhost/redis_test
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# Number of ms to wait before throwing an exception if no connection is available.
spring.datasource.tomcat.max-wait=10000
# Maximum number of active connections that can be allocated from this pool at the same time.
spring.datasource.tomcat.max-active=50
# Validate the connection before borrowing it from the pool.
spring.datasource.tomcat.test-on-borrow=true
启动,测试一下。
使用postman联调一下。
优化一下时间格式。
成功了。。。
29.3 JPA and ‘Spring Data’ 29.1.2 Connection to a production database
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有