JFinalConfig配置
1 package com.sandu.common.config; 2 3 import com.jfinal.config.Constants; 4 import com.jfinal.config.Handlers; 5 import com.jfinal.config.Interceptors; 6 import com.jfinal.config.JFinalConfig; 7 import com.jfinal.config.Plugins; 8 import com.jfinal.config.Routes; 9 import com.jfinal.core.JFinal; 10 import com.jfinal.ext.interceptor.SessionInViewInterceptor; 11 import com.jfinal.kit.PropKit; 12 import com.jfinal.plugin.activerecord.ActiveRecordPlugin; 13 import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory; 14 import com.jfinal.plugin.c3p0.C3p0Plugin; 15 import com.jfinal.render.JspRender; 16 import com.jfinal.render.ViewType; 17 import com.sandu.admin.interceptor.AdminInterceptor; 18 import com.sandu.admin.interceptor.GlobalActionInterceptor; 19 import com.sandu.admin.model._MappingKit; 20 import com.sandu.common.handler.CommonHandler; 21 22 public class MainConfig extends JFinalConfig { 23 24 /** 25 * 配置jfinal常量值 26 */ 27 @Override 28 public void configConstant(Constants me) { 29 //设置默认视图jsp 30 me.setViewType(ViewType.JSP); 31 //读取配置文件 32 PropKit.use("config.properties"); 33 //设置当前是否为开发模式 34 me.setDevMode(PropKit.getBoolean("devMode")); 35 //设置文件上传路径 36 String fileUploadPath = "upload/image"; 37 me.setBaseUploadPath(fileUploadPath); 38 //JspRender对HttpServletRequest对象中的数据进行了处理,数据全被放入了Map之中,设置数据不被处理 39 JspRender.setSupportActiveRecord(true); 40 } 41 42 /** 43 * 配置接口的映射 44 */ 45 @Override 46 public void configRoute(Routes me) { 47 me.add(new AdminRoutes()); 48 me.add(new WeixinRoutes()); 49 } 50 51 /** 52 * 配置数据库映射 53 */ 54 @Override 55 public void configPlugin(Plugins me) { 56 //配置数据库连接池插件 57 C3p0Plugin c3p0Plugin=new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password")); 58 //orm映射 配置ActiveRecord插件 59 ActiveRecordPlugin arp=new ActiveRecordPlugin(c3p0Plugin); 60 arp.setContainerFactory(new CaseInsensitiveContainerFactory());//忽略数据库字段大小写 61 arp.setShowSql(true); 62 //数据库表与model映射 63 _MappingKit.mapping(arp); 64 //添加到插件列表中 65 me.add(c3p0Plugin); 66 me.add(arp); 67 } 68 69 @Override 70 public void configInterceptor(Interceptors me) { 71 //添加拦截器 72 me.add(new GlobalActionInterceptor()); 73 me.addGlobalServiceInterceptor(new AdminInterceptor());
//处理session传递数据找不到属性
me.add(new SessionInViewInterceptor()); 74 } 75 76 @Override 77 public void configHandler(Handlers me) { 78 79 } 80 81 public static void main(String[] args) { 82 JFinal.start("WebRoot", 80, "/", 5); 83 } 84 85 } 86