title: Thymeleaf How can I display a column from one table based on a value from another table
body: <p>I'm working on a small project trying to learn thymeleaf.
  I have 3 tables Timetables which contains an id, assignment id as a foreign key and other stuff, Assignments which contains and id and project id as a foreign key and Projects which contains and id and project name.</p>
  
  <p>I need to display Timetables in an html, easy enough, however i want to display the project name instead of the assignment id column.</p>
  
  <p>I already have a select in my service class which calls the required columns but how can i tell thymeleaf to read that column instead of looking for it in Timetables.</p>
  
  <p>Here is my code</p>
  
  <p>html</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;table class="table table-bordered"&gt;
      &lt;thead&gt;
      &lt;tr&gt;
          &lt;th&gt;id&lt;/th&gt;
          &lt;th&gt;assignment&lt;/th&gt;
          &lt;th&gt;date&lt;/th&gt;
          &lt;th&gt;number of hours&lt;/th&gt;
      &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
      &lt;tr th:each="timetable: ${timetables}"&gt;
          &lt;td th:text="${timetable.timetableId}"&gt;45&lt;/td&gt;
          &lt;td th:text="${timetable.assignmentId}"&gt;vasi&lt;/td&gt;
          &lt;td th:text="${timetable.date}"&gt;1 ian&lt;/td&gt;
          &lt;td th:text="${timetable.hoursWorked}"&gt;3000&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Service class</p>
  
  <pre><code>@Autowired
  JdbcTemplate template;
  
  public List&lt;Timetable&gt; findAll(String loginname) {
      String sql = "  SELECT timetables.timetableId, timetables.assignmentId, timetables.date, timetables.hoursWorked, users.username, projects.projectName FROM timetables INNER join assignments on assignments.assignmentId = timetables.assignmentId INNER JOIN users on users.userId = assignments.userId " +
              "INNER JOIN projects on assignments.projectId = projects.projectId where username= ?";
  
      RowMapper&lt;Timetable&gt; rm = new RowMapper&lt;Timetable&gt;() {
          @Override
          public Timetable mapRow(ResultSet resultSet, int i) throws SQLException {
              Timetable timetable = new Timetable(resultSet.getInt("timetableId"),
                      resultSet.getInt("assignmentId"),
                      resultSet.getDate("date"),
                      resultSet.getInt("hoursWorked"));
  
              return timetable;
          }
      };
  
      return template.query(sql, rm, loginname);
  }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>@Autowired
  TimetableService service;
  
  @Autowired
  AssignmentsService serv;
  
  @RequestMapping(value = {"/Timetable"}, method = RequestMethod.GET)
  public String index(Model md) {
      Authentication auth = SecurityContextHolder.getContext().getAuthentication();
      String loginname = auth.getName();
      md.addAttribute("timetables", service.findAll(loginname));
      return "Timetable";
  }
  </code></pre>