How to get all the result columns from database with other custom(concat, sum, count) columns in Jooq

徘徊边缘 提交于 2019-12-03 10:26:55

Option 1 (using the asterisk):

The * (asterisk, star) operator has been added to jOOQ 3.11 through DSL.asterisk() (unqualified asterisk) or through Table.asterisk() (qualified asterisk). It can be used like any other column being projected.

Prior to jOOQ 3.11, there were the following other options as well:

Option 2 (with the DSL syntax):

List<Field<?>> fields = new ArrayList<Field<?>>();
fields.addAll(Arrays.asList(Table1.TABLE1.fields()));
fields.add(Table1.ID.count().as("IdCount"));

Select<?> select = ctx.select(fields).from(Table1.TABLE1);

Option 3 (with the "regular" syntax, which you used):

SelectQuery q = factory.selectQuery();
q.addSelect(Table1.TABLE1.fields());
q.addSelect(Table1.ID.count().as("IdCount"));
q.addFrom(Table1.TABLE1);

Option 4 (added in a later version of jOOQ):

// For convenience, you can now specify several "SELECT" clauses
ctx.select(Table1.TABLE1.fields())
   .select(Table1.ID.count().as("IdCount")
   .from(Table1.TABLE1);

All of the above options are using the Table.fields() method, which of course relies on such meta information being present at runtime, e.g. by using the code generator.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!