你好,我在Spring Boot中使用JOOQ,想知道是否有一种方法可以获取具有其名称字符串的表及其列?例如:
Hello I'm using JOOQ with Spring Boot and was wondering if there was a way to obtain a table and its columns with a string of their name? For example:
我希望能够通过执行以下操作来获取表格:
I want to be able to get a table by doing something like:
someObject.getTable("user")
然后使用该get方法的结果,我还想获取该表的所有列,并能够将列名与其他字符串进行比较.换句话说,如果有一种获取表的方法,我还可以从同一对象中获取表的列名吗?
Then using the result of that get method I also want to obtain all of that table's columns and be able to compare the column names to other strings. In other words if there is a way to get a table, can I also get the table's column names from that same object?
在此方面,我将不胜感激.
I would really appreciate any help with this.
推荐答案是的,您可以:
当您生成模式时,所有这些信息都可以从生成的代码中获得.只需转到您的架构并查找表(区分大小写!):
When you generate your schema, all this information is available to you from generated code. Just go to your schema and look for the table (case-sensitive!):
Table<?> table = PUBLIC.getTable("user");然后:
Field<?>[] fields = table.fields();使用 org.jooq.Meta
如果尚未生成元数据,您仍然可以使用 DSLContext.meta() ,从中可以浏览架构/表/等.
Using org.jooq.Meta
If you don't have generated meta data, you can still look up things from your JDBC connection using DSLContext.meta(), from where you can navigate your schemas / tables / etc.
更多推荐
JOOQ:使用字符串获取表和列?
发布评论