Idea创建spring boot 项目(4)整合Spring Data Jpa

本文详细介绍了如何在Idea中创建一个Spring Boot项目,并整合Spring Data JPA,涉及添加依赖、配置文件设置、JPA配置类编写、数据库表创建、实体类和JPA接口设计,以及测试接口的步骤。示例使用了HikariCP作为数据源,配合Lombok简化代码,同时利用Swagger进行API文档展示。
摘要由CSDN通过智能技术生成

接博客---> Idea创建spring boot 项目(3)集成Lombok

使用工具:

    IDE:idea 2017.2.6

    Spirng boot:1.5.9

    Swagger版本:2.7.0

    Lombok版本:1.16.20

        MySql版本:6.0.6

        数据库连接池:HikariCP 2.7.7

1、添加依赖:

    打开项目build.gradle文件,添加依赖如下:

buildscript {
   ext {
      springBootVersion = '1.5.9.RELEASE'//spring boot 版本
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}


//添加资源库
repositories {
   maven { url 'http://maven.aliyun.com/nexus/content/repositories/central' }//添加阿里仓库
   mavenCentral()//添加Maven中央资源库
}


apply plugin: 'java'// 指定项目为java项目,项目编译(在项目提示符下执行:gradle build)时生成项目的jar包。
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'application'

group = 'com.demo'
version = '1.5.9-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8

mainClassName = 'com.tinckay.App'//告诉gradle启动类的路径

dependencies {

   compile("org.springframework.boot:spring-boot-starter-web")

   testCompile("org.springframework.boot:spring-boot-starter-test")

   compile("org.springframework.boot:spring-boot-starter-tomcat")

   compile("io.springfox:springfox-swagger2:2.7.0")//swagger2核心依赖
   compile("io.springfox:springfox-swagger-ui:2.7.0")//为项目提供api展示及测试的界面

   compile("org.projectlombok:lombok:1.16.20")//lombok依赖包

   compile("org.springframework.boot:spring-boot-starter-data-jpa")

   compile("mysql:mysql-connector-java:6.0.6")//连接mysql数据库驱动
   compile("com.zaxxer:HikariCP:2.7.7")//HikariCP 数据库连接池依赖

}


2、配置文件:

            打开项目application.properties文件,配置如下信息:

            注意:数据源的配置信息要配本机的;

#配置端口号
server.port=5252

#配置数据源
db.driver=com.mysql.jdbc.Driver
db.username=test
db.password=
db.url=jdbc:mysql://127.0.0.1:3306/demo

#Hibernate Configuration
hibernate.naming.strategy=org.hibernate.cfg.DefaultComponentSafeNamingStrategy
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.hbm2ddl.auto=none
hibernate.connection.autocommit=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值