Skip to content

Commit 15d4481

Browse files
committed
update comment
1 parent 9e2cb3c commit 15d4481

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

README.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,39 @@ public class App {
124124
@Bean
125125
RouterDefinition<Handler> routerDef() {
126126
return router -> router
127-
.get("/", (req, res) -> res.body("Sample")) // curl localhost:8080
128-
.get("/hello", (req, res) -> res.body("Hello World!")) // curl localhost:8080/hello
127+
/* curl localhost:8080 ==> Sample*/
128+
.get("/", (req, res) -> res.body("Sample"))
129+
/* curl localhost:8080/hello ==> Hello World! */
130+
.get("/hello", (req, res) -> res.body("Hello World!"))
131+
/* curl localhost:8080/json ==> {"name":"John","age":30} */
129132
.get("/json", (req, res) -> res
130133
.contentType(MediaType.APPLICATION_JSON)
131-
.body(new Person("John", 30))) // curl localhost:8080/json
134+
.body(new Person("John", 30)))
135+
/* curl localhost:8080/xml ==> <?xml version="1.0" encoding="UTF-8" standalone="yes"?><person><age>30</age><name>John</name></person> */
132136
.get("/xml", (req, res) -> res
133137
.contentType(MediaType.APPLICATION_XML)
134-
.body(new Person("John", 30))) // curl localhost:8080/xml
138+
.body(new Person("John", 30)))
139+
/* curl localhost:8080/template ==> [templates/hello.html will be rendered via Thymeleaf] */
135140
.get("/template", (req, res) -> {
136-
// curl localhost:8080/template
137141
req.put("message", "Hello World!");
138142
return res.view("hello");
139143
})
144+
/* curl localhost:8080/bar/aaa ==> foo = aaa */
140145
.get("/bar/{foo}", (req, res) ->
141-
// curl localhost:8080/bar/aaa
142146
res.body("foo = " + req.param("foo")
143147
.orElse("??")))
148+
/* curl localhost:8080/param -d name=John ==> Hi John */
144149
.post("/echo", (req, res) ->
145-
// curl localhost:8080/param -d name=John
146150
res.body(req.param("name")
147151
.map(name -> "Hi " + name)
148152
.orElse("Please input name!")))
153+
/* curl localhost:8080/param -d name=John -d age=30 ==> {"name":"John","age":30} */
149154
.post("/param", (req, res) -> {
150-
// curl localhost:8080/param -d name=John -d age=30
151155
Person person = req.params(Person.class);
152156
return res.body(person);
153157
})
158+
/* curl localhost:8080/body -H 'Content-Type: application/json' -d '{"name":"John","age":30}' ==> {"name":"John","age":30} */
154159
.post("/body", (req, res) -> {
155-
// curl localhost:8080/body -H 'Content-Type: application/json' -d '{"name":"John","age":30}'
156160
Person person = req.body(Person.class);
157161
return res.body(person);
158162
});

example/default/src/main/java/demo/App.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,39 @@ HandlerAdapter routerHandlerAdapter(RouterHandlerMapping<Handler> handlerMapping
3737
@Bean
3838
RouterDefinition<Handler> routerDef() {
3939
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} */
4245
.get("/json", (req, res) -> res
4346
.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> */
4549
.get("/xml", (req, res) -> res
4650
.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] */
4853
.get("/template", (req, res) -> {
49-
// curl localhost:8080/template
5054
req.put("message", "Hello World!");
5155
return res.view("hello");
5256
})
57+
/* curl localhost:8080/bar/aaa ==> foo = aaa */
5358
.get("/bar/{foo}", (req, res) ->
54-
// curl localhost:8080/bar/aaa
5559
res.body("foo = " + req.param("foo")
5660
.orElse("??")))
61+
/* curl localhost:8080/param -d name=John ==> Hi John */
5762
.post("/echo", (req, res) ->
58-
// curl localhost:8080/param -d name=John
5963
res.body(req.param("name")
6064
.map(name -> "Hi " + name)
6165
.orElse("Please input name!")))
66+
/* curl localhost:8080/param -d name=John -d age=30 ==> {"name":"John","age":30} */
6267
.post("/param", (req, res) -> {
63-
// curl localhost:8080/param -d name=John -d age=30
6468
Person person = req.params(Person.class);
6569
return res.body(person);
6670
})
71+
/* curl localhost:8080/body -H 'Content-Type: application/json' -d '{"name":"John","age":30}' ==> {"name":"John","age":30} */
6772
.post("/body", (req, res) -> {
68-
// curl localhost:8080/body -H 'Content-Type: application/json' -d '{"name":"John","age":30}'
6973
Person person = req.body(Person.class);
7074
return res.body(person);
7175
});

0 commit comments

Comments
 (0)