我在Spring Boot项目中对Thymeleaf“ forEach”和Lombok项目有疑问。 如果我将生成getter和setter,则一切正常。以防我在使用龙目岛注释时出现此异常:
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>
答案 0 :(得分:2)
我已经发现了一个问题。
问题缺少用于Intellij中启用注释处理的复选框。