0

データ・モデル

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 Bean クラス [java.lang.String] の無効なプロパティ 'firstName': Bean プロパティ 'firstName' が読み取れないか、無効な getter メソッドがあります: 戻りますかgetter の型は setter のパラメータ型と一致しますか?

データ オブジェクトの firstName フィールドを読み取れないのはなぜですか?

上記のエラーメッセージの「bean class」のみを java.lang.String から java に変更するタグ (「bean="com.foo.bar.baz.model.Customer」) に完全なパッケージを追加しようとしました。 .lang.クラス

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 に答える