org.springframework.beans.NotReadablePropertyException:

塔雷克

我从控制器发送这样的BinderPlaceOrder对象

model.addAttribute("addNewBinderPlaceOrder", new BinderPlaceOrder());

我的Thymeleaf页面是

<form class="addBinderPlaceOrderForm" role="form" action="#" th:action="@{/binderPlaceOrder/new-binderPlaceOrder}" th:object="${addNewBinderPlaceOrder}" method="post">      
  
  <div class="form-group">
        <label>Book</label>
        <select class="form-control" th:field="*{binderOrderItemDetails.book}">
            <option th:if="${book} == null" value=" " >Select Book</option>
            <option th:each="book : ${allBook}"
                    th:value="${book.id}"
                    th:text="${book.name}">
            </option>
        </select>
    </div> 
  
  <form>

这是控制器,

@Controller
@RequestMapping("/binderPlaceOrder")
public class BinderPlaceOrderController{

@Autowired
BinderPlaceOrderService binderPlaceOrderService;

@Autowired
BookService bookService;

@RequestMapping(value="/new-binderPlaceOrder", method = RequestMethod.GET)
public String newBinderPlaceOrder(Model model){

    model.addAttribute("addNewBinderPlaceOrder", new BinderPlaceOrder());

    model.addAttribute("allBook", bookService.getAllBooks();

    model.addAttribute("addNewBinderOrderItemDetails", new BinderOrderItemDetails());

    return "user/binderPlaceOrder/new";
}
}

在运行期间,出现以下错误

org.springframework.beans.NotReadablePropertyException:Bean类[PublisherInventory.model.user.BinderPlaceOrder]的无效属性'binderOrderItemDetails.book':Bean属性'binderOrderItemDetails.book'不可读或具有无效的getter方法:返回类型为getter与setter的参数类型匹配?

以下是课程。

请注意,每个类都有其自己的Id属性以及其他属性。为了便于阅读,省略了这些内容。

这是BinderPlaceOrder类,

@Entity
public class BinderPlaceOrder implements Comparator<BinderPlaceOrder> {    

@OneToMany(mappedBy = "binderPlaceOrder", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<BinderOrderItemDetails> binderOrderItemDetails;   

public List<BinderOrderItemDetails> getBinderOrderItemDetails() {
    return binderOrderItemDetails;
}

public void setBinderOrderItemDetails(List<BinderOrderItemDetails> binderOrderItemDetails) {
    this.binderOrderItemDetails = binderOrderItemDetails;
}

}

这是BinderOrderItemDetails类

@Entity
@Indexed
public class BinderOrderItemDetails {

@OneToOne(fetch = FetchType.EAGER,cascade = CascadeType.ALL)
@JoinColumn(name="bookId")
private Book book;

@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name="binderPlaceOrderId")
private BinderPlaceOrder binderPlaceOrder;       

public Book getBook() { return book; }

public void setBook(Book book) { this.book = book; }    

public BinderPlaceOrder getBinderPlaceOrder() { return binderPlaceOrder; }

public void setBinderPlaceOrder(BinderPlaceOrder binderPlaceOrder) {
 this.binderPlaceOrder = binderPlaceOrder; }    
}

这是书本课

@Entity
@Indexed
public class Book implements Comparator<Book> {

@Column(name = "name")
@NotNull
@NotBlank 
private String name;

public String getName() {  return name; }
public void setName(String name) { this.name = name;}    
}

您能告诉我我做错了什么或如何解决吗?

提前致谢。

夸哈吉扬

正如@JBNizet指出的那样,您的BinderPlaceOrder具有

public List<BinderOrderItemDetails> getBinderOrderItemDetails() {
    return binderOrderItemDetails;
}

这是一个列表,因此

th:field="*{binderOrderItemDetails.book}"

是不正确的,

但说您想插入第一个元素,

 th:field="${binderOrderItemDetails[0].book}"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

org.springframework.beans.NotReadablePropertyException:-下拉表单

org.springframework.beans.NotReadablePropertyException:Bean类的无效属性

org.apache.jasper.JasperException:org.springframework.beans.NotReadablePropertyException:Bean类的无效属性“地址”

org.springframework.beans.factory.BeanCreationException问题

异常org.springframework.beans.factory.UnsatisfiedDependencyException

org.springframework.beans.factory.UnsatisfiedDependencyException 1

org.springframework.beans.factory.CannotLoadBeanClassException:

org.springframework.beans.factory.UnsatisfiedDependencyException org.springframework.beans.factory.NoUniqueBeanDefinitionException

org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.ui.Model]:指定的类是接口

Spring Profiles org.springframework.beans.factory.NoSuchBeanDefinitionException

java.lang.NoClassDefFoundError:org / springframework / beans / factory / config / EmbeddedValueResolver

NoSuchMethodError:org.springframework.beans.factory.config.ConfigurableListableBeanFactory

org.springframework.beans.InvalidPropertyException:Bean类的无效属性“ id”

如何修复org.springframework.beans.factory.BeanCreationException

自动连线字段上的org.springframework.beans.factory.BeanCreationException

Spring + Hibernate + Gradle-> org.springframework.beans.factory.BeanCreationException

线程“主要” org.springframework.beans.factory.NoSuchBeanDefinitionException中的异常

org.springframework.beans.NotWritablePropertyException:Bean类的无效属性'adminEmails'

注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}

org.springframework.beans.factory.CannotLoadBeanClassException:找不到类

Tomcat提供了org.springframework.beans.factory.CannotLoadBeanClassException:

启动jasperserver失败:org.springframework.beans.factory.BeanCreationException

生成的Jar文件抛出org.springframework.beans.factory.UnsatisfiedDependencyException

org.springframework.beans.factory.parsing.BeanDefinitionParsingException:多个“属性”定义

org.springframework.beans.factory.BeanDefinitionStoreException,如何修复错误?

java.lang.NoClassDefFoundError:org / springframework / beans / factory / Aware

org.springframework.beans.BeanInstantiationException:无法实例化

Spring MVC项目中的org.springframework.beans.factory.BeanCreationException

org.springframework.beans.NotWritablePropertyException:Bean类的无效属性“ xxxx”: