如何在插入thymleaf+springboot后获得不同的图像?

zaq34kh6  于 2021-07-05  发布在  Java
关注(0)|答案(0)|浏览(206)

我有一个产品表,我正在存储产品的详细信息,包括(产品图像),并希望迭代不同的图像,并显示在主屏幕上(在旋转木马),但不幸的是,我不知道如何迭代。请检查我下面的代码,并向我建议(我是新来的,希望学习,所以请帮助。) Spring 启动+百里香叶
控制器代码-

@GetMapping("/home")
    public ModelAndView demoDo(HttpSession session) {

        ModelAndView model = new ModelAndView();

        List<String> img = pRepo.getImageName();

        System.out.println(img);

        model.addObject("slideDisps", img);
        model.setViewName("home");

        return model;
}

胸腺叶代码-

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" th:each="slideDisp : ${slideDisps}">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>
  <div class="carousel-inner" >
    <div class="carousel-item active" >
      <img class="d-block w-100" th:src="@{'/uploads/' +${slideDisp}}" alt="First 1 slide" width="100" height="350">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" th:src="@{'/uploads/' +${slideDisp}}" width="100" height="350" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" th:src="@{'/uploads/' +${slideDisp}}" width="300" height="350" alt="Third slide">
    </div>
  </div>
  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

接口-

public interface ProdRepo extends JpaRepository<Product, Integer> {

    @Query(value ="SELECT distinct filename FROM Product", nativeQuery = true)
    List<String> getImageName();

}

输出需要从数据库中提取3个不同的图像(建议顶部(3个)是否与我们可以实现的查询相似),并显示在类似carousel的amazon主页(顶部部分)上。请帮帮我,我现在真的不知道该怎么办了。请帮忙

暂无答案!

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

相关问题