Mic*_*tum 11 java spring spring-mvc
我有一个这样的弹簧控制器/ POJO:
@RequestMapping("/foo");
public class MyController {
@RequestMapping("/bar")
public String MyAction() { return someSharedFunc(false); }
@RequestMapping("/debug/ping");
public String MyDebugPing() { return someSharedFunc(true); }
private String someSharedFunc(boolean debug) {
if(debug) return "FooBar"; else return "Debug!";
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,MyDebugPing的URL是/foo/debug/ping
.但是,我希望它/debug/ping
有效地忽略了类上的RequestMapping.
那可能吗?
只需@RequestMapping
从类中删除注释,并使用每个方法的完整路径.例如
public class MyController {
@RequestMapping("/foo/bar")
public String MyAction() { return someSharedFunc(false); }
@RequestMapping("/debug/ping");
public String MyDebugPing() { return someSharedFunc(true); }
private String someSharedFunc(boolean debug) {
if(debug) return "FooBar"; else return "Debug!";
}
}
Run Code Online (Sandbox Code Playgroud)
如果有很多方法,那么您可以简单地将方法移出到另一个控制器.
归档时间: |
|
查看次数: |
4527 次 |
最近记录: |