Skip to content

Commit 33f6d94

Browse files
authored
Merge pull request boylegu#20 from boylegu/issue/19/update_api
close boylegu#19 finished update api in spring boot
2 parents eda5e6f + 2d55b94 commit 33f6d94

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

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

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.springframework.web.bind.annotation.RequestMapping;
66
import org.springframework.web.bind.annotation.RequestMethod;
77
import org.springframework.web.bind.annotation.RequestParam;
8+
import org.springframework.web.bind.annotation.RequestBody;
89
import org.springframework.web.bind.annotation.RestController;
910
import org.springframework.web.bind.annotation.PathVariable;
1011
import org.springframework.beans.factory.annotation.Value;
@@ -17,8 +18,8 @@
1718
import org.springframework.data.domain.Sort.Direction;
1819
import org.springframework.data.domain.PageRequest;
1920

20-
import com.boylegu.springboot_vue.controller.pagination.PaginationMultiTypeValuesHelper;
2121
import com.boylegu.springboot_vue.dao.PersonsRepository;
22+
import com.boylegu.springboot_vue.controller.pagination.PaginationMultiTypeValuesHelper;
2223
import com.boylegu.springboot_vue.controller.pagination.PaginationFormatting;
2324

2425
import java.util.*;
@@ -43,8 +44,9 @@ public ResponseEntity<?> getSexAll() {
4344
* @apiGroup Info Manage
4445
* @apiVersion 1.0.0
4546
* @apiExample {httpie} Example usage:
46-
* <p>
47-
* http /api/persons/sex
47+
*
48+
* http /api/persons/sex
49+
*
4850
* @apiSuccess {String} label
4951
* @apiSuccess {String} value
5052
*/
@@ -91,8 +93,8 @@ public Map<String, PaginationMultiTypeValuesHelper> getPersonsAll(
9193
* http /api/persons?sex=xxx
9294
* http /api/persons?email=xx
9395
*
94-
* @apiParam {String} sex
95-
* @apiParam {String} email
96+
* @apiParam {String} sex
97+
* @apiParam {String} email
9698
*
9799
* @apiSuccess {String} create_datetime
98100
* @apiSuccess {String} email
@@ -119,7 +121,7 @@ public Map<String, PaginationMultiTypeValuesHelper> getPersonsAll(
119121
}
120122

121123
@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
122-
public ResponseEntity<Persons> getUser(@PathVariable Long id) {
124+
public ResponseEntity<Persons> getUserDetail(@PathVariable Long id) {
123125

124126
/*
125127
* @api {GET} /api/persons/detail/:id details info
@@ -129,7 +131,8 @@ public ResponseEntity<Persons> getUser(@PathVariable Long id) {
129131
*
130132
* @apiExample {httpie} Example usage:
131133
*
132-
* http /api/persons/detail/1
134+
* @apiParam {String} sex
135+
* @apiParam {String} email
133136
*
134137
* @apiSuccess {String} email
135138
* @apiSuccess {String} id
@@ -145,5 +148,34 @@ public ResponseEntity<Persons> getUser(@PathVariable Long id) {
145148
return new ResponseEntity<>(user, HttpStatus.OK);
146149
}
147150

151+
@RequestMapping(value = "/detail/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
152+
public Persons updateUser(@PathVariable Long id, @RequestBody Persons data) {
153+
154+
/*
155+
* @api {PUT} /api/persons/detail/:id update person info
156+
* @apiName PutPersonDetails
157+
* @apiGroup Info Manage
158+
* @apiVersion 1.0.0
159+
*
160+
* @apiParam {String} phone
161+
* @apiParam {String} zone
162+
*
163+
* @apiSuccess {String} create_datetime
164+
* @apiSuccess {String} email
165+
* @apiSuccess {String} id
166+
* @apiSuccess {String} phone
167+
* @apiSuccess {String} sex
168+
* @apiSuccess {String} username
169+
* @apiSuccess {String} zone
170+
171+
*/
172+
Persons user = personsRepository.findById(id);
173+
174+
user.setPhone(data.getPhone());
175+
176+
user.setZone(data.getZone());
177+
178+
return personsRepository.save(user);
179+
}
148180

149181
}

0 commit comments

Comments
 (0)