【问题标题】:Thymeleaf doesn't work with lombok forEachThymeleaf 不适用于 lombok forEach
【发布时间】: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


    【解决方案1】:

    我已经发现了一个问题。

    问题是在 Intellij 中缺少启用注释处理的复选框。

    【讨论】:

    • 请告诉我们哪个 chekcbox?如何启用它?我对百里香和龙目岛也有同样的问题
    猜你喜欢
    • 2017-06-24
    • 2018-07-22
    • 2020-05-16
    • 1970-01-01
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    相关资源
    最近更新 更多