package com.rabbi.formwork.common.base;
import com.jfinal.plugin.activerecord.*;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
/**
* Created with IntelliJ IDEA.
*
* @Description:
* @User: rabbi
* @Date: 2018-04-18
* @Time: 下午4:51
*/
public abstract class BaseService<M extends BaseModel<M>> {
protected M dao = null;
protected Class<M> modelClass = null;
protected Table table = null;
public BaseService() {
this.modelClass = getModelClazz();
this.table = TableMapping.me().getTable(this.modelClass);
try {
dao = modelClass.newInstance();
} catch (Exception e) {
e.printStackTrace();
}
}
private Class<M> getModelClazz() {
Type t = getClass().getGenericSuperclass();
Type[] params = ((ParameterizedType) t).getActualTypeArguments();
return (Class<M>) params[0];
}
}