本文介绍了SpringMVC:如何在函数中获取@RequestMapping的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个课程如下:
@Controller
@RequestMapping("/path1")
public class MyController
{
@RequestMapping(value = "/path2", method = RequestMethod.GET)
public ModelAndView func(ModelAndView mav)
{
String path = getRequestMappingValue(); // Here I expect a function which returns "/path1/path2"
mav.setViewName(path + ".jsp");
return mav;
}
}
我需要的是函数getRequestMappingValue(),返回注释@RequestMapping的值(在这种情况下,它是/ path1 / path2)
What I require is the function getRequestMappingValue(), which returns the value of annotation @RequestMapping (in this case, it is "/path1/path2")
推荐答案
这不是解决方案实现了您所需要的功能?
Doesn't this solution here achieve pretty much what you're looking for?
private final static String MAPPING = "/hello";
@RequestMapping(value = MAPPING)
@ResponseBody
public void helloMethod(AtmosphereResource atmosphereResource) {
// MAPPING accessible as it's stored in instance variable
}
这篇关于SpringMVC:如何在函数中获取@RequestMapping的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!