File tree Expand file tree Collapse file tree
guest/spring-mvc/src/main/java/com/forketyfork/guest/springmvc/web Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44import org .springframework .stereotype .Controller ;
55import org .springframework .web .bind .annotation .GetMapping ;
66import org .springframework .web .bind .annotation .PostMapping ;
7+ import org .springframework .web .bind .annotation .RequestBody ;
8+ import org .springframework .web .bind .annotation .ResponseBody ;
79import org .springframework .web .servlet .ModelAndView ;
810
911import java .util .Collections ;
@@ -28,4 +30,10 @@ public ModelAndView login(LoginData loginData) {
2830 }
2931 }
3032
33+ @ ResponseBody
34+ @ PostMapping ("/message" )
35+ public MyOutputResource sendMessage (@ RequestBody MyInputResource inputResource ) {
36+ return new MyOutputResource ("Received: " + inputResource .getRequestMessage ());
37+ }
38+
3139}
Original file line number Diff line number Diff line change 1+ package com .forketyfork .guest .springmvc .web ;
2+
3+ public class MyInputResource {
4+
5+ private String requestMessage ;
6+
7+ public String getRequestMessage () {
8+ return requestMessage ;
9+ }
10+
11+ public void setRequestMessage (String requestMessage ) {
12+ this .requestMessage = requestMessage ;
13+ }
14+ }
Original file line number Diff line number Diff line change 1+ package com .forketyfork .guest .springmvc .web ;
2+
3+ public class MyOutputResource {
4+
5+ private String responseMessage ;
6+
7+ public MyOutputResource (String responseMessage ) {
8+ this .responseMessage = responseMessage ;
9+ }
10+
11+ public String getResponseMessage () {
12+ return responseMessage ;
13+ }
14+
15+ }
Original file line number Diff line number Diff line change 1+ package com .forketyfork .guest .springmvc .web ;
2+
3+ import org .springframework .web .bind .annotation .GetMapping ;
4+ import org .springframework .web .bind .annotation .RestController ;
5+
6+ @ RestController
7+ public class RestfulWebServiceController {
8+
9+ @ GetMapping ("/message" )
10+ public MyOutputResource getMessage () {
11+ return new MyOutputResource ("Hello!" );
12+ }
13+
14+ }
You can’t perform that action at this time.
0 commit comments