本文介绍了JOOQ使用转换器内联将字符串转换为枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如此处所问,对此的后续问题

As asked here the follow up Question to this #58538732

根据Lukas Eder的建议,我编写了 EnumConverter 来转换 Integer DayOfWeek

As suggested by Lukas Eder I wrote an EnumConverter to convert the Integer to a DayOfWeek

public class DOWConverter extends EnumConverter<Integer, DayOfWeek>  {

    public DOWConverter()
    {
        super(Integer.class, DayOfWeek.class);
    }
}

select 现在看起来如下

DataType<DayOfWeek> typeDOW = SQLDataType.INTEGER.asConvertedDataType(new DOWConverter() /*ERROR*/);
Field<DayOfWeek> fieldDOW = DSL.field("{0}", typeDOW, lecture.DAY_OF_WEEK);

create.select( ..., fieldDOW, ...)...

出现错误消息:

As声明,当前无法在CodeGen时使用Converter。

As stated, using the Converter at CodeGen Time is currently not an option.

推荐答案

似乎您放置了 DOWConverter 在另一个类中,从而创建一个。我建议您将转换器放在其自己的文件的顶层,使其成为顶层类。如果必须创建一个嵌套类,请通过使其成为静态来确保它不是内部类:

It seems that you placed your DOWConverter inside of another class, thus creating an inner class. I recommend you place the converter at the top level, in its own file, making it a top level class. If you must create a nested class, make sure it is not an inner class by making it static:

public class Enclosing {
    // Make this class here static:
    public static class DOWConverter extends EnumConverter<Integer, DayOfWeek> {
        public DOWConverter() {
            super(Integer.class, DayOfWeek.class);
        }
    }
}

这篇关于JOOQ使用转换器内联将字符串转换为枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 07:02