我是 Jooq 的新手。我想将字符串转换为整数。
在表 1 中定义:-
TableField<?, Integer> city_id;
在表2中定义:-
TableField<?, String> city_id;
在选择查询中。
dsl.select()
.from(Table1)
.leftOuterJoin(Table2)
.on(Table1.city_id.eq(Table2.city_id))
.fetch();
因为 city_id 在 Table1 和 TABLE2 中的格式不同。所以它需要将 table2 的 city_id 从 String 转换为 Integer,反之亦然 我试过 Integer.valueOf()、Integer.parseInt(),不起作用。
感谢任何帮助。提前致谢。
最佳答案
jOOQ 文档 ( https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/cast-expressions/ ) 描述了 cast()
的用法,它可以在语句中用于将字段转换为另一种类型。
使用你的例子:
Defined in Table1:-
TableField<?, Integer> city_id;
Defined in Table2:-
TableField<?, String> city_id;
In select query.
dsl.select()
.from(Table1)
.leftOuterJoin(Table2)
.on(Table1.city_id.eq(Table2.city_id))
.fetch();
使用cast将Integer转String的语句:
dsl.select()
.from(Table1)
.leftOuterJoin(Table2)
.on(Table1.city_id.cast(String.class).eq(Table2.city_id))
.fetch();
关于java - jooq 字符串到整数的转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44017831/