spring mvc中的@PathVariable

来源:互联网 发布:node需要nginx吗 编辑:程序博客网 时间:2024/05/22 07:01

 spring mvc中的@PathVariable是用来获得请求url中的动态参数的,十分方便


下面举个例子来解释:(代码片段)~

@RequestMapping(value = "/get/{bodyIndexId}")
    public String get(HttpServletRequest request,
            HttpServletResponse response, @PathVariable int bodyIndexId) {
        BodyIndexDO bodyIndex = bodyIndexService.getById(bodyIndexId);
        return "Hello~~~";
    }


传入的bodyIndexId,是一个动态参数,所以用 @PathVariable 接受参数之后下面的方法就可以直接调用了,非常方便的~

0 0
原创粉丝点击