package com.sandu.common.config; import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.ext.interceptor.SessionInViewInterceptor;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.JspRender;
import com.jfinal.render.ViewType;
import com.sandu.admin.interceptor.AdminInterceptor;
import com.sandu.admin.interceptor.GlobalActionInterceptor;
import com.sandu.admin.model._MappingKit;
import com.sandu.common.handler.CommonHandler; public class MainConfig extends JFinalConfig { /**
* 配置jfinal常量值
*/
@Override
public void configConstant(Constants me) {
//设置默认视图jsp
me.setViewType(ViewType.JSP);
//读取配置文件
PropKit.use("config.properties");
//设置当前是否为开发模式
me.setDevMode(PropKit.getBoolean("devMode"));
//设置文件上传路径
String fileUploadPath = "upload/image";
me.setBaseUploadPath(fileUploadPath);
//JspRender对HttpServletRequest对象中的数据进行了处理,数据全被放入了Map之中,设置数据不被处理
JspRender.setSupportActiveRecord(true);
} /**
* 配置接口的映射
*/
@Override
public void configRoute(Routes me) {
me.add(new AdminRoutes());
me.add(new WeixinRoutes());
} /**
* 配置数据库映射
*/
@Override
public void configPlugin(Plugins me) {
//配置数据库连接池插件
C3p0Plugin c3p0Plugin=new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password"));
//orm映射 配置ActiveRecord插件
ActiveRecordPlugin arp=new ActiveRecordPlugin(c3p0Plugin);
arp.setContainerFactory(new CaseInsensitiveContainerFactory());//忽略数据库字段大小写
arp.setShowSql(true);
//数据库表与model映射
_MappingKit.mapping(arp);
//添加到插件列表中
me.add(c3p0Plugin);
me.add(arp);
} @Override
public void configInterceptor(Interceptors me) {
//添加拦截器
me.add(new GlobalActionInterceptor());
me.addGlobalServiceInterceptor(new AdminInterceptor());
//处理session传递数据找不到属性
me.add(new SessionInViewInterceptor());
} @Override
public void configHandler(Handlers me) { } public static void main(String[] args) {
JFinal.start("WebRoot", 80, "/", 5);
} }