Reputation: 1986
I have a problem with Spring and Thymeleaf.
I have a controller:
@RequestMapping(value = "/add")
public String addPage(@PathVariable("id") String id, Model model) {
InvoiceData invoiceData = new InvoiceData();
model.addAttribute("contractorid", id);
model.addAttribute("invoicedata", invoiceData);
return "add";
}
And I have an URI:
<li class="menu"><a th:href="@{/add/{id}(id=${contractor.id})}">Add invoice</a>
and of course, I have this add.html
document containing a form to fill and save data to ContractorData
.
But when I click the link, I get:
There was an unexpected error (type=Not Found, status=404).
No message available
And the URL in the browser looks like this:
http://localhost:8080/add/5c9e31b05b9b380a6b08dc94
So it is completely basing on the basic URI
How do I modify the URI or my code so I can pass the contractor.id
to the /add controller and put it into Model
so it will be available for me to use in add.html?
Upvotes: 0
Views: 760
Reputation: 1981
It should help, i think.
@RequestMapping(value = "/add/{id}")
public String addPage(@PathVariable("id") String id, Model model) {
InvoiceData invoiceData = new InvoiceData();
model.addAttribute("contractorid", id);
model.addAttribute("invoicedata", invoiceData);
return "add";
}
Upvotes: 1