私の Grails 2.2.3 アプリケーションには、次のコマンド オブジェクトがあります。
@Validateable
class PictureCommand {
MultipartFile picture
String notes
Boolean isDocument
static constraints = {
picture nullable: false, validator: { val ->
if (!val.contentType in ['image/jpeg', 'image/png', 'image/pjpeg', 'image/gif','image/bmp'])
return 'fileType.invalid'
}
notes nullable: true
isDocument nullable: true
}
}
これにより、画像ファイルのアップロードが可能になり、有効なタイプのリストに含まれていることが保証されます。ただし、問題は、そのリストにないファイルをアップロードできることです。呼び出すとcmd.validate()
gettrue
を呼び出し、次に呼び出しcmd.hasErrors()
て get を取得しますfalse
。'fileType.invalid'
Stringと Listを返そうとしましたが['fileType.invalid']
、どちらも機能しません。誰にもアイデアはありますか?ありがとう。