2017-07-09 4 views
0

Grailsを使用して簡単なCRUDアプリケーションを作成しようとしています。私はこのフレームワークに対して全く新しいです。私のCRUDテーブルには、ローカルデータベースに接続されたプロパティはほとんどなく、画像を読み込むことができないという点を除いてはうまく機能します。私はそれがタイプのミスマッチであるというエラーを得る。どのようにそれを解決するには?プロパティxxxは型が一致していません

私のコントローラクラスは以下の通りです:

class Person 
{ 
    int id 
    String name 
    String address 
    byte[] profilePic 
} 

static constraints 
{ 
    profilePic maxSize :204800 
} 

static mapping 
{ 
    table 'all_users' 
    version false 
    columns 
    { 
     id column: 'id' 
     name column: 'name' 
     address column: 'address' 
     profilePic column: 'profilepic' 
    } 
} 
+0

あなたのコンソールなどにエラーがある場合は、質問に追加してください。スタックトレース、...)。 「うまくいかない」と推測するのが難しく、何がうまくいかない。また、コードが正しく貼り付けられていることを確認してください。クラス外のスタティックブロックは絶対に間違って見えます。 – cfrick

+0

@cfrickエラーが発生する「ファイルを選択」フィールドにイメージを読み込もうとすると、プロパティイメージの型が一致しない –

答えて

0

ドメインコード

class Person 
{ 
    int id 
    String name 
    String address 
    String profilePic 
} 

static mapping 
{ 
    table 'all_users' 
    version false 
    columns 
    { 
     id column: 'id' 
     name column: 'name' 
     address column: 'address' 
     profilePic column: 'profilepic' 
    } 
} 

コントローラコード

def save(){ 
     def person = new Person(params) 
     person.save flush: true, failOnError: true 
     redirect action: "show", id: person.id 
     def downloadedfile= request.getFile('profilePic') 
     String profilePic = "D:/Your Grails Applications/grails-app/assets/images/" + person.name + ".jpg" 
     downloadedfile.transferTo(new File(profilePic)) 
    } 

ビューコード

<input type="file" name="profilePic"/> 
関連する問題