@@ -37,35 +37,39 @@ HandlerAdapter routerHandlerAdapter(RouterHandlerMapping<Handler> handlerMapping
37
37
@ Bean
38
38
RouterDefinition <Handler > routerDef () {
39
39
return router -> router
40
- .get ("/" , (req , res ) -> res .body ("Sample" )) // curl localhost:8080
41
- .get ("/hello" , (req , res ) -> res .body ("Hello World!" )) // curl localhost:8080/hello
40
+ /* curl localhost:8080 ==> Sample*/
41
+ .get ("/" , (req , res ) -> res .body ("Sample" ))
42
+ /* curl localhost:8080/hello ==> Hello World! */
43
+ .get ("/hello" , (req , res ) -> res .body ("Hello World!" ))
44
+ /* curl localhost:8080/json ==> {"name":"John","age":30} */
42
45
.get ("/json" , (req , res ) -> res
43
46
.contentType (MediaType .APPLICATION_JSON )
44
- .body (new Person ("John" , 30 ))) // curl localhost:8080/json
47
+ .body (new Person ("John" , 30 )))
48
+ /* curl localhost:8080/xml ==> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><person><age>30</age><name>John</name></person> */
45
49
.get ("/xml" , (req , res ) -> res
46
50
.contentType (MediaType .APPLICATION_XML )
47
- .body (new Person ("John" , 30 ))) // curl localhost:8080/xml
51
+ .body (new Person ("John" , 30 )))
52
+ /* curl localhost:8080/template ==> [templates/hello.html will be rendered via Thymeleaf] */
48
53
.get ("/template" , (req , res ) -> {
49
- // curl localhost:8080/template
50
54
req .put ("message" , "Hello World!" );
51
55
return res .view ("hello" );
52
56
})
57
+ /* curl localhost:8080/bar/aaa ==> foo = aaa */
53
58
.get ("/bar/{foo}" , (req , res ) ->
54
- // curl localhost:8080/bar/aaa
55
59
res .body ("foo = " + req .param ("foo" )
56
60
.orElse ("??" )))
61
+ /* curl localhost:8080/param -d name=John ==> Hi John */
57
62
.post ("/echo" , (req , res ) ->
58
- // curl localhost:8080/param -d name=John
59
63
res .body (req .param ("name" )
60
64
.map (name -> "Hi " + name )
61
65
.orElse ("Please input name!" )))
66
+ /* curl localhost:8080/param -d name=John -d age=30 ==> {"name":"John","age":30} */
62
67
.post ("/param" , (req , res ) -> {
63
- // curl localhost:8080/param -d name=John -d age=30
64
68
Person person = req .params (Person .class );
65
69
return res .body (person );
66
70
})
71
+ /* curl localhost:8080/body -H 'Content-Type: application/json' -d '{"name":"John","age":30}' ==> {"name":"John","age":30} */
67
72
.post ("/body" , (req , res ) -> {
68
- // curl localhost:8080/body -H 'Content-Type: application/json' -d '{"name":"John","age":30}'
69
73
Person person = req .body (Person .class );
70
74
return res .body (person );
71
75
});
0 commit comments