1

This is my controller mapping, I need to print all the properties of the list objects in my view.

@RequestMapping(value = "/get" , method = RequestMethod.GET)
@ModelAttribute("todolist")
public List<Todo> getuser() {
    return  (List<Todo>) todoRepository.findAll();
}

This is my View, and a link to my GitHub project.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en">
    <head>
    </head>
<body>
<table>
    <tr th:each="message : ${todolist}">
        <td th:text="${todolist.title}">Title</td>
        <td th:text="${todolist.description}">Description</td>
    </tr>
</table>
</body>
</html>

1 Answer 1

2

You need to use message instead of todolist

<tr th:each="message : ${todolist}">
    <td th:text="${message.title}">Title</td>
    <td th:text="${message.description}">Description</td>
</tr>

Because th:each will iterate through the list of todolist and puts the value inside message property. Means message is your variable name for one element of the list. Would be better to call it todo for example.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the response sorry i forgot it..but still the html renders as blank page with only Title and Description in it.
@NarenViswanath you need to give more information in your question what are u doing and whats works and whats not. And your github source looks quite ok for this controller?!?! TodoController
I'm trying to get data from mysql and render it in my HTML view. I fetched it as object list and got stuck here. I don't know how to send these objects to my view for printing it. I can submit the data from html to database from the same controller. The controller works well. New to Stack overflow sorry :P.
@NarenViswanath Show your full controller class please

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.