Skip to content

Commit e498772

Browse files
authored
Merge pull request boylegu#15 from boylegu/issue/13/filter_in_spring
Issue/13/filter in spring
2 parents a76b8be + 30460a6 commit e498772

File tree

11 files changed

+346
-45
lines changed

11 files changed

+346
-45
lines changed

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ dist/
2323
nbdist/
2424
.nb-gradle/
2525

26-
# images
27-
*.lpop
26+
## images
27+
*.lpop
28+
29+
## NodeJS
30+
node_modules

frontend/src/components/DbFooter.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
export default {
3333
data(){
3434
return {
35-
message: 'SanicCRUD-Vue.js v0.1',
35+
message: 'SpringBoot-Vue.js v0.1',
3636
}
3737
},
3838
mounted (){

frontend/src/components/DbHeader.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
name: 'db-header',
1313
data () {
1414
return {
15-
msg: 'SanicCRUD-vue'
15+
msg: 'SpringBoot-vue'
1616
}
1717
}
1818
}

frontend/src/components/DbTable.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@
106106
email: this.email
107107
}
108108
}).then((response) => {
109-
this.tableData = response.data.results;
110-
this.total = response.data.total;
111-
this.pageSize = response.data.count;
112-
console.log(response.data);
109+
this.tableData = response.data.data.results;
110+
this.total = response.data.data.total;
111+
this.pageSize = response.data.data.count;
112+
console.log(response.data.data);
113113
}).catch(function (response) {
114114
console.log(response)
115115
});

src/main/java/com/boylegu/springboot_vue/App.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package com.boylegu.springboot_vue;
2-
2+
import org.springframework.context.annotation.Configuration;
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55

66

7+
@Configuration
78
@SpringBootApplication
89
public class App {
910

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package com.boylegu.springboot_vue.controller;
22

3+
import com.boylegu.springboot_vue.entities.Persons;
4+
import org.springframework.beans.factory.annotation.Autowired;
35
import org.springframework.web.bind.annotation.RequestMapping;
46
import org.springframework.web.bind.annotation.RequestMethod;
7+
import org.springframework.web.bind.annotation.RequestParam;
58
import org.springframework.web.bind.annotation.RestController;
9+
import org.springframework.beans.factory.annotation.Value;
610
import org.springframework.http.ResponseEntity;
711
import org.springframework.http.HttpStatus;
8-
import org.springframework.beans.factory.annotation.Autowired;
12+
import org.springframework.http.MediaType;
913
import org.springframework.data.domain.Pageable;
1014
import org.springframework.data.domain.Sort;
1115
import org.springframework.data.domain.Sort.Direction;
1216
import org.springframework.data.domain.PageRequest;
1317

1418
import com.boylegu.springboot_vue.controller.pagination.PaginationMultiTypeValuesHelper;
1519
import com.boylegu.springboot_vue.dao.PersonsRepository;
20+
import com.boylegu.springboot_vue.controller.pagination.PaginationFormatting;
1621

1722
import java.util.*;
1823

@@ -21,60 +26,94 @@
2126
@RequestMapping("/api/persons")
2227
public class MainController {
2328

24-
/**
25-
* @api {GET} /api/persons/sex Get all sexList
26-
* @apiName GetAllSexList
27-
* @apiGroup Info Manage
28-
* @apiVersion 1.0.0
29-
* @apiExample {httpie} Example usage:
30-
* <p>
31-
* http /api/persons/sex
32-
* @apiSuccess {String} label
33-
* @apiSuccess {String} value
34-
*/
35-
3629
@Autowired
3730
private PersonsRepository personsRepository;
3831

32+
@Value(("${com.boylegu.paginatio.max-per-page}"))
33+
Integer maxPerPage;
34+
3935
@RequestMapping(value = "/sex", method = RequestMethod.GET)
4036
public ResponseEntity<?> getSexAll() {
4137

38+
/*
39+
* @api {GET} /api/persons/sex Get all sexList
40+
* @apiName GetAllSexList
41+
* @apiGroup Info Manage
42+
* @apiVersion 1.0.0
43+
* @apiExample {httpie} Example usage:
44+
* <p>
45+
* http /api/persons/sex
46+
* @apiSuccess {String} label
47+
* @apiSuccess {String} value
48+
*/
49+
4250
ArrayList<Map<String, String>> results = new ArrayList<>();
4351

4452
for (Object value : personsRepository.findSex()) {
53+
4554
Map<String, String> sex = new HashMap<>();
4655

4756
sex.put("label", value.toString());
57+
4858
sex.put("value", value.toString());
59+
4960
results.add(sex);
5061
}
62+
5163
ResponseEntity<ArrayList<Map<String, String>>> responseEntity = new ResponseEntity<>(results,
5264
HttpStatus.OK);
65+
5366
return responseEntity;
5467
}
5568

56-
@RequestMapping(value = "/", method = RequestMethod.GET)
57-
public Map<String, PaginationMultiTypeValuesHelper> getPersonsAll() {
69+
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
70+
public Map<String, PaginationMultiTypeValuesHelper> getPersonsAll(
71+
@RequestParam(value = "page", required = false) Integer pages,
72+
@RequestParam("sex") String sex,
73+
@RequestParam("email") String email
74+
) {
75+
76+
/*
77+
* @api {GET} /api/persons Get all or a part of person info
78+
* @apiName GetAllInfoList
79+
* @apiGroup Info Manage
80+
* @apiVersion 1.0.0
81+
*
82+
* @apiExample {httpie} Example usage: (support combinatorial search)
83+
*
84+
* All person:
85+
* http /api/persons
86+
*
87+
* You can according to 'sex | email' or 'sex & email'
88+
* http /api/persons?sex=xxx&email=xx
89+
* http /api/persons?sex=xxx
90+
* http /api/persons?email=xx
91+
*
92+
* @apiParam {String} sex
93+
* @apiParam {String} email
94+
*
95+
* @apiSuccess {String} create_datetime
96+
* @apiSuccess {String} email
97+
* @apiSuccess {String} id
98+
* @apiSuccess {String} phone
99+
* @apiSuccess {String} sex
100+
* @apiSuccess {String} username
101+
* @apiSuccess {String} zone
102+
*/
103+
104+
if (pages == null) {
105+
106+
pages = 1;
58107

59-
int page = 1, size = 5;
60-
Sort sort = new Sort(Direction.ASC, "id");
61-
Pageable pageable = new PageRequest(page, size, sort);
108+
}
62109

63-
PaginationMultiTypeValuesHelper multiValue = new PaginationMultiTypeValuesHelper();
64-
Map<String, PaginationMultiTypeValuesHelper> results = new HashMap<>();
110+
Sort sort = new Sort(Direction.ASC, "id");
65111

66-
Integer count = personsRepository.findAll(pageable).getSize();
67-
Integer page_number = personsRepository.findAll(pageable).getNumber();
112+
Pageable pageable = new PageRequest(pages - 1, maxPerPage, sort);
68113

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);
114+
PaginationFormatting paginInstance = new PaginationFormatting();
75115

76-
results.put("data", multiValue);
77-
return results;
116+
return paginInstance.filterQuery(sex, email, pageable);
78117
}
79118

80119
}

src/main/java/com/boylegu/springboot_vue/controller/pagination/Pagination.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)