JFinal1.1.4 && Jfinal-ext1.1 开发环境搭建【不断更新】

1.导Jar包


2.写一个Config继承com.jfinal.config.JFinalConfig,示例用AppConfig:

package com.demo.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.ext.route.AutoControllerRegist;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.tablebind.AutoTableBindPlugin;
import com.jfinal.plugin.tablebind.TableNameStyle;

public class AppConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants arg0) {
		arg0.setDevMode(true);
	}

	@Override
	public void configHandler(Handlers arg0) {
		
	}

	@Override
	public void configInterceptor(Interceptors arg0) {
		
	}

	@Override
	public void configPlugin(Plugins arg0) {
		//数据库连接池
		loadPropertyFile("dbConfig.properties");
		C3p0Plugin cp = new C3p0Plugin(getProperty("jdbcUrl"),getProperty("username"),getProperty("password"),getProperty("driver"));
		arg0.add(cp);
		//自动绑定表【有了它就不再需要 ActiveRecordPlugin了】
		AutoTableBindPlugin atbp = new AutoTableBindPlugin(cp,TableNameStyle.LOWER);
		arg0.add(atbp);
	}

	@Override
	public void configRoute(Routes arg0) {
		//自动注册路由
		AutoControllerRegist.regist(arg0);
	}

}


3.在web.xml中配置JFinal核心过滤器:

    <filter>
        <filter-name>jfinal</filter-name>
        <filter-class>com.jfinal.core.JFinalFilter</filter-class>
        <init-param>
            <param-name>configClass</param-name>
            <param-value>com.demo.config.AppConfig</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>jfinal</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


4.后续工作:

①写dbConfig.properties,放在WebRoot/WEB-INF文件夹下;

默认的注册规则是截取类名Controller前的部分并首字母小写.

如果需要单独配置Route,需要在Controller上加上ControllerBind注解,例如:

@ControllerBind(controllerKey="/{路由地址}")

一个model自动绑定的表明默认是该类的simpleClassname,如果需要用其他 的命名风格,需要在构造函数中指定,在具体Model上加相应注解,例如:

@TableBind(tableName="{表名}")


你可能感兴趣的:(jFinal,web框架)