在 Grails 中...如何在单个控制器中合并两个表?
我有两个表,但它们作为 Grails 中的插件安装。
T1 中的列是:a1、b1、c1、d1
T2 中的列是:a2、b2、c2、d2
我需要从以下位置选择列 a*、b*、c*、d* (=1,2)将控制器中的两个表作为联合并按列 d 对所有表进行排序,我该怎么做?
此外,分页如何将结果视为单个表格?
请帮忙。欣赏!!
I have two tables, but they are installed as plugin in Grails.
Columns in T1 are: a1, b1, c1, d1
Columns in T2 are: a2, b2, c2, d2
I need to select columns a*, b*, c*, d* (=1,2) from both tables in a controller as union and sort all of them by the column d, how can I do that?
Furthermore, how can the pagination work as treating about result as a single table?
Pls help. Appreciate!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否有帮助。我们过去遇到过类似(尽管不完全)的问题,我们通过创建视图来解决它。您可以创建视图来进行联合和选择,然后创建映射到该视图的新域类。
您将无法对表使用 grails auto create ,这是另一个限制。
Not sure if this is helpful or not. We hit a similar (though not exact) problem in the past, and we solved it by creating a view. You can create the view to do your union and select, and then create the new domain class that maps to the view.
You won't be able to use grails auto create for the table, which is another limitation.
分页时:
groovy.sql.Sql
行()
和eachRow()
有第二个和第三个参数max
和offset
,您可以像平常一样对它们进行分页列表
。使用另一个 SQL 查询或其他方式检索总计数。构造一个
PagedResultList
数据页rows()
和int totalCount
- 您就得到了一个可以用作模型的对象。On pagination:
groovy.sql.Sql
rows()
andeachRow()
have 2nd and 3rd parametersmax
andoffset
that you can paginate with all like in ordinarylist
.Retrieve total count with another SQL query or some other way. Construct a
PagedResultList
from a data pagerows()
andint totalCount
- and you got an object that you can use as a model.