0

我正在尝试将记录列表转换为某个 Java 对象(因此,ActiveJDBC 模型转换为另一个 Java 类),但我希望能够为我的所有模型调用相同的方法并传递模型类型,例如:

private <M extends Model, T> List<T> getObjects(Class<M> modelType, Class<T> objectType) {
    List<T> records = new ArrayList<T>();
    M.findWith(new ModelListener<M>() {
        public void onModel(M row) {
            // Here I would convert the Model to my desired object and add it to the list of records
        }
    }, null);
    return records.isEmpty() ? null : records;
}

我会这样称呼:

getObjects(MyModel.class, MyObject.class);

我明白了

Exception: failed to determine Model class name, are you sure models have been instrumented?

M.findWith(...)

知道如何使它工作吗?

谢谢!

4

1 回答 1

1

您需要在使用模型之前对其进行检测。请参阅http://javalite.io/instrumentation

于 2015-09-16T20:49:11.523 回答