我试图在运行服务器时将用户管理数据插入到测试中。Bootstrap 类执行成功,但记录未插入表中。我在这里粘贴我的角色、用户和引导文件
我的角色域
package com.mediacast
class Role {
static mapWith="mongo"
String roleType
static constraints = {
roleType(nullable:false,blank:false)
}
static mapping = {
}
}
我的测试域
package com.mediacast
class Tests {
static mapWith="mongo"
//static hasMany = [roles: Role]
String userName
String password
String mailId
String pwdSet
String role
Role roles
static constraints = {
userName nullable:false,blank:false, unique:true
mailId blank:false
}
static mapping={
version false
}
}
我的引导类是
import com.mediacast.User
import com.mediacast.Role
import com.mediacast.Tests
class BootStrap {
def springSecurityService
def init = { servletContext ->
if (!Tests.count()) {
createData()
}
}
private void createData(){
def roleInstance = Role.findByRoleType("Admin")
System.out.println("--------Instance-----------"+roleInstance.roleType);
//def password = springSecurityService.encodePassword("admin")
def userSec =new Tests(userName:"admin",password:"admin",mailId:"raghurame@techaffinity.com",roles:roleInstance,pwdSet:"Y").save(flush:true)
System.out.println("--------Instance-----------"+userSec);
}
def destroy = {
}
}
它正在执行,但记录未插入引导程序。请在这方面提供帮助。