[英]Incomplete text from @PathVariable Java Spring
我正在尝试使用以下方式将ID发送给我的控制器:
<a href="/host/admin/sensor/downloadCSV/${sensor.id}" class="btn btn-primary"> Export CSV</a>
${sensor.id}
testApp_provider.osom_component2.RT3
${sensor.id}
变量的内容为: testApp_provider.osom_component2.RT3
在我的控制器中,我得到了:
@RequestMapping("/downloadCSV/{sensorId}")
public ModelAndView handleRequestInternal(HttpServletResponse response, @PathVariable final String sensorId) throws IOException {
System.out.println("sensor:"+sensorId);
return null;
}
但是println
的输出是:
sensor:testApp_provider.osom_component2
我丢失了最后一部分: .RT3
有任何想法吗?
您需要将其更改为
@RequestMapping("/downloadCSV/{sensorId:.+}")
public ModelAndView handleRequestInternal(HttpServletResponse response, @PathVariable final String sensorId) throws IOException {
System.out.println("sensor:"+sensorId);
return null;
}
由于最后一个点后面的所有内容都是Spring的文件扩展名,因此默认情况下会将其截断。
另一种全局解决方案是在注册RequestMappingHandlerMapping
时将useRegisteredSuffixPatternMatch
属性设置为false
。
但是,更干净的方法是在末尾添加尾随/
斜杠
@RequestMapping("/downloadCSV/{sensorId}/")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.