一耙饰、問題
項目使用SpringBoot時,使用 注解接收參數,前端頁面?zhèn)鬟f參數值為100.01,但是后臺接收參數為100,而且通過request去獲取url時就是100.01 ,所以懷疑是該注解注入值導致的,通過網上找了一些資料,發(fā)現了解決辦法
后臺接收的參數
Controller:
@RequestMapping("/toUpper/{amount}")
@ResponseBody
publicStringtoUpper(@PathVariable("amount")String amount){
}
二症汹、解決方案
1.在version段后增加一個靜態(tài)的字符段塑崖,這個段沒有任何意義,可以為任意字符惹苗。
URL:
http://localhost:8070/amount/toUpper/100/suibianjia?t=1517391101418
代碼
@RequestMapping("/toUpper/{amount}/suibianjia")
@ResponseBody
publicStringtoUpper(@PathVariable("amount")String amount){
問題雖然解決了殿较,但畢竟URL后多了個小尾巴,心情不愉悅桩蓉。
再次谷哥淋纲。
參考:
http://stackoverflow.com/questions/3526523/spring-mvc-pathvariable-getting-truncated
2.在@RequestMapping的value中使用SpEL來表示,value中的{amount}換成{amount:.+}院究。
@RequestMapping("/toUpper/{amount:.+}")
@ResponseBody
publicStringtoUpper(@PathVariable("amount")String amount){
}