波总你好,我打算把之前2.0的项目迁移到3.0上面,并且使用3.0的sql模板
我已经在config中配置了好路径,并且调试进去也加载sqlkit中。但是我在model AdvertStartpage中 getSql("getValidAdvertStartpage"); 就是返回空,我跟踪进去发现这个model中的sqlkit不同于刚才config中那个。还望各位大神指导下,谢谢!
config:
@Override
public void configPlugin(Plugins me) {
// TODO Auto-generated method stub
// 配置数据库连接池插件 Druid
DruidPlugin druidPlugin = new DruidPlugin(ConfigKit.get("jdbc.url"), ConfigKit.get("jdbc.username"), ConfigKit.get("jdbc.password"),
ConfigKit.get("jdbc.driver"));
druidPlugin.addFilter(new WallFilter());//配置防御SQL注入攻击
druidPlugin.addFilter(getStatFilter());//打开Druid的监控统计功能
me.add(druidPlugin);
// 配置ActiveRecordPlugin
ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql",druidPlugin);
arpMysql.setBaseSqlTemplatePath(PathKit.getRootClassPath());
arpMysql.addSqlTemplate("acr.sql");
me.add(arpMysql);
// 添加自动绑定model与表插件
AutoTableBindPlugin autoTableBindPlugin = new AutoTableBindPlugin(druidPlugin, TableNameStyle.LOWER_UNDERLINE);
autoTableBindPlugin.setShowSql(true);
autoTableBindPlugin.setDialect(new MysqlDialect());// 配置MySql方言
autoTableBindPlugin.setContainerFactory(new CaseInsensitiveContainerFactory(true));
me.add(autoTableBindPlugin);
// 缓存插件
me.add(new EhCachePlugin());
}
acr.sql
#sql("getValidAdvertStartpage")
SELECT * from table
#end
Model:
public class AdvertStartpage extends BaseModel<AdvertStartpage> {
public static final AdvertStartpage dao = new AdvertStartpage();
public List<AdvertStartpage> getValidAdvertStartpage() {
System.out.println(getSql("getValidAdvertStartpage") );
return find(getSql("getValidAdvertStartpage"));
}
}