Skip to content

Commit 2d2bb5c

Browse files
committed
add spring boot jpa examples
1 parent 5dc76a5 commit 2d2bb5c

28 files changed

+1133
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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>3.0.0</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<java.version>17</java.version>
24+
</properties>
25+
26+
<dependencies>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-data-jpa</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>mysql</groupId>
33+
<artifactId>mysql-connector-java</artifactId>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-test</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.junit.vintage</groupId>
41+
<artifactId>junit-vintage-engine</artifactId>
42+
<scope>test</scope>
43+
<exclusions>
44+
<exclusion>
45+
<groupId>org.hamcrest</groupId>
46+
<artifactId>hamcrest-core</artifactId>
47+
</exclusion>
48+
</exclusions>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-maven-plugin</artifactId>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.neo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class JpaApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(JpaApplication.class, args);
11+
}
12+
}
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 jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.Id;
7+
8+
@Entity
9+
public class Address {
10+
11+
@Id
12+
@GeneratedValue
13+
private Long id;
14+
@Column(nullable = false, length = 30)
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: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.neo.model;
2+
3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
5+
import jakarta.persistence.GeneratedValue;
6+
import jakarta.persistence.Id;
7+
8+
@Entity
9+
public class User {
10+
11+
@Id
12+
@GeneratedValue
13+
private Long id;
14+
@Column(nullable = false, unique = true, length = 30)
15+
private String userName;
16+
@Column(nullable = false)
17+
private String passWord;
18+
@Column(nullable = false, unique = true, length = 30)
19+
private String email;
20+
@Column(nullable = true, unique = true, length = 30)
21+
private String nickName;
22+
@Column(nullable = false)
23+
private String regTime;
24+
25+
public User() {
26+
}
27+
28+
public User(String userName, String passWord, String email, String nickName, String regTime) {
29+
this.userName = userName;
30+
this.passWord = passWord;
31+
this.email = email;
32+
this.nickName = nickName;
33+
this.regTime = regTime;
34+
}
35+
36+
public Long getId() {
37+
return id;
38+
}
39+
40+
public void setId(Long id) {
41+
this.id = id;
42+
}
43+
44+
public String getUserName() {
45+
return userName;
46+
}
47+
48+
public void setUserName(String userName) {
49+
this.userName = userName;
50+
}
51+
52+
public String getPassWord() {
53+
return passWord;
54+
}
55+
56+
public void setPassWord(String passWord) {
57+
this.passWord = passWord;
58+
}
59+
60+
public String getEmail() {
61+
return email;
62+
}
63+
64+
public void setEmail(String email) {
65+
this.email = email;
66+
}
67+
68+
public String getNickName() {
69+
return nickName;
70+
}
71+
72+
public void setNickName(String nickName) {
73+
this.nickName = nickName;
74+
}
75+
76+
public String getRegTime() {
77+
return regTime;
78+
}
79+
80+
public void setRegTime(String regTime) {
81+
this.regTime = regTime;
82+
}
83+
}
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 jakarta.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, length = 30)
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 jakarta.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)