Answer the question
In order to leave comments, you need to log in
How to get records from related table in thymeleaf?
Hello!
I deduce the table with the data from one table and with it of problems it is not observed. But this Entity is connected to another using @ManyToMany, so there is an additional one. table with additional data. How can I access this table from thymeleaf?
@Entity
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long taskId;
@ManyToMany
@JoinTable(name="task_authors",
joinColumns = @JoinColumn(name="task_id", referencedColumnName="taskId"),
inverseJoinColumns = @JoinColumn(name="user_id", referencedColumnName="user_id")
)
private List<User> userList = new ArrayList<>();
}
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long user_id;
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "userList")
private List<Task> taskList = new ArrayList<>();
}
<tr th:each="task : ${tasks}">
<td th:text="${task.taskId}">${task.taskId}</td>
<!-- здесь нужно вывести данные из таблицы task_authors (ManyToMany)-->
</tr>
${tasks}
nestedList<Task>
Answer the question
In order to leave comments, you need to log in
<tr th:each="task : ${tasks}">
<td th:text="${task.taskId}"></td>
<td th:each="user : ${task.userList}" th:text="${user}"></td>
</tr>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question