Skip to content

Commit d81c7d9

Browse files
authored
Merge pull request #6 from boylegu/issue/5/api_java
close #5 finished init api architecture
2 parents a34e8de + 6535fbc commit d81c7d9

File tree

9 files changed

+92
-110
lines changed

9 files changed

+92
-110
lines changed

info.db

0 Bytes
Binary file not shown.

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@
5353
<artifactId>spring-boot-starter-test</artifactId>
5454
<scope>test</scope>
5555
</dependency>
56+
57+
<dependency>
58+
<groupId>org.springframework.boot</groupId>
59+
<artifactId>spring-boot-devtools</artifactId>
60+
<optional>true</optional>
61+
</dependency>
62+
63+
<dependency>
64+
<groupId>org.hibernate</groupId>
65+
<artifactId>hibernate-core</artifactId>
66+
<version>5.0.12.Final</version>
67+
</dependency>
5668
</dependencies>
5769

5870
<build>

schema_data.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE persons (id integer, create_datetime datetime, email varchar(255), phone varchar(255), sex varchar(255), username varchar(255), zone blob, primary key (id));
2+
3+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), 'gubaoer@hotmail.com', 08613000001111, 'male', 'gubaoer', 'HongKou District');
4+
5+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), 'boyle.gu@hotmail.com', 08613000001112, 'male', 'baoer.gu', 'JingAn District');
6+
7+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), 'yoyo.wu@gmail.com', 08613000001113, 'fmale', 'yoyo.wu', 'JingAn District');
Lines changed: 18 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,43 @@
11
package com.boylegu.springboot_vue.config;
22

3-
/*
4-
* The author disclaims copyright to this source code. In place of
5-
* a legal notice, here is a blessing:
6-
*
7-
* May you do good and not evil.
8-
* May you find forgiveness for yourself and forgive others.
9-
* May you share freely, never taking more than you give.
10-
*
11-
*/
12-
133
import java.sql.Types;
14-
import org.hibernate.dialect.Dialect;
154

16-
import org.hibernate.dialect.function.AbstractAnsiTrimEmulationFunction;
17-
import org.hibernate.dialect.function.NoArgSQLFunction;
18-
import org.hibernate.dialect.function.SQLFunction;
5+
import org.hibernate.dialect.Dialect;
196
import org.hibernate.dialect.function.SQLFunctionTemplate;
207
import org.hibernate.dialect.function.StandardSQLFunction;
218
import org.hibernate.dialect.function.VarArgsSQLFunction;
22-
import org.hibernate.type.StandardBasicTypes;
9+
import org.hibernate.type.StringType;
2310

2411
public class SQLiteDialect extends Dialect {
2512
public SQLiteDialect() {
26-
registerColumnType(Types.BIT, "boolean");
13+
registerColumnType(Types.BIT, "integer");
2714
registerColumnType(Types.TINYINT, "tinyint");
2815
registerColumnType(Types.SMALLINT, "smallint");
2916
registerColumnType(Types.INTEGER, "integer");
3017
registerColumnType(Types.BIGINT, "bigint");
3118
registerColumnType(Types.FLOAT, "float");
3219
registerColumnType(Types.REAL, "real");
3320
registerColumnType(Types.DOUBLE, "double");
34-
registerColumnType(Types.NUMERIC, "numeric($p, $s)");
21+
registerColumnType(Types.NUMERIC, "numeric");
3522
registerColumnType(Types.DECIMAL, "decimal");
3623
registerColumnType(Types.CHAR, "char");
37-
registerColumnType(Types.VARCHAR, "varchar($l)");
24+
registerColumnType(Types.VARCHAR, "varchar");
3825
registerColumnType(Types.LONGVARCHAR, "longvarchar");
3926
registerColumnType(Types.DATE, "date");
4027
registerColumnType(Types.TIME, "time");
41-
registerColumnType(Types.TIMESTAMP, "datetime");
28+
registerColumnType(Types.TIMESTAMP, "timestamp");
4229
registerColumnType(Types.BINARY, "blob");
4330
registerColumnType(Types.VARBINARY, "blob");
4431
registerColumnType(Types.LONGVARBINARY, "blob");
32+
// registerColumnType(Types.NULL, "null");
4533
registerColumnType(Types.BLOB, "blob");
4634
registerColumnType(Types.CLOB, "clob");
47-
registerColumnType(Types.BOOLEAN, "boolean");
48-
49-
//registerFunction( "abs", new StandardSQLFunction("abs") );
50-
registerFunction( "concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "") );
51-
//registerFunction( "length", new StandardSQLFunction("length", StandardBasicTypes.LONG) );
52-
//registerFunction( "lower", new StandardSQLFunction("lower") );
53-
registerFunction( "mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2" ) );
54-
registerFunction( "quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING) );
55-
registerFunction( "random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER) );
56-
registerFunction( "round", new StandardSQLFunction("round") );
57-
registerFunction( "substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING) );
58-
registerFunction( "substring", new SQLFunctionTemplate( StandardBasicTypes.STRING, "substr(?1, ?2, ?3)" ) );
59-
registerFunction( "trim", new AbstractAnsiTrimEmulationFunction() {
60-
protected SQLFunction resolveBothSpaceTrimFunction() {
61-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)");
62-
}
63-
64-
protected SQLFunction resolveBothSpaceTrimFromFunction() {
65-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)");
66-
}
67-
68-
protected SQLFunction resolveLeadingSpaceTrimFunction() {
69-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)");
70-
}
71-
72-
protected SQLFunction resolveTrailingSpaceTrimFunction() {
73-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)");
74-
}
75-
76-
protected SQLFunction resolveBothTrimFunction() {
77-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)");
78-
}
79-
80-
protected SQLFunction resolveLeadingTrimFunction() {
81-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)");
82-
}
83-
84-
protected SQLFunction resolveTrailingTrimFunction() {
85-
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)");
86-
}
87-
} );
88-
//registerFunction( "upper", new StandardSQLFunction("upper") );
35+
registerColumnType(Types.BOOLEAN, "integer");
36+
37+
registerFunction("concat", new VarArgsSQLFunction(StringType.INSTANCE, "", "||", ""));
38+
registerFunction("mod", new SQLFunctionTemplate(StringType.INSTANCE, "?1 % ?2"));
39+
registerFunction("substr", new StandardSQLFunction("substr", StringType.INSTANCE));
40+
registerFunction("substring", new StandardSQLFunction("substr", StringType.INSTANCE));
8941
}
9042

9143
public boolean supportsIdentityColumns() {
@@ -124,12 +76,8 @@ public boolean supportsLimit() {
12476
return true;
12577
}
12678

127-
public boolean bindLimitParametersInReverseOrder() {
128-
return true;
129-
}
130-
13179
protected String getLimitString(String query, boolean hasOffset) {
132-
return new StringBuffer(query.length()+20).
80+
return new StringBuffer(query.length() + 20).
13381
append(query).
13482
append(hasOffset ? " limit ? offset ?" : " limit ?").
13583
toString();
@@ -144,7 +92,7 @@ public String getCreateTemporaryTableString() {
14492
}
14593

14694
public boolean dropTemporaryTableAfterUse() {
147-
return true; // TODO Validate
95+
return false;
14896
}
14997

15098
public boolean supportsCurrentTimestampSelection() {
@@ -171,11 +119,9 @@ public boolean dropConstraints() {
171119
return false;
172120
}
173121

174-
/*
175-
public String getAddColumnString() {
176-
return "add column";
177-
}
178-
*/
122+
public String getAddColumnString() {
123+
return "add column";
124+
}
179125

180126
public String getForUpdateString() {
181127
return "";
@@ -204,20 +150,6 @@ public boolean supportsIfExistsBeforeTableName() {
204150
}
205151

206152
public boolean supportsCascadeDelete() {
207-
return true;
208-
}
209-
210-
/* not case insensitive for unicode characters by default (ICU extension needed)
211-
public boolean supportsCaseInsensitiveLike() {
212-
return true;
213-
}
214-
*/
215-
216-
public boolean supportsTupleDistinctCounts() {
217153
return false;
218154
}
219-
220-
public String getSelectGUIDString() {
221-
return "select hex(randomblob(16))";
222-
}
223155
}

src/main/java/com/boylegu/springboot_vue/controller/HelloWorldController.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.boylegu.springboot_vue.controller;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RestController;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.web.bind.annotation.RequestMethod;
7+
8+
import com.boylegu.springboot_vue.dao.PersonsRepository;
9+
import com.boylegu.springboot_vue.entities.Persons;
10+
11+
12+
import java.util.List;
13+
14+
@RestController
15+
@RequestMapping("/api/persons")
16+
public class MainController {
17+
18+
@Autowired
19+
private PersonsRepository personsRepository;
20+
21+
@RequestMapping(value="/sex", method = RequestMethod.GET)
22+
public List<Persons> getAll() {
23+
24+
return personsRepository.findAll();
25+
}
26+
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package com.boylegu.springboot_vue.dao;
22

3-
43
import org.springframework.data.jpa.repository.JpaRepository;
5-
import org.springframework.data.jpa.repository.query.Jpa21Utils;
6-
import org.springframework.stereotype.Repository;
74

85
import com.boylegu.springboot_vue.entities.Persons;
96

107

11-
public interface PersonsRepository extends JpaRepository <Persons, Long> {
12-
8+
public interface PersonsRepository extends JpaRepository<Persons, Long> {
139
}

src/main/java/com/boylegu/springboot_vue/entities/Persons.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
package com.boylegu.springboot_vue.entities;
22

33
import javax.persistence.*;
4-
import java.awt.*;
54
import java.util.Date;
5+
import java.io.Serializable;
6+
7+
import org.springframework.format.annotation.DateTimeFormat;
68

79

810
@Entity
9-
public class Persons {
11+
@Table(name = "persons")
12+
public class Persons implements Serializable {
1013
@Id
1114
@GeneratedValue(strategy = GenerationType.AUTO)
1215

1316
private long id;
17+
@Column(name = "create_datetime")
18+
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
1419
private Date create_datetime;
20+
@Column(name = "username")
1521
private String username;
22+
@Column(name = "email")
1623
private String email;
24+
@Column(name = "phone")
1725
private String phone;
26+
@Column(name = "sex")
1827
private String sex;
19-
private TextArea zone;
28+
@Column(name = "zone")
29+
private String zone;
2030

2131
public long getId() {
2232
return id;
@@ -66,4 +76,12 @@ public String getSex() {
6676
public void setSex(String sex) {
6777
this.sex = sex;
6878
}
79+
80+
public String getZone() {
81+
return zone;
82+
}
83+
84+
public void setZone(String zone) {
85+
this.zone = zone;
86+
}
6987
}
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
debug=true
2+
spring.output.ansi.enabled=DETECT
13

2-
spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
4+
# spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
5+
6+
spring.jpa.properties.hibernate.hbm2ddl.auto=update
37
spring.datasource.url=jdbc:sqlite:info.db
48
spring.datasource.driver-class-name = org.sqlite.JDBC
5-
spring.jpa.database-platform=com.boylegu.springboot_vue.config.SQLiteDialect
9+
spring.jpa.database-platform=com.boylegu.springboot_vue.config.SQLiteDialect
10+
spring.jpa.show-sql= true

0 commit comments

Comments
 (0)