我尝试使用 MongoDB 2.0.6 替换 MySQL 5.5.25 来测试 Grails 2.1 应用程序,但遇到了一些奇怪的问题。
使用 MongoDB 但不使用 MySQL 时出现的问题:
使用脚手架时,我无法使用静态约束对字段进行排序
当我指定 inList 作为约束时,使用 MySQL 后端时会得到一个下拉列表,但使用 MongoDB 后端时会得到一个字段。
字段中没有 *(星号)blank=false
指定的约束。
领域类:
package study
class Student {
String login
String firstName
String lastName
String gender
Boolean active
Date dateCreated
Date lastUpdated
static constraints = {
login()
firstName(blank: false)
lastName(blank: false)
gender(inList: ['M', 'F'])
active()
}
}
控制器
package study
class StudentController {
def scaffold = true
}
数据源.groovy(MySQL的东西注释掉了):
grails {
mongo {
host = "dev-linux"
port = 27017
username = "study"
password= "********"
databaseName = "study"
}
}
//dataSource {
// pooled = true
// driverClassName = "com.mysql.jdbc.Driver"
// dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
// username = "study"
// password = "********"
// dbCreate = "create-drop" // one of 'create', 'create-drop','update'
// url = "jdbc:mysql://dev-linux:3306/study"
//
//}
//hibernate {
// cache.use_second_level_cache = true
// cache.use_query_cache = true
// cache.provider_class = "net.sf.ehcache.hibernate.EhCacheProvider"
//}
BuildConfig.groovy(显示的插件部分是我为了用 MongoDB 代替 MySQL 所做的所有更改,该文件的其余部分是 Grails 创建的默认值)
plugins {
// build ":hibernate:$grailsVersion"
// compile ":mysql-connectorj:5.1.12"
compile ":mongodb:1.0.0.GA"
build ":tomcat:$grailsVersion"
}
我对放入 MongoDB 并取出 MySQL 所做的唯一更改是对数据源.groovy and BuildConfig.groovy如上所示。
我是否缺少任何配置项?
我确实看到有人提到过这个纳布尔论坛帖子 http://grails.1312388.n4.nabble.com/2-0-1-order-of-fields-for-scaffolding-is-broken-td4445221.html字段排序可能是 MongoDB 的问题。
不过,这篇文章没有透露任何细节。
另外,我不明白为什么或如何后端数据库引擎会影响使用脚手架时呈现视图的方式。具体来说,页面和下拉菜单与文本字段上的顺序。
我本以为这将来自域类的字段类型和约束。
之前有人在 MongoDB 中使用 Grails+Scaffolding 时遇到过这种奇怪的行为吗?有谁知道修复或有任何见解吗?
预先非常感谢您,我很感激。