92 lines
2.8 KiB
Java
92 lines
2.8 KiB
Java
package cn.cloudowr.ywxj.shangbao;
|
|
|
|
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
|
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
|
import com.jfinal.config.*;
|
|
import com.jfinal.template.Engine;
|
|
import com.mongodb.MongoClient;
|
|
import com.mongodb.MongoCredential;
|
|
import com.mongodb.ServerAddress;
|
|
import com.mongodb.client.MongoDatabase;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import static cn.cloudowr.ywxj.shangbao.Main.*;
|
|
|
|
/**
|
|
* Created by lyf66 on 2017/2/18.
|
|
*/
|
|
public class Config extends JFinalConfig{
|
|
private static MongoDatabase mongoDatabase;
|
|
|
|
|
|
public static MongoDatabase getMongoDatabase() {
|
|
return mongoDatabase;
|
|
}
|
|
|
|
@Override
|
|
public void configConstant(Constants me) {
|
|
}
|
|
|
|
@Override
|
|
public void configRoute(Routes me) {
|
|
me.add("/", Controller.class);
|
|
}
|
|
|
|
@Override
|
|
public void configEngine(Engine me) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void configPlugin(Plugins me) {
|
|
// String db_type = PropKit.get(ConstConfig.db_type_key);
|
|
// DruidPlugin druidPlugin = new DruidPlugin(
|
|
// PropKit.get(ConstConfig.db_connection_jdbcUrl),
|
|
// PropKit.get(ConstConfig.db_connection_userName),
|
|
// PropKit.get(ConstConfig.db_connection_passWord),
|
|
// PropKit.get(ConstConfig.db_connection_driverClass));
|
|
//
|
|
// druidPlugin.set(
|
|
// PropKit.getInt(ConstConfig.db_initialSize),
|
|
// PropKit.getInt(ConstConfig.db_minIdle),
|
|
// PropKit.getInt(ConstConfig.db_maxActive));
|
|
//
|
|
// druidPlugin.addFilter(new StatFilter());
|
|
// WallFilter wall = new WallFilter();
|
|
// wall.setDbType(db_type);
|
|
// WallConfig config = new WallConfig();
|
|
// config.setFunctionCheck(false); // 支持数据库函数
|
|
// wall.setConfig(config);
|
|
// druidPlugin.addFilter(wall);
|
|
//
|
|
// ActiveRecordPlugin arp = new ActiveRecordPlugin(ConstConfig.db_dataSource_main, druidPlugin);
|
|
// //arp.setTransactionLevel(4);//事务隔离级别
|
|
// boolean devMode = PropKit.getBoolean(ConstConfig.config_devMode);
|
|
// arp.setDevMode(devMode); // 设置开发模式
|
|
// arp.setShowSql(devMode); // 是否显示SQL
|
|
//
|
|
// arp.setDialect(new MysqlDialect());
|
|
// me.add(druidPlugin); // 多数据源继续添加
|
|
}
|
|
|
|
@Override
|
|
public void configInterceptor(Interceptors me) {
|
|
me.add(new JQueryParameterFilter());
|
|
me.add(new ErrorInterceptor());
|
|
}
|
|
|
|
@Override
|
|
public void configHandler(Handlers me) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void afterJFinalStart() {
|
|
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
|
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
|
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
|
}
|
|
|
|
}
|