简体   繁体   English

JOOQ动态表名称

[英]JOOQ dynamic table name

Say for example my function accepts a parameter called 'entityType', and according to that it queries the table entityType_other_stuff . 比如说我的函数接受一个名为“ entityType”的参数,并据此查询表entityType_other_stuff

Is this possible to implement in JOOQ on runtime? 是否可以在运行时在JOOQ中实现?

The correct way to create dynamic org.jooq.Table objects by name is to use DSL.table(Name) as in: 按名称创建动态org.jooq.Table对象的正确方法是使用DSL.table(Name)如下所示:

String parameter = "entityType";
Table<?> table = table(name(parameter + "_other_stuff"));

If you use the standard Settings.renderNameStyle QUOTED , then the identifier will be quoted and escaped, and thus SQL-injection safe. 如果使用标准的Settings.renderNameStyle QUOTED ,则标识符将被加引号和转义,从而可以安全地进行SQL注入。

For more information, see the manual: https://www.jooq.org/doc/latest/manual/sql-building/names 有关更多信息,请参见手册: https : //www.jooq.org/doc/latest/manual/sql-building/names

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM