我正在尝试使用Grails构建简单的CRUD应用程序。我对这个框架非常陌生。我的CRUD表有很少的属性,连接到本地数据库,它工作得很好,除了它不能加载图片。我收到错误,表明它的类型不匹配。怎么解决?
我的控制器类如下:
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 :(得分: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"/>
答案 1 :(得分:0)