• 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
  • 相关阅读:
    《人月神话》阅读笔记02
    学习进度条-4
    课堂作业3
    MySql 8.0及对应驱动包匹配注意点
    关于Ubuntu中Could not get lock /var/lib/dpkg/lock解决方案
    STM32之ADC配置,ADC_Mode模式理解
    STM32串口中断的方式发送
    RTC 与RCC 之间的关系
    stm32 MDK5软件仿真之查看io口输出
    STM32 PWM学习
  • 原文地址:https://www.cnblogs.com/suruozhong/p/6253240.html
Copyright © 2020-2023  润新知