在springboot+thymeleaf+mybatis中怎么集合里面中的list列表中某个值取出

怎样将bookList中的id bookName等值在前端thymeleaf模板中读出显示

CustomerController.java

public class CustomerController {

    @Autowired
    CustomerRepository customerRepository;

    @RequestMapping("/")
    public String test(HttpSession session){
        List<Customer> customers = customerRepository.findAll();
        session.setAttribute("customers",customers);
        return "test";
    }
}

CustomerRepository .java

public interface CustomerRepository extends JpaRepository<Customer, Long> {
	List<Customer> findAll();
}

html

<table >
    <tr th:each="c, State : ${session.customers}">
        <td th:text="${c.name}"></td>
        <td th:text="${c.passWord}"></td>
    </tr>
</table>

CustomerController.java

public class CustomerController {

    @Autowired
    CustomerRepository customerRepository;

    @RequestMapping("/")
    public String test(HttpSession session){
        Customer customers = customerRepository.findOne();
        session.setAttribute("customers",customers);
        return "test";
    }
}

CustomerRepository .java

public interface CustomerRepository extends JpaRepository<Customer, Long> {
	Customer findOne();
}

html

<table >
    <tr th:if="${session.customers} != null">
        <td th:text="${session.customers.name}"></td>
        <td th:text="${session.customers.passWord}"></td>
    </tr>
</table>

这样其他值可以取出来,但是bookList列表里的值怎样才能取出来啊

 一个循环取值,一个直接取

<tr th:each="book: ${bookList}">
    <td th:test="${book.name}"></td>
    <td th:test="${bookList[0].name}"></td>
</tr>

 

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m