假设我有跟随控制器。
@RestController()
@RequestMapping("/my/{path}")
public class MyController {
public void some1(@PathVariable("path") String path) {
}
public void some2(@PathVariable("path") String path) {
}
public void some3(@PathVariable("path") String path) {
}
}
现在我想将path
注入一个字段。
// I usually do this with JAX-RS
@RequestScope // I added this!
@RestController()
@RequestMapping("/my/{path}")
public class MyController {
public void some1() {
}
public void some2() {
}
public void some3() {
}
// single declaration for all methods
// I know ElementType.FIELD is not one of @PathVariable's target
// Is there any equivalent way to do this with Spring?
@PathVariable("path")
String path
}
不编译。
我该怎么做?
答案 0 :(得分:0)
请求网址:/ a / b / c
private String some;
@RequestMapping(value = "/a/{some}/c")
public void some(@PathVariable("some") String some) {
this.some = some;
}
答案 1 :(得分:-1)
@PathVariable Annotation,指示方法参数应绑定到URI模板变量。
示例:
<dd ng-bind-html="vm.model.PERSON_INFO | ageFilter"></dd>
&#13;
请参阅以下链接:
https://www.journaldev.com/3358/spring-requestmapping-requestparam-pathvariable-example