首页 > 解决方案 > 春季启动:路径参数为空

问题描述

我已经编写了这个控制器方法实现:

@RequestMapping(
    value = "/userlogin4download/{id}",
    method = RequestMethod.GET
)
@Override
public void downloadAfterGicar(
    HttpServletRequest request,
    HttpServletResponse response,
    String id
) throws IOException {

    LOG.info("Requested URI: " + request.getRequestURI());
    LOG.info("{id} path param: " + id);

    // other code
}

达到了这个方法。尽管如此,日志:

Requested URI: /userlogin4download/cpd1-dc598036-f615-4200-b685-d24831fb9343
{id} path param: null

如您所见,id路径参数是null.

有任何想法吗?

标签: springspring-boot

解决方案


你不见了@PathVariable

@RequestMapping(value = "/userlogin4download/{id}", method = RequestMethod.GET)
@Override
public void downloadAfterGicar(HttpServletRequest request, 
                               HttpServletResponse response,
                               @PathVariable("id") String id) throws IOException {

    LOG.info("Requested URI: " + request.getRequestURI());
    LOG.info("{id} path param: " + id);

    // other code
}

推荐阅读