自 thymeleaf 以来,我如何获得元组值(querydsl)?

How i can get tuple value (querydsl) since thymeleaf?

我不知道我是如何获得 queryDSL 的元组值的,因为 thymeleaf

自从后端我发送这个值:

List<Tuple> products = productServiceImpl.findProductByFiltersPaginate(null, 0, 1, null);

ModelAndView view = new ModelAndView();
        view.addObject("products",products);
        view.setViewName(ViewConst.MAIN_LAYOUT);
        view.addObject("view","catalog");
        return view;

但在前面 (thymeleaf) 我不知道如何获取这些值。我的代码如下:

<div th:each="product :${products}">
             <h2 th:text="${product}"></h2>
        </div>
    </div>

但我不知道变量名后面放的是什么。 我已经尝试过这些方法: ${product.name}, ${产品['name']}, ${产品[0]} 但是 none 有效。

如果我只放这个 ${product} 它 returns 我用这种格式每个值

[39, Moto KTM DUKE, /images/products/product39/m_39_0.jpg]

根据您的回复,我认为这些可能有效:

product.get(0, Product.class)

<!-- Note, you have to replace your.package.Product with the actual package -->
<div th:each="product :${products}" th:with="class=${T(your.package.Product).class}">
  <h2 th:text="${product.get(0, class)}" />
</div>

product.get(qProduct.title)

<!-- For this, you need to add qProduct on the model -->
<div th:each="product :${products}">
  <h2 th:text="${product.get(qProduct.title)}" />
</div>

您也可以使用 toArray(),但我不完全确定结果如何:

<div th:each="product :${products}" th:with="data=${product.toArray()}">
  <h2 th:text="${data[0]}" />
</div>