Java Thymeleaf看不到来自控制器的引用
我试图使用Thymeleaf在html页面上显示本地数据库PostgreSQL中的所有客户。我的项目是使用SpringBoot 连接和从数据库获取数据不是这个问题的重点,是吗?。关键是thymeleaf并没有看到我通过控制器传递的模型 homePage.htmlJava Thymeleaf看不到来自控制器的引用,java,postgresql,spring-boot,spring-data,thymeleaf,Java,Postgresql,Spring Boot,Spring Data,Thymeleaf,我试图使用Thymeleaf在html页面上显示本地数据库PostgreSQL中的所有客户。我的项目是使用SpringBoot 连接和从数据库获取数据不是这个问题的重点,是吗?。关键是thymeleaf并没有看到我通过控制器传递的模型 homePage.html !DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd"> <html xmlns="http://
!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Opera</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Opera home page'" />
<ul th:each="customer : ${customers}">
<li>
<span th:text="${customers.getFirstName}">Name</span>
<span th:text="${customers.getLastName}">Surname</span>
<span th:text="${customers.getPhone}">Phone</span>
<span th:text="${customers.getEmail}">e-mail</span>
</li>
</ul>
</body>
</html>
显示问题的html文件截图:
编辑:一些英文更正:不要在模板中使用getter。这样做:
<span th:text="${customer.firstName}">Name</span>
很抱歉,您还必须删除s我将其更改为customer.firstName等,但thymeleaf似乎根本无法识别客户列表,因此for each循环甚至无法启动VM,情况就是这样:它工作正常,但客户仍然突出显示。显然是IntelliJ bug。谢谢
@Repository
public interface CustomerRepository extends CrudRepository<Customer, Long> {
}
@Entity
@Getter @Setter
public class Customer {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
@NotNull private String firstName;
@NotNull private String lastName;
@NotNull private String phoneNumber;
@NotNull private String email;
protected Customer(){}
public Customer(Long id, String firstName, String lastName, String phoneNumber, String email){
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
this.email = email;
}
@Override
public String toString(){
return String.format(
"Customer[id=%d, firstName='%s', lastName='%s', phoneNumber='%s', emailr='%s']",this.getId(),
firstName, lastName, phoneNumber, email);
}
}
<span th:text="${customer.firstName}">Name</span>