Skip to content

Commit f9d0e28

Browse files
顾鲍尔顾鲍尔
authored andcommitted
close boylegu#7 finished init pagination
1 parent 2d6c783 commit f9d0e28

File tree

8 files changed

+135
-8
lines changed

8 files changed

+135
-8
lines changed

info.db

2 KB
Binary file not shown.

schema_data.sql

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1+
/*
2+
* below to information is fake data or fiction data.Please don't take for reality.
3+
*/
4+
5+
16
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));
27

38
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001111, 'male', 'gubaoer', 'HongKou District');
49

510
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001112, 'male', 'baoer.gu', 'JingAn District');
611

7-
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001113, 'fmale', 'yoyo.wu', 'JingAn District');
12+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001113, 'fmale', 'yoyo.wu', 'JingAn District');
13+
14+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001114, 'fmale', 'stacy.gao', 'MinHang District');
15+
16+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001115, 'fmale', 'yomiko.zhu', 'PuDong District');
17+
18+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001116, 'male', 'hong.zhu', 'YangPu District');
19+
20+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001117, 'male', 'leon.lai', 'JinShan District');
21+
22+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001118, 'male', 'mark.lei', 'HuangPu District');
23+
24+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001119, 'male', 'wen.liu', 'ChongMing District');
25+
26+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001120, 'fmale', 'cai.lu', 'BaoShan District');
27+
28+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001121, 'male', 'alex.li', 'ChangNing District');
29+
30+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001122, 'fmale', 'sofia.xu', 'ZhaBei District');
31+
32+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001123, 'fmale', 'cora.zhang', 'XuHui District');
33+
34+
INSERT INTO persons (create_datetime, email, phone, sex, username, zone) VALUES (datetime('now'), '[email protected]', 08613000001124, 'fmale', 'tom.gao', 'HuangPu District');
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.boylegu.springboot_vue.config;
2+
3+
import javax.persistence.criteria.CriteriaBuilder;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
public class NiHao {
8+
9+
private Integer count, page;
10+
//private List<String> phoneNumbers = Collections.emptyList();
11+
12+
public void setCount(Integer name) {
13+
this.count = name;
14+
}
15+
16+
public Integer getCount() {
17+
return count;
18+
}
19+
20+
public Integer getPage() {
21+
return page;
22+
}
23+
24+
public void setPage(Integer page) {
25+
this.page = page;
26+
}
27+
}

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

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
import org.springframework.web.bind.annotation.RequestMapping;
44
import org.springframework.web.bind.annotation.RequestMethod;
55
import org.springframework.web.bind.annotation.RestController;
6-
import org.springframework.beans.factory.annotation.Autowired;
76
import org.springframework.http.ResponseEntity;
87
import org.springframework.http.HttpStatus;
8+
import org.springframework.beans.factory.annotation.Autowired;
9+
import org.springframework.data.domain.Pageable;
10+
import org.springframework.data.domain.Sort;
11+
import org.springframework.data.domain.Sort.Direction;
12+
import org.springframework.data.domain.PageRequest;
913

14+
import com.boylegu.springboot_vue.controller.pagination.PaginationMultiTypeValuesHelper;
1015
import com.boylegu.springboot_vue.dao.PersonsRepository;
1116

12-
import java.util.Map;
13-
import java.util.HashMap;
14-
import java.util.ArrayList;
17+
import java.util.*;
1518

1619

1720
@RestController
@@ -34,12 +37,12 @@ public class MainController {
3437
private PersonsRepository personsRepository;
3538

3639
@RequestMapping(value = "/sex", method = RequestMethod.GET)
37-
public ResponseEntity<?> getAll() {
40+
public ResponseEntity<?> getSexAll() {
3841

39-
ArrayList<Map<String, String>> results = new ArrayList<Map<java.lang.String, java.lang.String>>();
42+
ArrayList<Map<String, String>> results = new ArrayList<>();
4043

4144
for (Object value : personsRepository.findSex()) {
42-
Map<String, String> sex = new HashMap<String, String>();
45+
Map<String, String> sex = new HashMap<>();
4346

4447
sex.put("label", value.toString());
4548
sex.put("value", value.toString());
@@ -50,4 +53,28 @@ public ResponseEntity<?> getAll() {
5053
return responseEntity;
5154
}
5255

56+
@RequestMapping(value = "/", method = RequestMethod.GET)
57+
public Map<String, PaginationMultiTypeValuesHelper> getPersonsAll() {
58+
59+
int page = 1, size = 5;
60+
Sort sort = new Sort(Direction.ASC, "id");
61+
Pageable pageable = new PageRequest(page, size, sort);
62+
63+
PaginationMultiTypeValuesHelper multiValue = new PaginationMultiTypeValuesHelper();
64+
Map<String, PaginationMultiTypeValuesHelper> results = new HashMap<>();
65+
66+
Integer count = personsRepository.findAll(pageable).getSize();
67+
Integer page_number = personsRepository.findAll(pageable).getNumber();
68+
69+
Object content = personsRepository.findAll(pageable).getContent();
70+
Long total = personsRepository.count();
71+
multiValue.setCount(count);
72+
multiValue.setPage(page_number);
73+
multiValue.setResults(content);
74+
multiValue.setTotal(total);
75+
76+
results.put("data", multiValue);
77+
return results;
78+
}
79+
5380
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.boylegu.springboot_vue.controller.pagination;
2+
3+
public class Pagination {
4+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.boylegu.springboot_vue.controller.pagination;
2+
3+
public class PaginationMultiTypeValuesHelper {
4+
private Integer count, page;
5+
private Object results;
6+
private Long total;
7+
//private List<String> phoneNumbers = Collections.emptyList();
8+
9+
public void setCount(Integer name) {
10+
this.count = name;
11+
}
12+
13+
public Integer getCount() {
14+
return count;
15+
}
16+
17+
public Integer getPage() {
18+
return page;
19+
}
20+
21+
public void setPage(Integer page) {
22+
this.page = page;
23+
}
24+
25+
public Object getResults() {
26+
return results;
27+
}
28+
29+
public void setResults(Object results) {
30+
this.results = results;
31+
}
32+
33+
public Long getTotal() {
34+
return total;
35+
}
36+
37+
public void setTotal(Long total) {
38+
this.total = total;
39+
}
40+
}

src/main/java/com/boylegu/springboot_vue/dao/PersonsRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ public interface PersonsRepository extends JpaRepository<Persons, Long> {
1414

1515
@Query(FIND_SEX)
1616
List<Persons> findSex();
17+
1718
}

src/main/resources/application.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
debug=true
22
spring.output.ansi.enabled=DETECT
3+
server.port = 8000
34

45
# spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
56

0 commit comments

Comments
 (0)