minor mapping work
This commit is contained in:
parent
b7d6a5377a
commit
0f71d7d2b8
|
@ -1,6 +1,7 @@
|
|||
package org.baeldung.spring.web.controller;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
@ -34,4 +35,12 @@ public class BarController {
|
|||
return "Get a specific Bar with id=" + id;
|
||||
}
|
||||
|
||||
// with @PathVariable
|
||||
|
||||
@RequestMapping(value = "/bars/{numericId:[\\d]+}")
|
||||
@ResponseBody
|
||||
public String getBarsBySimplePathWithPathVariable(@PathVariable final long numericId) {
|
||||
return "Get a specific Bar with id=" + numericId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,20 +23,20 @@ public class FooController {
|
|||
return "Simple Get some Foos";
|
||||
}
|
||||
|
||||
// @RequestMapping(value = "/foos")
|
||||
// @ResponseBody
|
||||
// public String getFoosByAdvancedPath() {
|
||||
// return "Advanced Get some Foos";
|
||||
// }
|
||||
|
||||
// with @PathVariable
|
||||
|
||||
@RequestMapping(value = "/foos/{id}")
|
||||
@ResponseBody
|
||||
public String getFoosBySimplePathWithPathVariable(@PathVariable("id") final long id) {
|
||||
public String getFoosBySimplePathWithPathVariable(@PathVariable final long id) {
|
||||
return "Get a specific Foo with id=" + id;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/foos/{fooid}/bar/{barid}")
|
||||
@ResponseBody
|
||||
public String getFoosBySimplePathWithPathVariables(@PathVariable final long fooid, @PathVariable final long barid) {
|
||||
return "Get a specific Bar with id=" + barid + " from a Foo with id=" + fooid;
|
||||
}
|
||||
|
||||
// other HTTP verbs
|
||||
|
||||
@RequestMapping(value = "/foos", method = RequestMethod.POST)
|
||||
|
@ -59,6 +59,12 @@ public class FooController {
|
|||
return "Get some Foos with Header";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/foos", produces = { "application/json", "application/xml" })
|
||||
@ResponseBody
|
||||
public String getFoosAsJsonFromREST() {
|
||||
return "Get some Foos with Header Exact";
|
||||
}
|
||||
|
||||
// advanced - multiple mappings
|
||||
|
||||
@RequestMapping(value = { "/advanced/bars", "/advanced/foos" })
|
||||
|
@ -79,4 +85,10 @@ public class FooController {
|
|||
return "Fallback for All Requests";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/foos/multiple", method = { RequestMethod.PUT, RequestMethod.POST })
|
||||
@ResponseBody
|
||||
public String putAndPostFoos() {
|
||||
return "Advanced - PUT and POST within single method";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue