绑定<a> tag to object in Thymeleaf

时间:2019-01-17 10:17:42

标签: java html spring-boot thymeleaf

I have List of data from Table 1 shown on a page and each data has a button "see more..." , when user clicks that button, they go to new page where I want to show only the associated data from Table 2, so far when user clicks the button all the data from Table 1 and Table 2 are displayed . I need to somehow associate the tag with the object.

Database Structure

胸腺模板1(列表项)

<div th:each="menu : ${menuList}">
     <div th:each="ing : ${menu.ingredient}" class="content">
        <div class="inside-box">
            <h1 th:text="${menu.name}" class="menu-name">Menu Name</h1>
            <a th:href="@{/foodDescription}"><p class="text">See More...</p></a>
            <!-- this is the button that I want to associate with the object-->
        </div>
     </div>
</div>

胸腺模板2(“查看更多...”页面)

   <div th:each="menu:${menuList}" class="content">
        <a th:href="@{/recipeList}">Go Back To List</a>
        <h1 th:text = "${menu.name}" class="menuName">Menu Name</h1>
        <div th:each="ing : ${menu.ingredient}" class="listItems">
            <ul>
                <li th:text = "${ing.ingredientName}">Food Description</li>
                    <ul>
                        <li th:text="${ing.ingredientDescription}"></li>
                    </ul>
            </ul>
        </div>
    </div>

菜单实体:

//Fields
...
// Mapping To second table
    @OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "menu_ingredient",
               joinColumns = @JoinColumn(name = "menu_id"),
               inverseJoinColumns = @JoinColumn(name = "ingredient_id"))
    private List<Ingredients> ingredient = new ArrayList<>();
// Constructors / Getters & Setters / ToString

0 个答案:

没有答案