File->New->Project選擇Spring Initializr默認使用官方的https://start.spring.io/選擇下一步。java
groupId: com.axd
artifactId: spring_boot_jpa
name: spring_boot_jpamysql
Type: Maven Project
Java Version: 1.8
packaging: Jarweb
點擊下一步選擇web,建立一個新的項目spring
<!-- Spring Boot jpa 依賴 --> <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.axd</groupId> <artifactId>spring_boot_jpa</artifactId> <version>0.0.1-SNAPSHOT</version> <name>spring_boot_jpa</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.13</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
!pom.xml具體配置()sql
spring.datasource.url=jdbc:mysql://192.168.80.129:3306/db_linkbiz spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.jpa.hibernate.ddl-auto=update spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect spring.jpa.show-sql=true
配置好以後測試連接成功數據庫
View->Tool Windows->persistence,默認找不到,須要設置一下。apache
添加Hibernate以後,若是沒有就下載。
app
再次打開就能夠看到persistence
maven
生成實體類
ide
若是粗線這種報錯,則須要增長一個配置
增長
從新建立
繼承JpaRepository,不須要寫實現,默認一些增刪改查
請求localhost:8080/advert/content/all