在 Grails 中...如何在单个控制器中合并两个表?

发布于 2024-11-17 20:30:02 字数 216 浏览 2 评论 0原文

我有两个表,但它们作为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

客…行舟 2024-11-24 20:30:02

不确定这是否有帮助。我们过去遇到过类似(尽管不完全)的问题,我们通过创建视图来解决它。您可以创建视图来进行联合和选择,然后创建映射到该视图的新域类。

您将无法对表使用 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.

倾城°AllureLove 2024-11-24 20:30:02

分页时:

  1. groovy.sql.Sql 行()eachRow() 有第二个和第三个参数 maxoffset,您可以像平常一样对它们进行分页列表

  2. 使用另一个 SQL 查询或其他方式检索总计数。构造一个 PagedResultList数据页 rows()int totalCount - 您就得到了一个可以用作模型的对象。

On pagination:

  1. groovy.sql.Sql rows() and eachRow() have 2nd and 3rd parameters max and offset that you can paginate with all like in ordinary list.

  2. Retrieve total count with another SQL query or some other way. Construct a PagedResultList from a data page rows() and int totalCount - and you got an object that you can use as a model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文