首先,你要配置web.xml文件:
<filter> <filter-name>jfinal</filter-name> <filter-class>com.jfinal.core.JFinalFilter</filter-class> <init-param> <param-name>configClass</param-name> <param-value>Demo.demoConfig</param-value> </init-param> </filter> <filter-mapping> <filter-name>jfinal</filter-name>//不变的东东 <url-pattern>/*</url-pattern> </filter-mapping> 其中,<param-value>Demo.demoConfig</param-value> 这个是自己下的配置文件,一定不能写错(src下,Demo包下的demoConfig.java文件)。
然后你需要写一个小文件config.txt,放在src文件夹下:
jdbcUrl = jdbc:mysql://127.0.0.1/estqq?characterEncoding=utf8&zeroDateTimeBehavior=convertToNulluser = rootpassword =123devMode = true
接着就是写好demoConfig.java这个文件了:
写好configConstant(Constants me),configRoute(Routes me),configPlugin(Plugins me), configInterceptor(Interceptors me),configHandler(Handlers me)下的配置。其中应该注意的是常量,路由和插件三个方面。值得注意的是数据源,我用的C3P0:
// 配置C3p0数据库连接池插件 C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"),getProperty("user"), getProperty("password").trim()); me.add(c3p0Plugin);// 配置ActiveRecord插件 ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin); me.add(arp);紧接着,你需要Model层和Controller层代码的设计和编写了。这里根据你自己的项目而不同。但基本的步骤应该是一样的,在model层做好大部分数据库的操作方法,然后在Controller层的action中调用model层的那些方法,返回页面渲染。我一般是在model层做好大量的数据库的操作,这样controller层就不会显得臃肿。在action中使用getModel真是很爽的,谁用谁知道。
最后,就是前端页面的代码编写了,我用的jsp,在常量配置中定义页面渲染视图为:
me.setViewType(ViewType.JSP)
171

被折叠的 条评论
为什么被折叠?



