Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
109 views
in Technique[技术] by (71.8m points)

Spring Thymleaf Class Object is retrieving from MySQL but Thymleaf is not able to render it completely

I have this class "Listing (kind of a product)". I haven;t created an upload form so i manually inserted one record in Listing Table in MySQL but when rendering on Front Thymleaf isn't rendering.

(Class Object is kind of a product with price, description, images etc.)

Listing Class

@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() {
        
    }
}

Controller

@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 page where i am trying to display each listing

<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>

This is the output I can see where totalItem is 1 as in MySQl there is only one listing which I manually inserted with 4 images as required by class object

question from:https://stackoverflow.com/questions/65893540/spring-thymleaf-class-object-is-retrieving-from-mysql-but-thymleaf-is-not-able-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...