我从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/