Skip to content

Commit f63298a

Browse files
committed
SpringBoot+Jpa(hibernate)数据库基本操作
1 parent 3296585 commit f63298a

File tree

16 files changed

+777
-60
lines changed

16 files changed

+777
-60
lines changed

pom.xml

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,71 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
66

7-
<groupId>com.coderdream</groupId>
8-
<artifactId>java-architect-util</artifactId>
9-
<packaging>pom</packaging>
10-
<version>1.0-SNAPSHOT</version>
11-
<modules>
12-
<module>junit5-practice</module>
13-
<module>javamail-practice</module>
14-
<module>poi-practice</module>
15-
<module>spring-javamail-practice</module>
16-
<module>java8-demo</module>
17-
</modules>
7+
<groupId>com.coderdream</groupId>
8+
<artifactId>java-architect-util</artifactId>
9+
<packaging>pom</packaging>
10+
<version>1.0-SNAPSHOT</version>
11+
<modules>
12+
<module>junit5-practice</module>
13+
<module>javamail-practice</module>
14+
<module>poi-practice</module>
15+
<module>spring-javamail-practice</module>
16+
<module>java8-demo</module>
17+
<module>spring-boot-jpa</module>
18+
</modules>
1819

19-
<name>Maven</name>
20-
<!-- FIXME change it to the project's website -->
21-
<url>http://maven.apache.org/</url>
22-
<inceptionYear>2001</inceptionYear>
20+
<name>Maven</name>
21+
<!-- FIXME change it to the project's website -->
22+
<url>http://maven.apache.org/</url>
23+
<inceptionYear>2001</inceptionYear>
2324

24-
<distributionManagement>
25-
<site>
26-
<id>website</id>
27-
<url>scp://webhost.company.com/www/website</url>
28-
</site>
29-
</distributionManagement>
25+
<distributionManagement>
26+
<site>
27+
<id>website</id>
28+
<url>scp://webhost.company.com/www/website</url>
29+
</site>
30+
</distributionManagement>
3031

31-
<properties>
32-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33-
</properties>
32+
<properties>
33+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
34+
</properties>
3435

35-
<build>
36-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
37-
<plugins>
38-
<plugin>
39-
<artifactId>maven-clean-plugin</artifactId>
40-
<version>3.1.0</version>
41-
</plugin>
42-
<plugin>
43-
<artifactId>maven-site-plugin</artifactId>
44-
<version>3.7.1</version>
45-
</plugin>
46-
<plugin>
47-
<artifactId>maven-project-info-reports-plugin</artifactId>
48-
<version>3.0.0</version>
49-
</plugin>
50-
</plugins>
51-
</pluginManagement>
52-
<plugins>
53-
<plugin>
54-
<groupId>org.apache.maven.plugins</groupId>
55-
<artifactId>maven-site-plugin</artifactId>
56-
<configuration>
57-
<locales>en,fr</locales>
58-
</configuration>
59-
</plugin>
60-
</plugins>
61-
</build>
36+
<build>
37+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-clean-plugin</artifactId>
41+
<version>3.1.0</version>
42+
</plugin>
43+
<plugin>
44+
<artifactId>maven-site-plugin</artifactId>
45+
<version>3.7.1</version>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-project-info-reports-plugin</artifactId>
49+
<version>3.0.0</version>
50+
</plugin>
51+
</plugins>
52+
</pluginManagement>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-site-plugin</artifactId>
57+
<configuration>
58+
<locales>en,fr</locales>
59+
</configuration>
60+
</plugin>
61+
</plugins>
62+
</build>
6263

63-
<reporting>
64-
<plugins>
65-
<plugin>
66-
<artifactId>maven-project-info-reports-plugin</artifactId>
67-
</plugin>
68-
</plugins>
69-
</reporting>
64+
<reporting>
65+
<plugins>
66+
<plugin>
67+
<artifactId>maven-project-info-reports-plugin</artifactId>
68+
</plugin>
69+
</plugins>
70+
</reporting>
7071
</project>

spring-boot-jpa/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SpringBootLearning
2+
Spring Boot 学习
3+
#源码跟随Spring Boot的学习而增加,从项目开始建立到加入使用的插件。
4+
主要过程如下
5+
6+
1.用maven搭建项目.
7+
8+
2.添加Swagger2构建RESTful APIs.
9+
10+
3.添加MySQL数据库及JPA.
11+
12+
[SpringBoot+Jpa(hibernate)数据库基本操作](https://blog.csdn.net/juanmiao/article/details/78501064)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="web" name="Web">
5+
<configuration>
6+
<descriptors>
7+
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/src/main/Webapp/WEB-INF/web.xml" />
8+
</descriptors>
9+
<webroots>
10+
<root url="file://$MODULE_DIR$/src/main/webapp" relative="/" />
11+
</webroots>
12+
<sourceRoots>
13+
<root url="file://$MODULE_DIR$/src/main/java" />
14+
<root url="file://$MODULE_DIR$/src/main/resources" />
15+
</sourceRoots>
16+
</configuration>
17+
</facet>
18+
</component>
19+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="false">
20+
<output url="file://$MODULE_DIR$/target/classes" />
21+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
22+
<content url="file://$MODULE_DIR$">
23+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
24+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
25+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
26+
<excludeFolder url="file://$MODULE_DIR$/target" />
27+
</content>
28+
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
29+
<orderEntry type="sourceFolder" forTests="false" />
30+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:1.4.0.RELEASE" level="project" />
31+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.4.0.RELEASE" level="project" />
32+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:1.4.0.RELEASE" level="project" />
33+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:1.4.0.RELEASE" level="project" />
34+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-logging:1.4.0.RELEASE" level="project" />
35+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.1.7" level="project" />
36+
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.1.7" level="project" />
37+
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.21" level="project" />
38+
<orderEntry type="library" name="Maven: org.slf4j:log4j-over-slf4j:1.7.21" level="project" />
39+
<orderEntry type="library" name="Maven: org.springframework:spring-core:4.3.2.RELEASE" level="project" />
40+
<orderEntry type="library" scope="RUNTIME" name="Maven: org.yaml:snakeyaml:1.17" level="project" />
41+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-tomcat:1.4.0.RELEASE" level="project" />
42+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-core:8.5.4" level="project" />
43+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-el:8.5.4" level="project" />
44+
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:8.5.4" level="project" />
45+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-validator:5.2.4.Final" level="project" />
46+
<orderEntry type="library" name="Maven: javax.validation:validation-api:1.1.0.Final" level="project" />
47+
<orderEntry type="library" name="Maven: org.jboss.logging:jboss-logging:3.3.0.Final" level="project" />
48+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.1" level="project" />
49+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.1" level="project" />
50+
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.1" level="project" />
51+
<orderEntry type="library" name="Maven: org.springframework:spring-web:4.3.2.RELEASE" level="project" />
52+
<orderEntry type="library" name="Maven: org.springframework:spring-aop:4.3.2.RELEASE" level="project" />
53+
<orderEntry type="library" name="Maven: org.springframework:spring-beans:4.3.2.RELEASE" level="project" />
54+
<orderEntry type="library" name="Maven: org.springframework:spring-context:4.3.2.RELEASE" level="project" />
55+
<orderEntry type="library" name="Maven: org.springframework:spring-webmvc:4.3.2.RELEASE" level="project" />
56+
<orderEntry type="library" name="Maven: org.springframework:spring-expression:4.3.2.RELEASE" level="project" />
57+
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger2:2.2.2" level="project" />
58+
<orderEntry type="library" name="Maven: org.mapstruct:mapstruct:1.0.0.CR1" level="project" />
59+
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.3" level="project" />
60+
<orderEntry type="library" name="Maven: io.swagger:swagger-models:1.5.3" level="project" />
61+
<orderEntry type="library" name="Maven: io.springfox:springfox-spi:2.2.2" level="project" />
62+
<orderEntry type="library" name="Maven: io.springfox:springfox-core:2.2.2" level="project" />
63+
<orderEntry type="library" name="Maven: io.springfox:springfox-schema:2.2.2" level="project" />
64+
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-common:2.2.2" level="project" />
65+
<orderEntry type="library" name="Maven: io.springfox:springfox-spring-web:2.2.2" level="project" />
66+
<orderEntry type="library" name="Maven: com.google.guava:guava:18.0" level="project" />
67+
<orderEntry type="library" name="Maven: com.fasterxml:classmate:1.3.1" level="project" />
68+
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.21" level="project" />
69+
<orderEntry type="library" name="Maven: org.aspectj:aspectjrt:1.8.9" level="project" />
70+
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.9" level="project" />
71+
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-core:1.2.0.RELEASE" level="project" />
72+
<orderEntry type="library" name="Maven: org.springframework.plugin:spring-plugin-metadata:1.2.0.RELEASE" level="project" />
73+
<orderEntry type="library" name="Maven: org.springframework.hateoas:spring-hateoas:0.20.0.RELEASE" level="project" />
74+
<orderEntry type="library" name="Maven: io.springfox:springfox-swagger-ui:2.2.2" level="project" />
75+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-data-jpa:1.4.0.RELEASE" level="project" />
76+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-aop:1.4.0.RELEASE" level="project" />
77+
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-jdbc:1.4.0.RELEASE" level="project" />
78+
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-jdbc:8.5.4" level="project" />
79+
<orderEntry type="library" name="Maven: org.apache.tomcat:tomcat-juli:8.5.4" level="project" />
80+
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:4.3.2.RELEASE" level="project" />
81+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-core:5.0.9.Final" level="project" />
82+
<orderEntry type="library" name="Maven: org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final" level="project" />
83+
<orderEntry type="library" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
84+
<orderEntry type="library" name="Maven: antlr:antlr:2.7.7" level="project" />
85+
<orderEntry type="library" name="Maven: org.jboss:jandex:2.0.0.Final" level="project" />
86+
<orderEntry type="library" name="Maven: dom4j:dom4j:1.6.1" level="project" />
87+
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
88+
<orderEntry type="library" name="Maven: org.hibernate.common:hibernate-commons-annotations:5.0.1.Final" level="project" />
89+
<orderEntry type="library" name="Maven: org.hibernate:hibernate-entitymanager:5.0.9.Final" level="project" />
90+
<orderEntry type="library" name="Maven: javax.transaction:javax.transaction-api:1.2" level="project" />
91+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-jpa:1.10.2.RELEASE" level="project" />
92+
<orderEntry type="library" name="Maven: org.springframework.data:spring-data-commons:1.12.2.RELEASE" level="project" />
93+
<orderEntry type="library" name="Maven: org.springframework:spring-orm:4.3.2.RELEASE" level="project" />
94+
<orderEntry type="library" name="Maven: org.springframework:spring-tx:4.3.2.RELEASE" level="project" />
95+
<orderEntry type="library" name="Maven: org.slf4j:jcl-over-slf4j:1.7.21" level="project" />
96+
<orderEntry type="library" name="Maven: org.springframework:spring-aspects:4.3.2.RELEASE" level="project" />
97+
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.39" level="project" />
98+
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1" level="project" />
99+
<orderEntry type="library" name="Maven: org.mybatis.spring.boot:mybatis-spring-boot-autoconfigure:1.1.1" level="project" />
100+
<orderEntry type="library" name="Maven: org.mybatis:mybatis:3.4.0" level="project" />
101+
<orderEntry type="library" name="Maven: org.mybatis:mybatis-spring:1.3.0" level="project" />
102+
</component>
103+
</module>

spring-boot-jpa/pom.xml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.coderdream</groupId>
8+
<artifactId>spring-boot-jpa</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<parent>
12+
<groupId>org.springframework.boot</groupId>
13+
<artifactId>spring-boot-starter-parent</artifactId>
14+
<version>1.4.0.RELEASE</version>
15+
</parent>
16+
17+
<properties>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-web</artifactId>
25+
</dependency>
26+
27+
<!--添加swagger-->
28+
<dependency>
29+
<groupId>io.springfox</groupId>
30+
<artifactId>springfox-swagger2</artifactId>
31+
<version>2.2.2</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>io.springfox</groupId>
35+
<artifactId>springfox-swagger-ui</artifactId>
36+
<version>2.2.2</version>
37+
</dependency>
38+
39+
<!-- 添加Mysql和JPA-->
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-data-jpa</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>mysql</groupId>
46+
<artifactId>mysql-connector-java</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.mybatis.spring.boot</groupId>
51+
<artifactId>mybatis-spring-boot-starter</artifactId>
52+
<version>1.1.1</version>
53+
</dependency>
54+
</dependencies>
55+
<build>
56+
<plugins>
57+
<plugin>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-maven-plugin</artifactId>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
64+
<repositories>
65+
<repository>
66+
<id>spring-releases</id>
67+
<url>https://repo.spring.io/libs-release</url>
68+
</repository>
69+
</repositories>
70+
<pluginRepositories>
71+
<pluginRepository>
72+
<id>spring-releases</id>
73+
<url>https://repo.spring.io/libs-release</url>
74+
</pluginRepository>
75+
</pluginRepositories>
76+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.shanghai;
2+
import org.springframework.boot.SpringApplication;
3+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
/**
8+
* Created by lijm on 2017/11/06
9+
*/
10+
@EnableAutoConfiguration
11+
@ComponentScan
12+
@Configuration
13+
public class Application{
14+
15+
public static void main(String[] args){
16+
SpringApplication.run(Application.class,args);
17+
}
18+
19+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.shanghai;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import springfox.documentation.builders.ApiInfoBuilder;
6+
import springfox.documentation.builders.PathSelectors;
7+
import springfox.documentation.builders.RequestHandlerSelectors;
8+
import springfox.documentation.service.ApiInfo;
9+
import springfox.documentation.spi.DocumentationType;
10+
import springfox.documentation.spring.web.plugins.Docket;
11+
import springfox.documentation.swagger2.annotations.EnableSwagger2;
12+
13+
/**
14+
* Created by lijm on 2017/11/06
15+
*/
16+
@Configuration
17+
@EnableSwagger2
18+
public class Swagger2Configure {
19+
20+
@Bean
21+
public Docket createRestApi() {
22+
return new Docket(DocumentationType.SWAGGER_2)
23+
.apiInfo(apiInfo())
24+
.select()
25+
.apis(RequestHandlerSelectors.basePackage("com.shanghai.controller"))
26+
.paths(PathSelectors.any())
27+
.build();
28+
}
29+
30+
private ApiInfo apiInfo() {
31+
return new ApiInfoBuilder()
32+
.title("Spring Boot中使用Swagger2构建RESTful APIs")
33+
.description("Spring Boot Swagger2")
34+
.contact("seawater")
35+
.version("1.0")
36+
.build();
37+
}
38+
39+
}

0 commit comments

Comments
 (0)