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'
}
}
默認情況下,byte[]數組在mysql下建立的字段是tinyblob,當上傳大點的圖片時,就會出現問題
解決辦法:運行程序后,手動將數據庫的tinyblob
改成 longblob
,然后 然后,在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"
}
}