Grails - 控制器如何连接两个表并显示在一个 gsp 上?
我有两个表(但它们都作为插件安装)T1和T2
在T1中,列是:1a、1b、1c、1d
在T2中,列是:2a、2b、2c、2d
我需要选择列* a, *b, *c, d (=1,2) 来自控制器中的两个表作为联合并按列 *d 对所有这些表进行排序,我该怎么办 那?
之后,分页如何将结果视为单个表格?
我对 Grails 还很陌生,对此我有点困惑。请帮忙。欣赏!!
I have two tables (but all of them are installed as plugin) T1, and T2
In T1, columns are: 1a, 1b, 1c, 1d
In T2, columns are: 2a, 2b, 2c, 2d
I need to select columns *a, *b, *c, d (=1,2) from both of the tables in a controller as union and sort all of them by the column *d, how can I do that?
After this, how can the pagination work as treating about result as a single table?
I am fairly new to Grails and I am a bit confused about this. Pls help. Appreciate!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hibernate 以及 grails 不支持联合。您必须编写原始 SQL 查询才能做到这一点。
更好的方法可能是简单地连接两个表,获取包含列 a1、b1、c1、d1、a2、b2、c2、d2 的结果集,并在代码中实现联合逻辑。通过坚持使用常规 GORM 查询,您将能够使用 内置分页。
Hibernate, and by extension, grails, has no support for unions. You'll have to write a raw SQL query to do it that way.
A better approach might be to just simply join the two tables, getting a result set with columns
a1, b1, c1, d1, a2, b2, c2, d2
and implement the union logic in code. By sticking with a regular GORM query, you'll be able to use the built-in pagination.