[英]Incomplete text from @PathVariable Java Spring
I'm trying to send an ID to my controller using: 我正在尝试使用以下方式将ID发送给我的控制器:
<a href="/host/admin/sensor/downloadCSV/${sensor.id}" class="btn btn-primary"> Export CSV</a>
The content of ${sensor.id}
variable is: testApp_provider.osom_component2.RT3
${sensor.id}
testApp_provider.osom_component2.RT3
${sensor.id}
变量的内容为: testApp_provider.osom_component2.RT3
In my controller I'm getting it with: 在我的控制器中,我得到了:
@RequestMapping("/downloadCSV/{sensorId}")
public ModelAndView handleRequestInternal(HttpServletResponse response, @PathVariable final String sensorId) throws IOException {
System.out.println("sensor:"+sensorId);
return null;
}
But the output of the println
is: 但是
println
的输出是:
sensor:testApp_provider.osom_component2
I'm losing the last part: .RT3
我丢失了最后一部分:
.RT3
Any Ideas? 有任何想法吗?
You need to change it to, 您需要将其更改为
@RequestMapping("/downloadCSV/{sensorId:.+}")
public ModelAndView handleRequestInternal(HttpServletResponse response, @PathVariable final String sensorId) throws IOException {
System.out.println("sensor:"+sensorId);
return null;
}
As everything behind the last dot is a file extension for Spring, so it truncates it by default. 由于最后一个点后面的所有内容都是Spring的文件扩展名,因此默认情况下会将其截断。
The other, global solution would be to set useRegisteredSuffixPatternMatch
property to false
when registering the RequestMappingHandlerMapping
. 另一种全局解决方案是在注册
RequestMappingHandlerMapping
时将useRegisteredSuffixPatternMatch
属性设置为false
。
More cleaner way however is to add trailing /
slash at the end 但是,更干净的方法是在末尾添加尾随
/
斜杠
@RequestMapping("/downloadCSV/{sensorId}/")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.