Skip to content

Commit aa942ef

Browse files
顾鲍尔顾鲍尔
authored andcommitted
close #17 finished detail api in spring
1 parent d38020d commit aa942ef

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.boylegu.springboot_vue.controller;
22

33
import com.boylegu.springboot_vue.entities.Persons;
4-
import org.springframework.beans.factory.annotation.Autowired;
4+
55
import org.springframework.web.bind.annotation.RequestMapping;
66
import org.springframework.web.bind.annotation.RequestMethod;
77
import org.springframework.web.bind.annotation.RequestParam;
88
import org.springframework.web.bind.annotation.RestController;
9+
import org.springframework.web.bind.annotation.PathVariable;
910
import org.springframework.beans.factory.annotation.Value;
11+
import org.springframework.beans.factory.annotation.Autowired;
1012
import org.springframework.http.ResponseEntity;
1113
import org.springframework.http.HttpStatus;
1214
import org.springframework.http.MediaType;
@@ -32,7 +34,7 @@ public class MainController {
3234
@Value(("${com.boylegu.paginatio.max-per-page}"))
3335
Integer maxPerPage;
3436

35-
@RequestMapping(value = "/sex", method = RequestMethod.GET)
37+
@RequestMapping(value = "/sex", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
3638
public ResponseEntity<?> getSexAll() {
3739

3840
/*
@@ -116,4 +118,32 @@ public Map<String, PaginationMultiTypeValuesHelper> getPersonsAll(
116118
return paginInstance.filterQuery(sex, email, pageable);
117119
}
118120

121+
@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
122+
public ResponseEntity<Persons> getUser(@PathVariable Long id) {
123+
124+
/*
125+
* @api {GET} /api/persons/detail/:id details info
126+
* @apiName GetPersonDetails
127+
* @apiGroup Info Manage
128+
* @apiVersion 1.0.0
129+
*
130+
* @apiExample {httpie} Example usage:
131+
*
132+
* http /api/persons/detail/1
133+
*
134+
* @apiSuccess {String} email
135+
* @apiSuccess {String} id
136+
* @apiSuccess {String} phone
137+
* @apiSuccess {String} sex
138+
* @apiSuccess {String} username
139+
* @apiSuccess {String} zone
140+
*/
141+
142+
143+
Persons user = personsRepository.findById(id);
144+
145+
return new ResponseEntity<>(user, HttpStatus.OK);
146+
}
147+
148+
119149
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.springframework.web.bind.annotation.RequestParam;
1111

1212
import java.util.List;
13+
import java.util.Map;
1314

1415

1516
public interface PersonsRepository extends JpaRepository<Persons, Long> {
@@ -25,4 +26,6 @@ public interface PersonsRepository extends JpaRepository<Persons, Long> {
2526

2627
Page<Persons> findBySex(String sexName, Pageable pageable);
2728

29+
Persons findById(Long id);
30+
2831
}

0 commit comments

Comments
 (0)