SpringMVC:如何在函数中获取@RequestMapping的值 [英] SpringMVC: how to get the value of @RequestMapping in the function

查看:1284
本文介绍了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的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆