2017-02-16 16:36:22 +08:00
|
|
|
package cn.cloudowr.dict;
|
|
|
|
|
|
2017-02-20 13:36:55 +08:00
|
|
|
import cn.cloudowr.sdk.jfinal.ErrorInterceptor;
|
2017-11-21 15:57:16 +08:00
|
|
|
import cn.cloudowr.sdk.jfinal.JQueryParameterFilter;
|
2017-02-16 16:36:22 +08:00
|
|
|
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;
|
2017-11-21 15:57:16 +08:00
|
|
|
import java.util.Properties;
|
2017-02-16 16:36:22 +08:00
|
|
|
|
2017-11-23 15:59:10 +08:00
|
|
|
import static cn.cloudowr.dict.Main.*;
|
|
|
|
|
|
2017-02-16 16:36:22 +08:00
|
|
|
/**
|
|
|
|
|
* Created by lyf66 on 2017/2/16.
|
|
|
|
|
*/
|
|
|
|
|
public class Config extends com.jfinal.config.JFinalConfig{
|
|
|
|
|
|
|
|
|
|
private static MongoDatabase mongoDatabase;
|
2017-11-23 15:59:10 +08:00
|
|
|
|
2017-02-16 16:36:22 +08:00
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configInterceptor(Interceptors me) {
|
2017-02-19 09:51:44 +08:00
|
|
|
me.add(new JQueryParameterFilter());
|
2017-02-20 13:36:55 +08:00
|
|
|
me.add(new ErrorInterceptor());
|
2017-02-16 16:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configHandler(Handlers me) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterJFinalStart() {
|
2017-11-21 15:57:16 +08:00
|
|
|
MongoCredential mongoCredential = MongoCredential.createCredential(username, database, password.toCharArray());
|
|
|
|
|
MongoClient mongoClient = new MongoClient(new ServerAddress(host, port), Arrays.asList(mongoCredential));
|
|
|
|
|
mongoDatabase = mongoClient.getDatabase(dabaseName);
|
2017-02-16 16:36:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static MongoDatabase getMongoDataBase() {
|
|
|
|
|
return mongoDatabase;
|
|
|
|
|
}
|
2017-11-23 15:59:10 +08:00
|
|
|
|
2017-11-21 15:57:16 +08:00
|
|
|
}
|