posted on 2014-09-07 20:43
xcp 阅读(7872)
评论(0) 编辑 收藏 所属分类:
java
前面学习了一个开源框架jfinal,并用此框架开发了一个实例网站现进行分享.
公司名称:凯发天生赢家一触即发官网的简介:渣土消纳证办理,大型支护土方深度开挖,矿山暗挖,基坑开挖,建筑垃圾清运,渣土清运,砂石料配送,工程机械租赁业务
公司网址:
1、框架jfinal
freemarker mysql
2、web.xml
xml version="1.0" encoding="utf-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xsi:schemalocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>北京丰帆佳宇运输有限公司display-name>
<filter>
<filter-name>jfinalfilter-name>
<filter-class>com.jfinal.core.jfinalfilterfilter-class>
<init-param>
<param-name>configclassparam-name>
<param-value>com.bjffjy.config.bjffjyconfigparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>jfinalfilter-name>
<url-pattern>/*url-pattern>
filter-mapping>
<session-config>
<session-timeout>30session-timeout>
session-config>
<listener>
<listener-class>com.bjffjy.listener.sessioncounterlistener-class>
listener>
<context-param>
<param-name>log4jconfiglocationparam-name>
<param-value>classpath:log4j.propertiesparam-value>
context-param>
<servlet>
<servlet-name>settingsservletservlet-name>
<servlet-class>com.bjffjy.servlet.settingsservletservlet-class>
<load-on-startup>0load-on-startup>
servlet>
<servlet>
<servlet-name>connectorservletservlet-name>
<servlet-class>com.ckfinder.connector.connectorservletservlet-class>
<init-param>
<param-name>xmlconfigparam-name>
<param-value>/web-inf/config.xmlparam-value>
init-param>
<init-param>
<param-name>debugparam-name>
<param-value>falseparam-value>
init-param>
<load-on-startup>1load-on-startup>
servlet>
<servlet-mapping>
<servlet-name>connectorservletservlet-name>
<url-pattern>/resource/js/ckfinder/core/connector/java/connector.javaurl-pattern>
servlet-mapping>
<servlet-mapping>
<servlet-name>connectorservletservlet-name>
<url-pattern>/ckfinder/core/connector/java/connector.javaurl-pattern>
servlet-mapping>
<filter>
<filter-name>fileuploadfilterfilter-name>
<filter-class>com.ckfinder.connector.fileuploadfilterfilter-class>
<init-param>
<param-name>sessioncookienameparam-name>
<param-value>jsessionidparam-value>
init-param>
<init-param>
<param-name>sessionparameternameparam-name>
<param-value>jsessionidparam-value>
init-param>
filter>
<filter-mapping>
<filter-name>fileuploadfilterfilter-name>
<url-pattern>/resource/js/ckfinder/core/connector/java/connector.javaurl-pattern>
filter-mapping>
<filter-mapping>
<filter-name>fileuploadfilterfilter-name>
<url-pattern>/ckfinder/core/connector/java/connector.javaurl-pattern>
filter-mapping>
<error-page>
<error-code>404error-code>
<location>/error.jsp?key=404location>
error-page>
<error-page>
<error-code>500error-code>
<location>/error.jsp?key=500location>
error-page>
web-app>
3、核心控制类
package com.bjffjy.config;
import com.alibaba.druid.filter.stat.statfilter;
import com.alibaba.druid.wall.wallfilter;
import com.bjffjy.interceptor.authinterceptor;
import com.bjffjy.model.car;
import com.bjffjy.model.news;
import com.bjffjy.model.picture;
import com.bjffjy.model.settings;
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.plugin.activerecord.activerecordplugin;
import com.jfinal.plugin.activerecord.dialect.mysqldialect;
import com.jfinal.plugin.activerecord.tx.txbyactionmethods;
import com.jfinal.plugin.druid.druidplugin;
import com.jfinal.plugin.druid.druidstatviewhandler;
import com.jfinal.plugin.ehcache.ehcacheplugin;
import com.jfinal.render.viewtype;
/**
* @title: bjffjyconfig.java
* @description: todo(总配置器)
* @author comsys-xcp
* @date 2014-7-6 下午05:22:49
* @company 北京丰帆佳宇运输有限公司
*/
public class bjffjyconfig extends jfinalconfig{
@override
public void configconstant(constants me) {
me.setdevmode(true);
loadpropertyfile("config.properties");
me.seterror404view("/error.jsp?key=400");
me.seterror500view("/error.jsp?key=500");
me.setviewtype(viewtype.jsp);
}
@override
public void configroute(routes me) {
me.add(new frontroutes());
me.add(new adminroutes());
}
@override
public void configinterceptor(interceptors me) {
//用户登录权限过滤
me.add(new authinterceptor());
//声明式事务处理
me.add(new txbyactionmethods("save","update","delete","batch"));
}
@override
public void configplugin(plugins me) {
//缓存插件
/*string ehcacheconf = pathkit.getwebrootpath() file.separator "web-inf" file.separator "ehcache.xml";
me.add(new ehcacheplugin(ehcacheconf)); */
me.add(new ehcacheplugin());
//数据源插件
druidplugin dp = new druidplugin(getproperty("jdbc.url"),getproperty("jdbc.username"), getproperty("jdbc.password"));
dp.addfilter(new statfilter());
wallfilter wall = new wallfilter();
wall.setdbtype("mysql");
dp.addfilter(wall);
me.add(dp);
//activerecord插件
activerecordplugin arp = new activerecordplugin(dp);
arp.setdialect(new mysqldialect()).setshowsql(true);
me.add(arp);
//添加映射
arp.addmapping("s_settings", settings.class);
arp.addmapping("b_news", news.class);
arp.addmapping("b_car", car.class);
arp.addmapping("b_picture", picture.class);
}
@override
public void confighandler(handlers me) {
druidstatviewhandler dvh = new druidstatviewhandler("/druid");
me.add(dvh);
}
}
package com.bjffjy.config;
import com.bjffjy.core.admincontroller;
import com.bjffjy.core.carcontroller;
import com.bjffjy.core.logincontroller;
import com.bjffjy.core.newscontroller;
import com.bjffjy.core.picturecontroller;
import com.bjffjy.core.settingscontroller;
import com.bjffjy.core.templatecontroller;
import com.bjffjy.core.updatecentercontroller;
import com.jfinal.config.routes;
/**
* @title: adminroutes.java
* @description: todo(后台管理路由器)
* @author comsys-xcp
* @date 2014-7-6 下午09:57:21
* @company 北京丰帆佳宇公司
*/
public class adminroutes extends routes{
@override
public void config() {
/**系统登录*/
add("/login",logincontroller.class);
add("/admin",admincontroller.class);
add("/admin/**,settingscontroller.class);
add("/admin/**",templatecontroller.class);
add("/admin/**",updatecentercontroller.class);
add("/admin/**",newscontroller.class);
add("/admin/**",carcontroller.class);
add("/admin/**",picturecontroller.class);
}
}
package com.bjffjy.config;
import com.bjffjy.core.indexcontroller;
import com.jfinal.config.routes;
/**
* @title: frontroutes.java
* @description: todo(前台管理路由器)
* @author comsys-xcp
* @date 2014-7-6 下午10:01:10
* @company 北京丰帆佳宇公司
*/
public class frontroutes extends routes{
@override
public void config() {
/**凯发k8网页登录首页展示*/
add("/", indexcontroller.class);
}
}
package com.bjffjy.config;
import javax.servlet.http.httpservletrequest;
import javax.servlet.http.httpservletresponse;
import com.jfinal.handler.handler;
/**
* @title: sessionhandler.java
* @description: todo(freemarker session)
* 因为 jfinal 提倡 restful 的 不建议使用 session
* 如果要在页面获取session 需要自己设置 一个handler 将session 放入request中
* http://www.oschina.net/question/582302_59626?sort=default&p=1
* @author comsys-xcp
* @date 2014-7-17 下午05:11:23
* @company *****公司
*/
public class sessionhandler extends handler {
@override
public void handle(string target, httpservletrequest request, httpservletresponse response, boolean[] ishandled) {
request.setattribute("session", request.getsession());
nexthandler.handle(target, request, response, ishandled);
}
}
package com.bjffjy.core;
import java.io.file;
import java.util.hashmap;
import java.util.map;
import java.util.regex.matcher;
import java.util.regex.pattern;
import com.bjffjy.model.news;
import com.bjffjy.util.imageutils;
import com.bjffjy.util.requestutil;
import com.jfinal.core.controller;
import com.jfinal.plugin.activerecord.page;
/**
* @title: newscontroller.java
* @description: todo(新闻信息控制类)
* @author comsys-xcp
* @date 2014-7-18 上午11:14:23
* @company 北京丰帆佳宇公司
*/
public class newscontroller extends controller{
/**
* @title: index
* @description: todo(列表查询)
*/
public void index(){
map querywhere = new hashmap();
//查询条件
querywhere.put("lx", getpara("news.lx"));
querywhere.put("bt", getpara("news.bt"));
querywhere.put("zt", getpara("news.zt"));
//分页
string currentpage = getpara("pagebean.currentpage");
string pagesize = getpara("pagebean.pagesize");
if(currentpage==null || currentpage.equals(""))currentpage = "1";
if(pagesize==null || pagesize.equals(""))pagesize = "15";
querywhere.put("currentpage",integer.parseint(currentpage));
querywhere.put("pagesize",integer.parseint(pagesize));
page newspage = news.dao.findbypagebean(querywhere);
setattr("newspage", newspage);
setattr("querywhere", querywhere);
render("list.jsp");
}
/**
* @title: add
* @description: todo(新增页面)
*/
public void add() {
createtoken("tokenid");
}
/**
* @title: save
* @description: todo(新增保存)
*/
public void save() {
if(!validatetoken("tokenid")){
stringbuilder sb = new stringbuilder();
sb.append("
4、freemarker
${settings.mc} - 官方网站
class
="yewuinfo" id="j_identity">
class="kwicks" id="ulkwicks7">