【发布时间】:2019-12-20 19:46:36
【问题描述】:
我不断收到此错误,现在我不知道为什么。
原因:org.springframework.beans.NotReadablePropertyException:bean 类 [java.util.ArrayList] 的无效属性“所有者”:bean 属性“所有者”不可读或具有无效的 getter 方法:返回类型是否为getter 是否匹配 setter 的参数类型?
我尝试过使用
th:field="*{owner}",
th:field="*{Owner}",和
th:field="*{setOwner}" 但仍然出现同样的错误。
控制器
@RequestMapping("/wqrms/customer/create")
public String customerCreate(Model model) {
List<Customer> customer = customerService.listAll();
model.addAttribute("customer", customer);
return "/views/wqrms/customer/create";
}
型号
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String owner;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getOwner() {
return owner;
}
public void setOwner(long id) {
this.owner = owner;
}
}
百里香
<form action="#" th:action="@{/wqrms/customer/save}" th:object="${customer}" method="post">
<div class="form-row">
<div class="form-group col-md-6">
<label>Customer Name</label>
<input class="form-control" placeholder="Customer Name" required th:field="*{owner}">
</div>
【问题讨论】:
-
属性'customer'的类型是List
,它确实没有字段'owner'。您可能希望向模型中添加一个“空”的单个客户,然后将其填充为 setter 方法。
标签: java html spring spring-boot thymeleaf