Skip to content

Commit 8de7f6b

Browse files
committed
add jpa examples
1 parent 7e5df2a commit 8de7f6b

28 files changed

+1125
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.neo</groupId>
7+
<artifactId>spring-boot-Jpa</artifactId>
8+
<version>1.0.0</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-Jpa</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.1.0.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-data-jpa</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>mysql</groupId>
34+
<artifactId>mysql-connector-java</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-test</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.springframework.boot</groupId>
47+
<artifactId>spring-boot-maven-plugin</artifactId>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
52+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.neo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.domain.EntityScan;
6+
7+
@SpringBootApplication
8+
public class JpaApplication {
9+
10+
public static void main(String[] args) {
11+
SpringApplication.run(JpaApplication.class, args);
12+
}
13+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.neo.model;
2+
3+
import javax.persistence.Column;
4+
import javax.persistence.Entity;
5+
import javax.persistence.GeneratedValue;
6+
import javax.persistence.Id;
7+
8+
@Entity
9+
public class Address {
10+
11+
@Id
12+
@GeneratedValue
13+
private Long id;
14+
@Column(nullable = false)
15+
private Long userId;
16+
private String province;
17+
private String city;
18+
private String street;
19+
20+
public Long getId() {
21+
return id;
22+
}
23+
24+
public void setId(Long id) {
25+
this.id = id;
26+
}
27+
28+
public Long getUserId() {
29+
return userId;
30+
}
31+
32+
public void setUserId(Long userId) {
33+
this.userId = userId;
34+
}
35+
36+
public String getProvince() {
37+
return province;
38+
}
39+
40+
public void setProvince(String province) {
41+
this.province = province;
42+
}
43+
44+
public String getCity() {
45+
return city;
46+
}
47+
48+
public void setCity(String city) {
49+
this.city = city;
50+
}
51+
52+
public String getStreet() {
53+
return street;
54+
}
55+
56+
public void setStreet(String street) {
57+
this.street = street;
58+
}
59+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.neo.model;
2+
3+
4+
5+
import javax.persistence.Column;
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.Id;
9+
10+
import java.io.Serializable;
11+
12+
@Entity
13+
public class User {
14+
15+
@Id
16+
@GeneratedValue
17+
private Long id;
18+
@Column(nullable = false, unique = true)
19+
private String userName;
20+
@Column(nullable = false)
21+
private String passWord;
22+
@Column(nullable = false, unique = true)
23+
private String email;
24+
@Column(nullable = true, unique = true)
25+
private String nickName;
26+
@Column(nullable = false)
27+
private String regTime;
28+
29+
public User() {
30+
}
31+
32+
public User(String userName, String passWord, String email, String nickName, String regTime) {
33+
this.userName = userName;
34+
this.passWord = passWord;
35+
this.email = email;
36+
this.nickName = nickName;
37+
this.regTime = regTime;
38+
}
39+
40+
public Long getId() {
41+
return id;
42+
}
43+
44+
public void setId(Long id) {
45+
this.id = id;
46+
}
47+
48+
public String getUserName() {
49+
return userName;
50+
}
51+
52+
public void setUserName(String userName) {
53+
this.userName = userName;
54+
}
55+
56+
public String getPassWord() {
57+
return passWord;
58+
}
59+
60+
public void setPassWord(String passWord) {
61+
this.passWord = passWord;
62+
}
63+
64+
public String getEmail() {
65+
return email;
66+
}
67+
68+
public void setEmail(String email) {
69+
this.email = email;
70+
}
71+
72+
public String getNickName() {
73+
return nickName;
74+
}
75+
76+
public void setNickName(String nickName) {
77+
this.nickName = nickName;
78+
}
79+
80+
public String getRegTime() {
81+
return regTime;
82+
}
83+
84+
public void setRegTime(String regTime) {
85+
this.regTime = regTime;
86+
}
87+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package com.neo.model;
2+
3+
4+
import org.hibernate.annotations.Fetch;
5+
import org.hibernate.annotations.FetchMode;
6+
7+
import javax.persistence.*;
8+
import java.io.Serializable;
9+
10+
@Entity
11+
public class UserDetail {
12+
13+
@Id
14+
@GeneratedValue
15+
private Long id;
16+
@Column(nullable = false, unique = true)
17+
private Long userId;
18+
private Integer age;
19+
private String realName;
20+
private String status;
21+
private String hobby;
22+
private String introduction;
23+
private String lastLoginIp;
24+
25+
public Long getId() {
26+
return id;
27+
}
28+
29+
public void setId(Long id) {
30+
this.id = id;
31+
}
32+
33+
public Long getUserId() {
34+
return userId;
35+
}
36+
37+
public void setUserId(Long userId) {
38+
this.userId = userId;
39+
}
40+
41+
public Integer getAge() {
42+
return age;
43+
}
44+
45+
public void setAge(Integer age) {
46+
this.age = age;
47+
}
48+
49+
public String getRealName() {
50+
return realName;
51+
}
52+
53+
public void setRealName(String realName) {
54+
this.realName = realName;
55+
}
56+
57+
public String getStatus() {
58+
return status;
59+
}
60+
61+
public void setStatus(String status) {
62+
this.status = status;
63+
}
64+
65+
public String getHobby() {
66+
return hobby;
67+
}
68+
69+
public void setHobby(String hobby) {
70+
this.hobby = hobby;
71+
}
72+
73+
public String getIntroduction() {
74+
return introduction;
75+
}
76+
77+
public void setIntroduction(String introduction) {
78+
this.introduction = introduction;
79+
}
80+
81+
public String getLastLoginIp() {
82+
return lastLoginIp;
83+
}
84+
85+
public void setLastLoginIp(String lastLoginIp) {
86+
this.lastLoginIp = lastLoginIp;
87+
}
88+
89+
@Override
90+
public String toString() {
91+
return "UserDetail{" +
92+
"id=" + id +
93+
", userId=" + userId +
94+
", age=" + age +
95+
", realName='" + realName + '\'' +
96+
", status='" + status + '\'' +
97+
", hobby='" + hobby + '\'' +
98+
", introduction='" + introduction + '\'' +
99+
", lastLoginIp='" + lastLoginIp + '\'' +
100+
'}';
101+
}
102+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.neo.model;
2+
3+
public interface UserInfo {
4+
String getUserName();
5+
String getEmail();
6+
String getHobby();
7+
String getIntroduction();
8+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.neo.param;
2+
3+
4+
import com.neo.model.Address;
5+
import org.hibernate.annotations.Fetch;
6+
import org.hibernate.annotations.FetchMode;
7+
8+
import javax.persistence.*;
9+
10+
public class UserDetailParam {
11+
private String userId;
12+
private Integer minAge;
13+
private Integer maxAge;
14+
private String realName;
15+
private String introduction;
16+
private String city;
17+
18+
public String getUserId() {
19+
return userId;
20+
}
21+
22+
public void setUserId(String userId) {
23+
this.userId = userId;
24+
}
25+
26+
public Integer getMinAge() {
27+
return minAge;
28+
}
29+
30+
public void setMinAge(Integer minAge) {
31+
this.minAge = minAge;
32+
}
33+
34+
public Integer getMaxAge() {
35+
return maxAge;
36+
}
37+
38+
public void setMaxAge(Integer maxAge) {
39+
this.maxAge = maxAge;
40+
}
41+
42+
public String getRealName() {
43+
return realName;
44+
}
45+
46+
public void setRealName(String realName) {
47+
this.realName = realName;
48+
}
49+
50+
public String getIntroduction() {
51+
return introduction;
52+
}
53+
54+
public void setIntroduction(String introduction) {
55+
this.introduction = introduction;
56+
}
57+
58+
public String getCity() {
59+
return city;
60+
}
61+
62+
public void setCity(String city) {
63+
this.city = city;
64+
}
65+
}

0 commit comments

Comments
 (0)