不考虑参数顺序,在JOOQ中进行POJO映射 [英] POJO Mapping in JOOQ regardless of parameter order

查看:114
本文介绍了不考虑参数顺序,在JOOQ中进行POJO映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我生成JOOQ POJO时,构造函数的参数与数据库表中的字段遵循相同的顺序.

When I generate the JOOQ POJOs, the constructor follows the same order for the parameters as the fields in the database table.

查询表并使用fetchInto时,只要POJO构造函数参数的顺序与数据库表中字段的顺序相同,就可以正常工作.

When querying the table and using fetchInto this works fine, as long as the order of the POJO constructor parameters and the order of the fields in the database table are the same.

return create
      .select()
      .from(KEY)
      .fetchInto(Key.class);

无论构造函数的参数顺序如何,如何将上面的查询映射到Key.class? 例如.我可以将mapstruct之类的东西与JOOQ结合使用吗?

How can I map the query above into Key.class regardless of the constructor parameter order? E.g. can I use something like mapstruct in conjunction with JOOQ?

推荐答案

您可以使用@java.beans.ConstructorProperties注释构造函数.我们还支持Java 8的参数名称反射(请参见 https://github.com/jOOQ/jOOQ/issue/4627 ),但这似乎并不可靠,因为它取决于您在编译自己的代码时设置的标志.

You can annotate your constructor with @java.beans.ConstructorProperties. We also support Java 8's parameter name reflection (see https://github.com/jOOQ/jOOQ/issues/4627), but that does not seem as reliable, as it depends on flags you set when compiling your own code.

另请参见 .

这篇关于不考虑参数顺序,在JOOQ中进行POJO映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆