使用Db+record 无需Model 类无需对数据库表进行映射
多数据源配置:
public void configPlugin(Plugins me) {
//sqlserver数据库插件
DruidPlugin druidPlugin = createDruidPlugin();
me.add(druidPlugin);
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
arp.setShowSql(PropKit.getBoolean("devMode", false));
arp.setDevMode(PropKit.getBoolean("devMode", false));
arp.setDialect(new SqlServerDialect());
//mysql数据库插件
DruidPlugin druidPluginMySql = createDruidPluginForMySql();
me.add(druidPluginMySql);
// 配置ActiveRecord插件,多个数据源后面加configname;
ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql",druidPluginMySql);
arpMysql.setShowSql(PropKit.getBoolean("devMode", false));
arpMysql.setDevMode(PropKit.getBoolean("devMode", false));
me.add(arp);
me.add(arpMysql);
me.add(new EhCachePlugin());
// 所有配置在 MappingKit 中搞定
_MappingKit.mapping(arp);
//_MappingKitMySql.mapping(arpMysql);
}
//sqlserver数据库插件
DruidPlugin druidPlugin = createDruidPlugin();
me.add(druidPlugin);
// 配置ActiveRecord插件
ActiveRecordPlugin arp = new ActiveRecordPlugin(druidPlugin);
arp.setShowSql(PropKit.getBoolean("devMode", false));
arp.setDevMode(PropKit.getBoolean("devMode", false));
arp.setDialect(new SqlServerDialect());
//mysql数据库插件
DruidPlugin druidPluginMySql = createDruidPluginForMySql();
me.add(druidPluginMySql);
// 配置ActiveRecord插件,多个数据源后面加configname;
ActiveRecordPlugin arpMysql = new ActiveRecordPlugin("mysql",druidPluginMySql);
arpMysql.setShowSql(PropKit.getBoolean("devMode", false));
arpMysql.setDevMode(PropKit.getBoolean("devMode", false));
me.add(arp);
me.add(arpMysql);
me.add(new EhCachePlugin());
// 所有配置在 MappingKit 中搞定
_MappingKit.mapping(arp);
//_MappingKitMySql.mapping(arpMysql);
}
分页:
public void getListData() {
String title=this.getPara("title");
Set<Condition> conditions=new HashSet<Condition>();
if(CommonUtils.isNotEmpty(title)){
conditions.add(new Condition("Name",Operators.LIKE,title));
}
Page<Record> paginate = Db.use("mysql").paginate(getPage(), getRows(), "select *", "from country");
this.renderJson(JqGridModelUtils.toJqGridView(paginate));
//使用model分页
//Page<Country> pageInfo=Country.dao.getPage(getPage(), this.getRows(),conditions,this.getOrderby());
//this.renderJson(JqGridModelUtils.toJqGridView(pageInfo));
//this.renderJson(JqGridModelUtils.toJqGridView(pageInfo));
}