Say I have controller with a method defined like this:
@RestController
@RequestMapping("/{user-id}/foo")
public class FooController {
@RequestMapping("bar")
public BarController someBarLogic() {
//
}
}
Is it possible to go further than {user-id}/foo/bar without specifying the whole root-path ? (Is there a way to relativize the path like @Path annotation in Jersey or an equivalent annotation in Spring-Boot ?)
It looks like you're looking for ant-style wildcards in path patterns. Have a look here:
Accordingly you can define a RequestMapping
like this
@RestController
@RequestMapping("/foo")
public class DemoController {
@RequestMapping(value = "/bar/**", method = RequestMethod.GET)
public String getDemo() {
return "Hello world!";
}
}
which will match /foo/bar/baz
.
Ok, another example based on your comment below:
@RestController
public class DemoController {
@RequestMapping(value = "/**/baz/**", method = RequestMethod.GET)
public String getDemo() {
return "Hello world!";
}
}
This will match the same url as above, and also /foo/bar/baz/bar/foo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.