Grails上傳文件,默認字段長度小的問題總結
1. 存在1個Domain class Profile,其中有個字段是存放相片的
class Profile {
//Profile is owned by User
//unidirectional relationship, profile can load user
static belongsTo = User
//binary data in byte[]
byte[] photo
static mapping = {
columns {
photo type:'blob'
}
}
//Profile is owned by User
//unidirectional relationship, profile can load user
static belongsTo = User
//binary data in byte[]
byte[] photo
static mapping = {
columns {
photo type:'blob'
}
}
默認情況下,byte[]數組在mysql下建立的字段是tinyblob,當上傳大點的圖片時,就會出現問題
然后,在datasouce.groovy中,把create-drop改成update,就可以了
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
//url = "jdbc:hsqldb:mem:devDB"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "dens"
url = "jdbc:mysql://localhost:3306/hubbub?useUnicode=true&characterEncoding=utf8"
}
}
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
//url = "jdbc:hsqldb:mem:devDB"
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = "dens"
url = "jdbc:mysql://localhost:3306/hubbub?useUnicode=true&characterEncoding=utf8"
}
}
posted on 2012-02-14 17:18 想飛就飛 閱讀(598) 評論(0) 編輯 收藏 所屬分類: Groovy/Grails