Grails 1.1 文件上传 - 通过数据绑定上传文件

文件上传同样可以通过数据绑定来完成。例如,假定你有一个像下面这样Image domain 类:class Image { byte[] myFile }现在,假如你创建一个image并像下面这个示例一样传入 params对象,Grails将自动把文件的内容当作一个byte绑定到myFile属性:def img = new Image(params)它同样可以设置文件的内容为一个string,通过改变image的myFile属性类型为一个String类型:class Image { String myFile }