Im trying to do a call to my REST service to create a supplier. I need the itemCode of the supplied item and the username that wants to create it. Right now, im call it like this:
th:href="@{/api/supplier/getSupplierViewItem/{username}(username = ${username})/{itemCode}(itemCode = ${item.itemCode})}
Then, my controller should get that petition:
@GetMapping("/getSupplierViewItem/{username:. }/{itemCode:. }")
public String getSupplierViewwithItem(@PathVariable("username")String username, @PathVariable("itemCode") String itemCode, ModelMap model){
model.addAttribute("username", username);
model.addAttribute("itemCode", itemCode);
return "createSupplier";
}
However, when I try it, I get this following petition:
http://localhost:8080/api/supplier/getSupplierViewItem/{username}(username = ${username})/01231
Basically, instead of the value of username, I´m getting
{username}(username = ${username})
Which is the best way to send both parameters?
CodePudding user response:
The correct syntax for your url is:
th:href="@{/api/supplier/getSupplierViewItem/{username}/{itemCode}(username=${username},itemCode=${item.itemCode})}"
See the standard url syntax for multiple parameters.
CodePudding user response:
Change
@GetMapping("/getSupplierViewItem/{username:. }/{itemCode:. }")
To
@GetMapping("/getSupplierViewItem/{username}/{itemCode}")
You can not insert whitespace in th:href
because it is url if you give whitespace it produce ASCII code for special character and space.
th:href="@{/api/supplier/getSupplierViewItem/{username}(username=${username})/{itemCode}(itemCode=${item.itemCode})}