0
我想將記錄列表轉換爲一些Java對象(所以,將ActiveJDBC模型轉換爲另一個Java類),但是我希望能夠爲我的所有模型調用相同的方法並通過模型類型,是這樣的:使用泛型和ActiveJDBC模型
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(...)
任何想法如何使它工作?
謝謝!
我確實(適用於我的其他代碼)。我認爲這是因爲仿製藥的工作方式,M.findWith(...)使用Model類而不是我的類擴展它(MyModel.java),而findWith()是靜態的這一事實並沒有幫助... –