grails - grails mybatis-plugin验证位置

标签 grails gorm mybatis

我从mybatis插件文档中引用:

"When working with MyBatis plugin your "Domain" classes should be located in src/groovy and not in grails-app/domain. This is necessary to avoid conflict with GROM since MyBatis plugin can coexist with existing GORM Domain classes."



所以,当我想在MyBatis插件上使用grails时,应该将验证和约束放在哪里?

最佳答案

您可以在Grails中的任何Groovy类中添加@Validateable批注,然后便可以对其进行验证...该插件当前不检查任何验证错误,因此您必须自己实现该代码。

从Grails官方文档中:

Classes which define the static constraints property and are annotated with @Validateable can be made validateable by the framework



http://grails.org/doc/2.1.0/guide/validation.html#validationNonDomainAndCommandObjectClasses

您甚至可以编写一个自定义的MyBatis拦截器(请参阅https://github.com/fzilic/Grails-MyBatis/blob/master/src/groovy/org/grails/plugins/mybatis/locking/OptimisticLockingInterceptor.groovy)并在创建SqlSession之后注册它。

当前,MyBatis插件不支持在其配置中注册自定义拦截器,但可以将其添加到拦截器链中

def factory = GrailsApplication.mainContext.getBean("sqlSessionFactoryBean_dataSource") 

factory.configuration.interceptorChain.addInterceptor(Interceptor)

将来的版本中可能会添加对此功能的支持。

关于grails - grails mybatis-plugin验证位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14010370/

相关文章:

Java - 避免创建空的子类和接口(interface)或生成 Java 源代码模板

java - MyBatis查询结果是HashMap吗?

grails - 在 Grails 中创建 war 时从插件中删除特定的 jar

grails - 我怎样才能绕过 : "query did not return a unique result"

grails - 为什么该Grails Spock GroovyMock测试失败(忽略参数)?

grails - 将两个gsp屏幕连接到grails中的三个域

grails - 查询grails树对象

spring - 在grails中左联接子查询?

java - MyBatis 中嵌套的 <collection> 和 <association> 给出 NULL 作为结果

grails - 设置后备区域设置