【发布时间】:2018-11-08 22:51:47
【问题描述】:
我对 Spring Boot 项目中的 Thymeleaf "forEach" 和 Lombok 项目有疑问。 如果我将生成 getter 和 setter,那么一切正常。如果我使用 lombok 注释,我会得到这个异常:
EL1008E:在“pl.codol.hibernate.model.CustomerEntity”类型的对象上找不到属性或字段“firstName” - 可能不是公共的或无效的?
有没有人知道可能出了什么问题?我阅读了其他主题,但它们并没有帮助我解决我的问题。
我的 POJO 类:
@Data // I also used @Getter and @Setter, doesn't work
@NoArgsConstructor
@Entity
@Table(name = "CUSTOMER")
public class CustomerEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "CUSTOMER_ID")
private Long id;
@Column(name = "FIRST_NAME")
private String firstName;
@Column(name = "LAST_NAME")
private String lastName;
@Column(name = "EMAIL")
private String email;
@Override
public String toString() {
return "CustomerEntity{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", email='" + email + '\'' +
'}';
}
}
控制器:
@Controller
@RequestMapping("/customer")
public class CustomerController {
private CustomerService customerService;
@Autowired
public CustomerController(CustomerService customerService) {
this.customerService = customerService;
}
@RequestMapping("/list")
public String listCustomers(Model model) {
List<CustomerEntity> allCustomers = customerService.findAllCustomers();
model.addAttribute("customers", allCustomers);
return "list-customers";
}
}
导致问题的部分html文件:
<th:block th:each="customer : ${customers}">
<tr>
<td th:text="${customer.firstName}">...</td>
<td th:text="${customer.lastName}">...</td>
<td th:text="${customer.email}">...</td>
</tr>
</th:block>
【问题讨论】:
标签: java spring tomcat thymeleaf lombok