Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhenglongfei
committed
Mar 7, 2019
1 parent
abc1501
commit 1b36bfc
Showing
19 changed files
with
665 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
CREATE TABLE `t_user` ( | ||
`id` int(11) unsigned NOT NULL primary key AUTO_INCREMENT, | ||
`name` varchar(20) DEFAULT NULL, | ||
`url` varchar(50) DEFAULT NULL, | ||
); | ||
INSERT INTO client (id,name,address,city,telephone) VALUES (1, 'tom','am','beijing',1333333); | ||
INSERT INTO card (id,number,ccv,type,client_id) VALUES (1, '01111111','123','xinyongka',1); | ||
INSERT INTO consumption_his (id,client_id,card_id,consumption_date,description,amount) VALUES (1,1,1,'2019-02-21 00:05:00','testing',100); | ||
INSERT INTO bank_advisors (consumption_his_id,name,specialty) VALUES (1, 'jerry','i dontt no'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?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"> | ||
<parent> | ||
<artifactId>jpa-example</artifactId> | ||
<groupId>cn.merryyou</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>ibm-crud</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-data-jpa</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>1.4.196</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</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-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-autoconfigure</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.6.1</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
15 changes: 15 additions & 0 deletions
15
ibm-crud/src/main/java/com/ibm/crud/JpaIBMApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.ibm.crud; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
/** | ||
* | ||
*/ | ||
@SpringBootApplication | ||
public class JpaIBMApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(JpaIBMApplication.class, args); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
ibm-crud/src/main/java/com/ibm/crud/common/NumberUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.ibm.crud.common; | ||
|
||
public class NumberUtils { | ||
public static String formatCard(String cardNumber) { | ||
if (cardNumber == null) { | ||
return null; | ||
} | ||
char delimiter = ' '; | ||
return cardNumber.replaceAll(".{4}(?!$)", "$0" + delimiter); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
ibm-crud/src/main/java/com/ibm/crud/domain/BankAdvisors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.ibm.crud.domain; | ||
|
||
import org.hibernate.validator.constraints.Length; | ||
|
||
import javax.persistence.*; | ||
import java.io.Serializable; | ||
|
||
@Entity | ||
@Table(name = "bank_advisors") | ||
public class BankAdvisors implements Serializable { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@Column | ||
@Length(max = 50) | ||
private String name; | ||
|
||
@Column | ||
@Length(max = 50) | ||
private String specialty; | ||
|
||
@OneToOne(cascade = CascadeType.ALL) | ||
@JoinColumn(name = "consumption_his_id") | ||
private ConsumptionHis consumptionHis; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getSpecialty() { | ||
return specialty; | ||
} | ||
|
||
public void setSpecialty(String specialty) { | ||
this.specialty = specialty; | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public ConsumptionHis getConsumptionHis() { | ||
return consumptionHis; | ||
} | ||
|
||
public void setConsumptionHis(ConsumptionHis consumptionHis) { | ||
this.consumptionHis = consumptionHis; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package com.ibm.crud.domain; | ||
|
||
import com.ibm.crud.common.NumberUtils; | ||
import lombok.Data; | ||
import org.hibernate.validator.constraints.Length; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.Pattern; | ||
import java.io.Serializable; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Table(name = "card") | ||
public class Card implements Serializable { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@Column | ||
@Length(min = 16, max = 16) | ||
@Pattern(regexp = "^[0-9]+$") | ||
private String number; | ||
|
||
@Length(min = 3, max = 4) | ||
private String ccv; | ||
|
||
@Length(max = 50) | ||
private String type; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "client_id") | ||
private Client client; | ||
|
||
@OneToMany(mappedBy = "card", cascade = CascadeType.ALL) | ||
private Set<ConsumptionHis> consumptionHis; | ||
|
||
public String getNumber() { | ||
return NumberUtils.formatCard(number); | ||
} | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public void setNumber(String number) { | ||
this.number = number; | ||
} | ||
|
||
public String getCcv() { | ||
return ccv; | ||
} | ||
|
||
public void setCcv(String ccv) { | ||
this.ccv = ccv; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public Client getClient() { | ||
return client; | ||
} | ||
|
||
public void setClient(Client client) { | ||
this.client = client; | ||
} | ||
|
||
public Set<ConsumptionHis> getConsumptionHis() { | ||
return consumptionHis; | ||
} | ||
|
||
public void setConsumptionHis(Set<ConsumptionHis> consumptionHis) { | ||
this.consumptionHis = consumptionHis; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String result = String.format( | ||
"Card[id=%d, number='%s', ccv='%s', type='%s']%n", | ||
id, number, ccv, type); | ||
|
||
if (consumptionHis != null) { | ||
for (ConsumptionHis his : consumptionHis) { | ||
result += String.format( | ||
"ConsumptionHis[id=%d, consumption_date='%s', description='%s', amount='%s']%n", | ||
his.getId(), his.getConsumptionDate(), his.getDescription(), his.getAmount()); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.ibm.crud.domain; | ||
|
||
import org.hibernate.validator.constraints.Length; | ||
|
||
import javax.persistence.*; | ||
import javax.validation.constraints.Pattern; | ||
import java.io.Serializable; | ||
import java.util.Set; | ||
|
||
@Entity | ||
@Table(name = "client") | ||
public class Client implements Serializable { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Integer id; | ||
|
||
@Column | ||
@Length(max = 50) | ||
private String name; | ||
|
||
@Length(max = 100) | ||
@Pattern(regexp = "^[a-zA-Z0-9]+$") | ||
private String address; | ||
|
||
@Length(max = 30) | ||
@Pattern(regexp = "^[a-zA-Z0-9]+$") | ||
private String city; | ||
|
||
@Length(max = 20) | ||
@Pattern(regexp = "^[0-9]+$") | ||
private String telephone; | ||
|
||
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL) | ||
private Set<Card> cards; | ||
|
||
@OneToMany(mappedBy = "client", cascade = CascadeType.ALL) | ||
private Set<ConsumptionHis> consumptionHis; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getAddress() { | ||
return address; | ||
} | ||
|
||
public void setAddress(String address) { | ||
this.address = address; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public void setCity(String city) { | ||
this.city = city; | ||
} | ||
|
||
public String getTelephone() { | ||
return telephone; | ||
} | ||
|
||
public void setTelephone(String telephone) { | ||
this.telephone = telephone; | ||
} | ||
|
||
public Set<Card> getCards() { | ||
return cards; | ||
} | ||
|
||
public void setCards(Set<Card> cards) { | ||
this.cards = cards; | ||
} | ||
|
||
public Set<ConsumptionHis> getConsumptionHis() { | ||
return consumptionHis; | ||
} | ||
|
||
public void setConsumptionHis(Set<ConsumptionHis> consumptionHis) { | ||
this.consumptionHis = consumptionHis; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String result = String.format( | ||
"Client[id=%d, name='%s', address='%s', city='%s', telephone='%s']%n", | ||
id, name, address, city, telephone); | ||
if (cards != null) { | ||
for (Card card : cards) { | ||
result += String.format( | ||
"Card[id=%d, number='%s', ccv='%s', type='%s']%n", | ||
card.getId(), card.getNumber(), card.getCcv(), card.getType()); | ||
} | ||
} | ||
if (consumptionHis != null) { | ||
for(ConsumptionHis his: consumptionHis){ | ||
result += String.format( | ||
"ConsumptionHis[id=%d, consumption_date='%s', description='%s', amount='%s']%n", | ||
his.getId(), his.getConsumptionDate(), his.getDescription(), his.getAmount()); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.