0

数据模型

package com.foo.bar.baz.model

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

普惠制

  ....
  <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 read or has an invalid getter method: 是否返回getter 的类型是否匹配 setter 的参数类型?

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

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

4

1 回答 1

1

弄清楚了。

fields 标记需要一个实时的 Customer 对象,而不是对类的引用。为了解决它,我做了以下事情:

在控制器中创建了一个新的空客户对象并将其提供给视图:

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

然后更改视图以使用此对象,一切正常:

<f:with bean="emptyCustomer">
    <f:field property="firstName"/>
</f:with>
于 2012-06-01T14:00:31.873 回答