簡體   English   中英

@PathVariable Java Spring中的文本不完整

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM