pom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<?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> <groupId>com.example</groupId> <artifactId>springboot-jpa-oracle-demo</artifactId> <version> 0.0 . 1 -SNAPSHOT</version> <packaging>jar</packaging> <name>springboot-jpa-oracle-demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version> 2.0 . 5 .RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF- 8 </project.build.sourceEncoding> <project.reporting.outputEncoding>UTF- 8 </project.reporting.outputEncoding> <java.version> 1.8 </java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
pom.xml
application.properties
domain:
repository:
controller:
启动程序
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> |
application.properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
spring.datasource.url=jdbc:oracle:thin: @localhost : 1521 :ORCL spring.datasource.username=test spring.datasource.password=test spring.datasource.driver- class -name=oracle.jdbc.driver.OracleDriver spring.jpa.properties.hibernate.hbm2ddl.auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect spring.jpa.show-sql= true spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl server.port = 9000 |
domain:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
package com.example.demo.domain; import javax.persistence.Column; import javax.persistence.GeneratedValue; import javax.persistence.Id; import org.hibernate.annotations.GenericGenerator; @javax .persistence.Table(name = "t_dynasty" ) @javax .persistence.Entity public class Dynasty { /** * * id * */ @Id @GenericGenerator (name = "system-uuid" , strategy = "uuid" ) @GeneratedValue (generator = "system-uuid" ) @Column (name = "id" ) private String id; @Column (name = "name" ) private String name; @Column (name = "startYear" ) private String startYear; @Column (name = "endYear" ) private String endYear; @Column (name = "age" ) private Integer age; public String getId() { return id; } public void setId(String id) { this .id = id; } public String getName() { return name; } public void setName(String name) { this .name = name; } public String getStartYear() { return startYear; } public void setStartYear(String startYear) { this .startYear = startYear; } public String getEndYear() { return endYear; } public void setEndYear(String endYear) { this .endYear = endYear; } public Integer getAge() { return age; } public void setAge(Integer age) { this .age = age; } } |
repository:
1
2
3
4
5
6
7
8
|
package com.example.demo.repository; import org.springframework.data.jpa.repository.JpaRepository; import com.example.demo.domain.Dynasty; public interface DynastyRepository extends JpaRepository<Dynasty, Long> { } |
controller:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package com.example.demo.web; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.example.demo.domain.Dynasty; import com.example.demo.repository.DynastyRepository; @RestController @RequestMapping ( "/dynasty" ) public class DynastyController { @Autowired private DynastyRepository dynastyRepository; @RequestMapping ( "/findAll" ) public List<Dynasty> findAll() { List<Dynasty> dynastys = dynastyRepository.findAll(); return dynastys; } @RequestMapping ( "/hello" ) public String hello() { return "success" ; } } |
启动程序
1
2
3
4
5
6
7
8
9
10
11
|
package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class Demo1Application { public static void main(String[] args) { SpringApplication.run(Demo1Application. class , args); } } |