spring - 春季启动:路径参数为空
问题描述
我已经编写了这个控制器方法实现:
@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
.
有任何想法吗?
解决方案
你不见了@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
}
推荐阅读
- linux - 补丁错误:在为 ubuntu 安装 RT Linux 补丁期间
- r - 使用 R 和 JAGS(以及 rjags)进行版本控制
- javascript - Chrome webview 停止加载 HTML
- angular - Angular - 访问 MatMenu 的 elementRef
- vb.net - 当vb net和sql Server中没有更多行时如何调整行
- libraries - 在 Dymola 中使用脚本 API 库
- entity-framework - ReferentialConstraint 中的依赖属性映射到存储生成的列。列:'DocumentId'
- prestashop - SMARTY:变量内的变量
- selenium - Selenium 的 Web 自动化最终会因“无活动会话”而崩溃
- linux - 使用 LFTP 访问 SFTP 服务器时出现问题