gpt4 book ai didi

grails - Grails:fields-1.2插件无法读取数据模型属性

转载 作者:行者123 更新时间:2023-12-02 15:35:50 25 4
gpt4 key购买 nike

DATAMODEL

package com.foo.bar.baz.model

class Customer {
Integer id
String firstName
String lastName
.....
}

GSP
  ....
<f:with bean="Customer">
<f:field property="firstName"/>
</f:with>
....

GSP不在views \ customer目录中,而是在views \ customerRegistration中。
当我尝试查看页面时,我得到:

URI /myApp/customerRegistration/index Class org.springframework.beans.NotReadablePropertyException Message Invalid property 'firstName' of bean class [java.lang.String]: Bean property 'firstName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?



为什么它不能读取我的数据对象中的名字字段?

我尝试将完整的程序包添加到标记(“bean =” com.foo.bar.baz.model.Customer“)中,该标记仅将上述错误消息中的“bean类”从java.lang.String更改为java .lang.Class

最佳答案

弄清楚了。

fields标签需要一个 Activity 的Customer对象,而不是对该类的引用。为了解决这个问题,我做了以下工作:

在 Controller 中创建了一个新的空客户对象,并将其提供给 View :

render(view: "myView", model: [emptyCustomer: new Customer()])

然后将 View 更改为使用此对象,并且一切正常:
<f:with bean="emptyCustomer">
<f:field property="firstName"/>
</f:with>

关于grails - Grails:fields-1.2插件无法读取数据模型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10850896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com