I am trying to implement Spring boot MVC application with rest and Thymeleaf. In my controller class I have something like below:
@RestController
public class UserController {
@Autowired
private GetUserInfoSrv userSrv;;
@RequestMapping("/") **OR** @GetMapping
public String getAllUsers(Model model) {
List<UserRep> listUser = userSrv.getAllUsersSvc(); //this is returning correct output
model.addAttribute("userList", listUser);
return "Index";
}
I am not getting the values populated in Index.html
:
<tbody>
<tr th:each="users : ${userList}">
<td th:text="${users.id}" />
<td th:text="${users.firstName}">First Name</td>
<td th:text="${users.lastName}">Last Name</td>
<td th:text="${users.email}">Email Id</td>
</td> -->
</tr>
</tbody>
If I use @Controller
annotation instead of @RestController
, I am able to view the results on page. Any reason why @RestController
does not work? I tried adding @RequestMapping
/ @GetMapping
at class level as well as method level in @RestController
but nothing works.