如何在Grails中进行简单的表联接 [英] How to do a simple table join in Grails

查看:55
本文介绍了如何在Grails中进行简单的表联接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对grails还是很陌生的,并且通过在这些表的基础上创建的域对象来联接两个现有表存在很多麻烦.有谁知道如何做到这一点?这是表格的外观,以及如何需要连接的表格的示例.先谢谢您的帮助.

I'm kind of new to grails and I'm having a lot of trouble with joining two existing tables through domain objects that have been created off of those tables. Does anyone know how to do this in grails? Here are what the tables look like and an example of how I need the joined table to look. Thanks in advance for the help.

Table1{ 

     field1table1 
} 

Table2{ 

     field1table2

     field2table2 
} 

我需要连接这两个表,其中field1table1 = field1table2和结果表联接,我需要看起来像这样:

I need to join these 2 tables where field1table1 = field1table2 and the resulting table join I need to look like this:

JoinedTable{

     field1table1 

     field2table2 
}

推荐答案

如果您的域没有任何关系(hasOne,hasMany等),则可以使用executequery来执行类似以下内容的hql查询:

If your domains does not have any relationship (hasOne, hasMany, etc) You can use executequery to execute hql queries something like this :

Table1.executeQuery("select * from Table1 t1,Table2 t2 where t1.field1table1 = t2.field2table2")

查看 doc

希望这会有所帮助

这篇关于如何在Grails中进行简单的表联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆