Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从grails中的域类调用数据库_Grails - Fatal编程技术网

如何从grails中的域类调用数据库

如何从grails中的域类调用数据库,grails,Grails,如何从域类调用数据库视图 我有一个域类作为 class domaintable{ Integer id String abc String def static mapping = { table 'domaintable' id column: 'domaintableIdId' } } 我需要调用另一个数据库视图,如vwAnotherview,对abc和def进行一些验证。如何从域类为此视图调用数据库?将该视图映射到域类并在验证器中

如何从域类调用数据库视图

我有一个域类作为

class domaintable{

   Integer id
   String abc
   String def

   static mapping = {
      table 'domaintable'
      id column: 'domaintableIdId'
   }
}

我需要调用另一个数据库视图,如vwAnotherview,对abc和def进行一些验证。如何从域类为此视图调用数据库?

将该视图映射到域类并在验证器中使用它。没有什么能阻止你这么做:

static constraints = {
   abc validator: {val, obj ->
      if (!AnotherView.findByThisObject(val).someProperty) return ['somethingsWrong.withAbc']
   }
   def validator: {val, obj ->
      if (!AnotherView.findByThisObject(val).someProperty) return ['somethingsWrong.withDef']
   }
}
另一个视图是映射到视图的对象

要了解有关验证器的更多信息,请查看以下内容: