- c3p0.properties:连接数据库
driver=com.mysql.jdbc.Driver jdbcUrl = jdbc:mysql://localhost:3306/test username = root password = root
- 定义一个类集成JFinalConfig类
import com.jfinal.config.*; import com.jfinal.kit.PropKit; import com.jfinal.plugin.activerecord.ActiveRecordPlugin; import com.jfinal.plugin.c3p0.C3p0Plugin; import com.jfinal.render.ViewType; public class MyJfinalConfig extends JFinalConfig { /** * 配置常量 * @param constants */ @Override public void configConstant(Constants constants) { constants.setViewType(ViewType.JSP); //读取外部文件 PropKit.use("c3p0.properties"); } /** * 配置访问路由 * @param routes */ @Override public void configRoute(Routes routes) { routes.add("/users",UsersController.class); } /** * 配置插件 * @param plugins */ @Override public void configPlugin(Plugins plugins) { //配置连接池 //输入库连接池 C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("username"), PropKit.get("password")); //ORM Activerecord ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin); arp.setShowSql(true); arp.addMapping("users", Users.class); plugins.add(c3p0Plugin); plugins.add(arp); } /** * 全局拦截器 * @param interceptors */ @Override public void configInterceptor(Interceptors interceptors) { } /** * 控制器 * @param handlers */ @Override public void configHandler(Handlers handlers) { } }
JFinal配置c3p0连接池
最新推荐文章于 2021-02-11 03:08:05 发布