Spring Boot:路径参数为空

时间:2019-07-11 10:06:31

标签: spring spring-boot

我已经编码了该控制器方法的实现:

@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

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您缺少@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
}