'How can I send me parameter to the front in Thymeleaf
I am trying to send my int x to the front, after clicking submit input, but it is giving me errors 404 not found.
Here is my Thymeleaf page with submit input:
<form th:action="@{/timetracking/compensatory/make-zero}" method="get">
<input type="submit" value="Submit" />
</form>
<p>Events<span th:text="${login}">Stopped events</span></p>
And my controller:
@RequestMapping(value = "/timetracking/compensatory/make-zero",method = RequestMethod.GET)
public Model home(Model model ) {
try {
int x = employeeEventRepository.setToZero();
model.addAttribute("login",x);
}
catch (Exception e){
System.out.println(e);
}
return model;
}
What I am doing wrong here, I have tried so many times, but my button is not working.
Solution 1:[1]
Problem is that your controller isn't returning a page.
If you want to post the same data to the same page, the example might look like this:
@RequestMapping(value = "/timetracking/compensatory/make-zero",
method = RequestMethod.GET)
public Model home(Model model) {
try {
int x = employeeEventRepository.setToZero();
model.addAttribute("login", x);
} catch (Exception e) {
System.out.println(e);
}
// Let's say "time-tracking.html" is your html file.
return "time-tracking.html";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
