Thymeleaf获取后台List传值
程序员文章站
2022-05-01 23:14:26
...
List
public class CustomerController {
@Autowired
CustomerRepository customerRepository;
@RequestMapping("/")
public String test(HttpSession session){
List<Customer> customers = customerRepository.findAll();
session.setAttribute("customers",customers);
return "test";
}
}
public interface CustomerRepository extends JpaRepository<Customer, Long> {
List<Customer> findAll();
}
<table >
<tr th:each="c, State : ${session.customers}">
<td th:text="${c.name}"></td>
<td th:text="${c.passWord}"></td>
</tr>
</table>
实体
public class CustomerController {
@Autowired
CustomerRepository customerRepository;
@RequestMapping("/")
public String test(HttpSession session){
Customer customers = customerRepository.findOne();
session.setAttribute("customers",customers);
return "test";
}
}
public interface CustomerRepository extends JpaRepository<Customer, Long> {
Customer findOne();
}
<table >
<tr th:if="${session.customers} != null">
<td th:text="${session.customers.name}"></td>
<td th:text="${session.customers.passWord}"></td>
</tr>
</table>
上一篇: js操作级联选择多选框
下一篇: thymeleaf基本语法