SpringThymLeaf类对象正在从mysql检索,但thymleaf无法完全呈现它

kkih6yb8  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(154)

我有一个类“listing(一种产品)”。我避风港;我没有创建一个上传表单,所以我在mysql的列表表中手动插入了一条记录,但是在前台渲染时,我没有渲染。
(类对象是具有价格、描述、图像等的产品)
列表类

@Entity
@Table(name="listings")
public class Listing {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int listing_id;

    @Column(nullable=false)
    private String listing_name;
    private LocalDateTime dateUploaded = LocalDateTime.now();
    @Column(nullable=false)
    private String decription;

    @Column(nullable=false)
    private int price;

    @Column(nullable=false)
    private boolean availability;

    @Lob
    private byte[] image_1;
    @Lob
    private byte[] image_2;
    @Lob
    private byte[] image_3;
    @Lob
    private byte[] image_4;

    @ManyToOne(fetch=FetchType.EAGER,cascade= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.DETACH,CascadeType.REFRESH})
    @JoinColumn(name="category_id")
    private Category category;

    @ManyToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="username")
    private User user;

    public Listing() {

    }
}

控制器

@RequestMapping("/")
    public String viewHomePage(Model model) {
        return viewPage(model,1);
    }
    @RequestMapping("/page/{thePageNumber}")
    public String viewPage(Model model,@PathVariable(name="thePageNumber") int thePageNumber) {

        List<Category> categories = aCategoryService.findall();
        Page<Listing> listings= aListingService.findAllPagedSortedByTime(thePageNumber);
        List<Listing> listingstoShow= listings.getContent();
        //System.out.println(Arrays.toString(listingstoShow.toArray()));
        model.addAttribute("currentPage",thePageNumber);
        model.addAttribute("allCategories", categories);
        model.addAttribute("listings",listingstoShow);
        model.addAttribute("totalPages",listings.getTotalPages());
        model.addAttribute("totalItems",listings.getTotalElements());
        return "index";
    }

我试图显示每个列表的html页面

<div th:each="product:${listingstoShow}"
                        class="col-lg-4 col-md-4 col-sm-6 product" data-aos="fade-up"
                        data-aos-delay="200">
                        <div class="product-inner">
                            <div class="thumb">
                                <a th:href="@{/}" class="image"> 
                                    <img class="first-image" th:src="${product.image_1}" alt="Product" /> 
                                    <img class="second-image" th:src="${product.image_2}" alt="Product" />
                                </a>
                            </div>
                            <div class="content">
                                <h4 class="sub-title">
                                    <a th:href= "@{/}" th:text="${product.listing_name}">Something</a>
                                </h4>
                                <h5 class="title">
                                    <a th:href="@{/}" th:text="${product.listing_name}">Listing Name</a>
                                </h5>
                                <p th:text="@{product.decription}">Description</p>
                                <span th:text="${product.price}" class="price"> <span class="new">$40.50</span></span>
                                <div class="shop-list-btn">
                                    <a th:href="@{/}"><button
                                            class="btn btn-sm btn-outline-dark btn-hover-primary"
                                            title="Add To Cart">Book</button></a>
                                </div>
                            </div>
                        </div>
                    </div>

这是我可以看到的输出,其中totalitem是1,因为在mysql中,只有一个列表,我根据类对象的要求手动插入了4个图像

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题