i am trying to send multiple values from anchor tag of thymleaf to controller. I am not sure how to send multiple values and to accept it in the ModelAttribute as object
thymleaf code:
<a th:href="@{/frontView(id1=${1})(id2=${2})}">Home</a>
controller:
@GetMapping("/frontView")
public void FrontView(@ModelAttribute Model m) {
}
error:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
CodePudding user response:
First, you are sending 2 values from the anchor tag in the wrong way do something like
<a th:href="@{/frontView/(id1=${1},id2=${2})}">home</a>
Or
for Path varibales
<a th:href="@{/frontView/{id1}/{id2} (id1=${1},id2=${2})}">home</a>
Then change your controller. Remove @ModelAttribute as it take an object and you are sending 2 values hence use @RequestParam or @PathVariable
@GetMapping("/frontView")
public void FrontView(@RequestParam("id1")int id1,@RequestParam("id2")int id2) {
}