jfinal实例-北京丰帆佳宇运输有限公司 -凯发k8网页登录

苟有恒,何必三更起五更眠;
最无益,只怕一日曝十日寒.
posts - 241, comments - 318, trackbacks - 0, articles - 16

jfinal实例-北京丰帆佳宇运输有限公司

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("");
            sb.append("alert('禁止重复提交表单!');");
            sb.append("document.location.href='" requestutil.getbasepath(getrequest()) "admin/news/add' ");
            sb.append("");
            renderjavascript(sb.tostring());
            return;
        }else{
            //获取数据
            news news = getmodel(news.class);
            news.set("id", requestutil.getuuid());
            int fwrs = (int) (math.random()*200);
            news.set("fwrs",fwrs);
            news.set("zt", 0);
            
            //图片解析
            
//生成效果图
            string imagepath = getfirstimagepath(news.get("zw") "");
            if(imagepath!=null && !"".equals(imagepath)){
                //保存效果图
                news.set("tj",imagepath);
                
                //生成缩阅图
                string basepath = getsession().getservletcontext().getrealpath("/");
                if(!basepath.endswith("/"))basepath ="/";
                file image = new file(basepath imagepath);
                if(image!=null){
                    int index = imagepath.lastindexof(".");
                    string signimagepath = imagepath.substring(0, index) "_small_170x130" imagepath.substring(index);
                    //system.out.println(signimagepath);
                    file signimage = new file(basepath signimagepath);
                    if(!signimage.exists()){
                        imageutils.buildsmallpic(image, signimage, 170, 130, false);
                    }
                    //保存缩阅图
                    news.set("syt", signimagepath);
                }
            }
            
            //保存
            news.save();
            
            //更新缓存
            
//cachekit.remove("commoncache", "findnewsbypagebean");
            
            
//跳转
            redirect("/admin/news");
        }
    }
    
    
    /** 
     * @title: getfirstimagepath 
     * @description: todo(取得第一张图片作为效果图)
     * 
@return 
     
*/
    private string getfirstimagepath(string source){
        string imagepath = "";
        pattern p = pattern.compile("        matcher m = p.matcher(source);
        if(m.find()){
            imagepath = m.group(1);
        }
        return imagepath;
    }
    
    /** 
     * @title: edit 
     * @description: todo(修改页面) 
     
*/
    public void edit() {
        createtoken("tokenid");
        setattr("news",news.dao.findbyid(getpara("id")));
    }
    
    /** 
     * @title: update 
     * @description: todo(修改保存) 
     
*/
    public void update() {
        if(!validatetoken("tokenid")){
            stringbuilder sb = new stringbuilder();
            sb.append("");
            sb.append("alert('禁止重复提交表单!');");
            sb.append("document.location.href='" requestutil.getbasepath(getrequest()) "admin/news' ");
            sb.append("");
            renderjavascript(sb.tostring());
            return;
        }else{
            //修改
            news news = getmodel(news.class);
            
            //图片解析
            
//生成效果图
            string imagepath = getfirstimagepath(news.get("zw") "");
            if(imagepath!=null && !"".equals(imagepath)){
                //保存效果图
                news.set("tj",imagepath);
                
                //生成缩阅图
                string basepath = getsession().getservletcontext().getrealpath("/");
                if(!basepath.endswith("/"))basepath ="/";
                file image = new file(basepath imagepath);
                if(image!=null){
                    int index = imagepath.lastindexof(".");
                    string signimagepath = imagepath.substring(0, index) "_small_170x130" imagepath.substring(index);
                    //system.out.println(signimagepath);
                    file signimage = new file(basepath signimagepath);
                    if(!signimage.exists()){
                        imageutils.buildsmallpic(image, signimage, 170, 130, false);
                    }
                    //保存缩阅图
                    news.set("syt", signimagepath);
                }
            }
            
            //数据更新
            news.update();
            
            //更新缓存
            
//cachekit.remove("commoncache", "findnewsbypagebean");
            
            
//跳转
            redirect("/admin/news");
        }
    }
    
    /** 
     * @title: del 
     * @description: todo(删除或批量删除) 
     
*/
    public void delete(){
        //删除
        string ids = getpara("id");
        for(string id: ids.split(",")){
            news.dao.deletebyid(id);
        }
        
        //更新缓存
        
//cachekit.remove("commoncache", "findnewsbypagebean");
        
        redirect("/admin/news");
    }
    
    
    /** 
     * @title: check 
     * @description: todo(审核) 
     
*/
    public void check(){
        string ids = getpara("id");
        string zt = getpara("zt");
        for(string id: ids.split(",")){
            news.dao.checknews(id,zt);
        }
        
        //更新缓存
        
//cachekit.remove("commoncache", "findnewsbypagebean");
        
        redirect("/admin/news");
    }

    public void addfwrs(){
        string carid = getpara("newsid");
        news.dao.addfwrs(carid);
        rendertext("增加访问人数成功");
        return;
    }
}


4、freemarker




    
    
    
    
    
    
    ${settings.mc} - 官方网站
    
    
    
    
    
    
    
    
    


    
    class="home_main">
        class="home_neir">
            class="zhuanye">

            class
="yewuinfo" id="j_identity">
                class="kwicks" id="ulkwicks7">
                    

  •                         class="kwicks_inner ks-clear" id="tm_sale">
                                class="bigletter index_tm" href="javascript:void(0);">
                                class="bigletter j_index index_tm_hover" href="javascript:void(0);"> 
                                class="smallletters" href="javascript:void(0);">
                                    class="ywspan hy02">消纳证办理
                                    class="ywnr">公司为客户办理“北京市建筑垃圾消纳许可证”服务 
                                
                               

  •                     
                        

  •                         class="kwicks_inner ks-clear" id="tb_sale">
                                class="bigletter index_tb" href="javascript:void(0);"> 
                                class="bigletter j_index index_tb_hover" href="javascript:void(0);"> 
                                class="smallletters" href="javascript:void(0);" target="_self">
                                    class="ywspan hy01">普通货运
                                    class="ywnr">公司为客户提供优质、快速、便捷、安全的全国货运服务
                                
                            

  •                     
                        

  •                         class="kwicks_inner ks-clear">
                                class="bigletter index_etao" href="javascript:void(0);">
                                class="bigletter j_index index_etao_hover" href="javascript:void(0);"> 
                                class="smallletters" href="javascript:void(0);">
                                    class="ywspan hy03">大型机械设备租赁
                                    class="ywnr">公司为客户提供各类型铲车、挖掘机、破碎锤、渣土运输车辆租赁服务
                                
                            

  •                     
                        

  •                         class="kwicks_inner ks-clear">
                                class="bigletter index_other" href="javascript:void(0);">
                                class="bigletter j_index index_other_hover" href="javascript:void(0);"> 
                                class="smallletters" href="javascript:void(0);">
                                    class="ywspan hy04">土方、建筑、沙石清运
                                    class="ywnr">公司为客户提供土方、建筑、沙石的挖掘、装载、清运等优质服务
                                
                            
                        

  •                 
                
            
        
        class="home_about">
            class="hoab_main">
                class="about_title">
                class="ho_team">
                    class="hotitle">
                    class="teampic">
                    class="teamwz">      北京丰帆佳宇运输有限公司成立于2011年11月16日,注册资金300万,坐落于北京市顺义区龙湾屯镇府前街。公司主要从事普通货运、大型机械设备租赁,土方、建筑垃圾及沙石的清运工作。公司现有员工25名,运输车辆福田十轮自卸车20辆,全部符合《建筑垃圾运输车辆标识、监控和封闭技术要求》,铲车50型5辆,挖掘机300型3台。破碎锤230型1台,并且有自己的修理厂专门服务于所属车队,时刻保持车队良好的运行。
                
                class="carteam">
                    class="hotitle car">
                    class="kache">
                        

                              <#if cars??>
                                  <#list cars as car>
                                          
    • if car.syt??>src="${path}/${car.syt}"if> width="200" height="132">

    •                             
                              if>
                          

                    
                
                class="fllow">
                    class="hotitle car">
                    class="fllow_info">
                        class="weibo">id:${settings.wb}
                          class="weixin">id:${settings.wx}
                    
                      class="add_info">
                        地址:${settings.dz}

                        电话:${settings.zj} 
      
                        手机:${settings.sj}(李月波-总经理)
        
                           13311384678(李志强-副总经理)
                    
                
            
        
        


    kissy.use("brix/gallery/kwicks/",function(s,kwicks){
        var kwicks1 = new kwicks({
            container:'#j_identity',
            tmpl:'#ulkwicks7',
            max:460,
            spacing:79,
            autoplay:false,
            sticky:false
        });
    });
        
    $(function () {
        win_width = document.documentelement.clientwidth;
        var curimgh = math.floor(win_width / 1573 * 352);
        jquery('#slideshow .img').css({ height: curimgh});
        var bannersider=jquery('#slideshow .img').bxslider({
            auto: true,
            speed: 2000
        });
        jquery('#slideshow').mouseenter(function(){
            jquery(this).find(".bx-prev").stop().animate({left:"5%"},400);
            jquery(this).find(".bx-next").stop().animate({right:"5%"},400);
            bannersider.stopauto();
        });
        jquery('#slideshow').mouseleave(function(){
            jquery(this).find(".bx-prev").stop().animate({left:"-5%"},300);
            jquery(this).find(".bx-next").stop().animate({right:"-5%"},300);
            bannersider.startauto();
        });

        $(".main_div_div").hover(function () {
            $(this).find(".ad").stop();
            $(this).find(".ad").fadein(300);
        }, function () {
            $(this).find(".ad").stop();
            $(this).find(".ad").fadeout(300);
        });
    });


    5、静态页面生成器

    package com.bjffjy.core;

    import java.io.bufferedwriter;
    import java.io.file;
    import java.io.fileoutputstream;
    import java.io.ioexception;
    import java.io.outputstreamwriter;
    import java.util.hashmap;
    import java.util.list;

    import com.bjffjy.init.bjffjypropertyregistry;
    import com.bjffjy.model.car;
    import com.bjffjy.model.news;
    import com.bjffjy.model.picture;
    import com.bjffjy.util.pagebean;
    import com.bjffjy.util.resourcemanager;
    import com.jfinal.core.controller;

    import freemarker.template.configuration;
    import freemarker.template.template;

    /**   
     * @title: updatecentercontroller.java
     * @description: todo(数据更新中心控制类) 
     * @author comsys-xcp  
     * @date 2014-7-18 上午11:12:12 
     * @company 北京丰帆佳宇公司 
     
    */
    public class updatecentercontroller extends controller{
        //private static logger log = logger.getlogger(updatecentercontroller.class);
        
    //模板存放文件夹
        private string templatepath;
        //基本路径-网络
        private string basepath ;
        private string basepath2 ;
        //模板传送数据
        private hashmap data = null;
        
        
        public void index(){
            renderjsp("/admin/template/updatecenter.jsp");
        }
        
        public void build(){
            templatepath = getsession().getservletcontext().getrealpath(bjffjypropertyregistry.template_path);
            //basepath = requestutil.getbasepath2(getrequest());
            basepath = resourcemanager.getvalue("basepath");
            basepath2 = basepath   bjffjypropertyregistry.template_path;
            //数据设置
            data = new hashmap();
            data.put("path", basepath);
            data.put("basepath", basepath2);
            data.put("settings",getsession().getservletcontext().getattribute("settings"));
            
            
            string type = getpara("type") "";
            string message = "数据更新中心成功";
            try{
                if(type.equals("1")){//刷新菜单导航
                    buildtop();
                }else if(type.equals("2")){//刷新凯发k8网页登录的版权备案
                    buildbuttom();
                }else if(type.equals("3")){//刷新网站凯发k8网页登录首页
                    buildindex();
                }else if(type.equals("4")){//刷新新闻列表
                    buildnewslist();
                }else if(type.equals("5")){//刷新新闻内容
                    buildnews();
                }else if(type.equals("6")){//刷新公司服务
                    buildservice();
                }else if(type.equals("7")){//刷新车队列表
                    buildcarlist();
                }else if(type.equals("8")){//刷新车队内容
                    buildcar();
                }else if(type.equals("9")){//刷新关于凯发k8网页登录
                    buildabout();
                }else if(type.equals("10")){//刷新全部
                    buildtop();
                    buildbuttom();
                    buildindex();
                    buildnewslist();
                    buildnews();
                    buildservice();
                    buildcarlist();
                    buildcar();
                    buildabout();
                }
            }catch(exception e){
                e.printstacktrace();
                message = "数据更新中心失败";
            }
            
            rendertext(message);
            return;
        }

        /** 
         * @title: buildtop 
         * @description: todo(通过template/default/top.ftl模板文件生成template/default/static/top.html文件)
         
    */
        private void buildtop() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"top.ftl");
            file top = new file(templatepath file.separator "static" file.separator "top.html");
            //获取输出流
            bufferedwriter out = getwriter(top);
            //要传送的数据
            
            
            
    //生在静态页面
            template.process(data, out);
            //关闭流
            if(out!=null){
                out.flush();
                out.close();
            };
        }
        
        /** 
         * @title: buildbuttom 
         * @description: todo(通过template/default/buttom.ftl模板文件生成template/default/static/buttom.html文件)
         * 
    @throws exception 
         
    */
        private void buildbuttom() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"buttom.ftl");
            file top = new file(templatepath file.separator "static" file.separator "buttom.html");
            //获取输出流
            bufferedwriter out = getwriter(top);
            //要传送的数据
            
            
            
    //生在静态页面
            template.process(data, out);
            //关闭流
            if(out!=null){
                out.flush();
                out.close();
            };
        }
        
        /** 
         * @title: buildbuttom 
         * @description: todo(通过template/default/index.ftl模板文件生成template/default/static/index.html文件)
         * 
    @throws exception 
         
    */
        private void buildindex() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"index.ftl");
            file top = new file(templatepath file.separator "static" file.separator "index.html");
            //获取输出流
            bufferedwriter out = getwriter(top);
            //要传送的数据
            
    //查询最新发布的3个车辆信息
            list cars = car.dao.findtop3forindex();
            list pics = picture.dao.findbycustom();
            data.put("cars", cars);
            data.put("pics", pics);
            
            
            //生在静态页面
            template.process(data, out);
            //关闭流
            if(out!=null){
                out.flush();
                out.close();
            };
        }
        
        /** 
         * @title: buildnewslist 
         * @description: todo(通过template/default/newslist.ftl模板文件生成template/default/static/newslist.html文件) 
         
    */
        private void buildnewslist() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"newslist.ftl");
            //获取输出流
            file top = null;
            bufferedwriter out =  null;
            //分页
            pagebean pagebean = new pagebean(1,15);
            
            //全部资讯
            string lx = "0";
            int allcount = news.dao.countnews(lx);
            pagebean.setallrow(allcount);
            pagebean.counttotalpage(allcount);
            boolean hasnext = true;
            string filename = "newslist";
            while(hasnext){
                if(pagebean.getcurrentpage()==1){
                    top = new file(templatepath file.separator "static" file.separator filename ".html");
                }else{
                    top = new file(templatepath file.separator "static" file.separator filename pagebean.getcurrentpage() ".html");
                }
                out = getwriter(top);
                
                //要传送的数据
                list newslist = news.dao.findallnews(lx,pagebean);
                data.put("newslist",newslist);
                data.put("pagebean",pagebean);
                data.put("lx",lx);
                
                //生在静态页面
                template.process(data, out);
                //关闭流
                if(out!=null){
                    out.flush();
                    out.close();
                };
                
                //查询第二页
                if(pagebean.getcurrentpage()                pagebean.setcurrentpage(pagebean.getcurrentpage() 1);
                }else{
                    hasnext = false;
                }
            }
            
            
            //公司动态
            lx = "1";
            int companycount = news.dao.countnews(lx);
            pagebean = new pagebean(1,15);
            pagebean.setallrow(companycount);
            pagebean.counttotalpage(companycount);
            hasnext = true;
            filename = "companylist";
            while(hasnext){
                if(pagebean.getcurrentpage()==1){
                    top = new file(templatepath file.separator "static" file.separator filename ".html");
                }else{
                    top = new file(templatepath file.separator "static" file.separator filename pagebean.getcurrentpage() ".html");
                }
                out = getwriter(top);
                
                //要传送的数据
                list newslist = news.dao.findallnews(lx,pagebean);
                data.put("newslist",newslist);
                data.put("pagebean",pagebean);
                data.put("lx",lx);
                
                //生在静态页面
                template.process(data, out);
                //关闭流
                if(out!=null){
                    out.flush();
                    out.close();
                };
                
                //查询第二页
                if(pagebean.getcurrentpage()                pagebean.setcurrentpage(pagebean.getcurrentpage() 1);
                }else{
                    hasnext = false;
                }
            }
            
            
            //行业信息
            lx = "2";
            int tradecount = news.dao.countnews(lx);
            pagebean = new pagebean(1,15);
            pagebean.setallrow(tradecount);
            pagebean.counttotalpage(tradecount);
            hasnext = true;
            filename = "tradelist";
            while(hasnext){
                if(pagebean.getcurrentpage()==1){
                    top = new file(templatepath file.separator "static" file.separator filename ".html");
                }else{
                    top = new file(templatepath file.separator "static" file.separator filename pagebean.getcurrentpage() ".html");
                }
                out = getwriter(top);
                
                //要传送的数据
                list newslist = news.dao.findallnews(lx,pagebean);
                data.put("newslist",newslist);
                data.put("pagebean",pagebean);
                data.put("lx",lx);
                
                //生在静态页面
                template.process(data, out);
                //关闭流
                if(out!=null){
                    out.flush();
                    out.close();
                };
                
                //查询第二页
                if(pagebean.getcurrentpage()                pagebean.setcurrentpage(pagebean.getcurrentpage() 1);
                }else{
                    hasnext = false;
                }
            }
        }
        
        /** 
         * @title: buildnews 
         * @description: todo(通过template/default/news.ftl模板文件生成template/default/static/news.html文件)
         * 
    @throws exception 
         
    */
        private void buildnews() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"news.ftl");
            //获取输出流
            file top = null;
            bufferedwriter out =  null;
            //全部资讯
            string lx = "0";
            //分页
            pagebean pagebean = new pagebean(1,15);
            int allcount = news.dao.countnews(lx);
            pagebean.setallrow(allcount);
            pagebean.counttotalpage(allcount);
            boolean hasnext = true;
            while(hasnext){
                list newslist = news.dao.findallnews2(lx,pagebean);
                for(news news: newslist){
                    //要传送的数据
                    top = new file(templatepath file.separator "static" file.separator "news" file.separator news.getstr("id") ".html");
                    out = getwriter(top);
                    data.put("news",news);
                    
                    //生在静态页面
                    template.process(data, out);
                    //关闭流
                    if(out!=null){
                        out.flush();
                        out.close();
                    };
                }
                
                //查询第二页
                if(pagebean.getcurrentpage()                pagebean.setcurrentpage(pagebean.getcurrentpage() 1);
                }else{
                    hasnext = false;
                }
            }
        }
        
        /** 
         * @title: buildservice 
         * @description: todo(通过template/default/service.ftl模板文件生成template/default/static/service.html文件)
         * 
    @throws exception 
         
    */
        private void buildservice() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"service.ftl");
            file top = new file(templatepath file.separator "static" file.separator "service.html");
            //获取输出流
            bufferedwriter out = getwriter(top);
            //要传送的数据
            list pics = picture.dao.findbypatner();
            data.put("pics", pics);
            
            //生在静态页面
            template.process(data, out);
            //关闭流
            if(out!=null){
                out.flush();
                out.close();
            };
        }
        
        /** 
         * @title: buildcarlist 
         * @description: todo(通过template/default/carlist.ftl模板文件生成template/default/static/carlist.html文件)
         * 
    @throws exception 
         
    */
        private void buildcarlist() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"carlist.ftl");
            file top = new file(templatepath file.separator "static" file.separator "carlist.html");
            //获取输出流
            bufferedwriter out = getwriter(top);
            //要传送的数据
            list cars = car.dao.findallforindex();
            data.put("cars", cars);
            
            //生在静态页面
            template.process(data, out);
            //关闭流
            if(out!=null){
                out.flush();
                out.close();
            };
        }
        
        /** 
         * @title: buildcar 
         * @description: todo(通过template/default/car.ftl模板文件生成template/default/static/car.html文件)
         * 
    @throws exception 
         
    */
        private void buildcar() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"car.ftl");
            
            //读取所有车辆
            list cars = car.dao.findallforindex();
            file top = null;
            bufferedwriter out =  null;
            string carid = "";
            if(cars!=null){
                data.remove("car");
                data.remove("pics");
                for(car car : cars){
                    carid = car.getstr("id");
                    top = new file(templatepath file.separator "static" file.separator "car" file.separator carid ".html");
                    //获取输出流
                    out = getwriter(top);
                    //要传送的数据
                    list pics = picture.dao.findbyywid("1",carid);
                    if(car.get("bz")==null)car.set("bz", "");
                    data.put("car", car);
                    data.put("pics", pics);
                    
                    //生在静态页面
                    template.process(data, out);
                    //关闭流
                    if(out!=null){
                        out.flush();
                        out.close();
                    };
                }
            }
        }
        
        /** 
         * @title: buildabout 
         * @description: todo(通过template/default/about.ftl模板文件生成template/default/static/about.html文件)
         * 
    @throws exception 
         
    */
        private void buildabout() throws exception{
            //读取模板
            template template = gettemplate(templatepath,"about.ftl");
            file top = new file(templatepath file.separator "static" file.separator "about.html");
            //获取输出流
            bufferedwriter out = getwriter(top);
            //要传送的数据
            list pics = picture.dao.findbyzzry();
            data.put("pics", pics);
            
            
            //生在静态页面
            template.process(data, out);
            //关闭流
            if(out!=null){
                out.flush();
                out.close();
            };
        }

        /** 
         * @title: getconfiguration 
         * @description: todo(获取模板文件夹)
         * 
    @throws ioexception 
         
    */
        private configuration getconfiguration(string templatepath) throws ioexception{
            configuration cfg = new configuration();
            cfg.setdefaultencoding("utf-8");
            cfg.setdirectoryfortemplateloading(new file(templatepath));
            return cfg;
        }
        /** 
         * @title: gettemplate 
         * @description: todo(获取模板文件)
         * 
    @param templatepath 模板文件夹路径
         * 
    @param templatename 模板文件名称
         * 
    @throws ioexception 
         
    */
        private template gettemplate(string templatepath,string templatename)throws ioexception{
            configuration cfg = getconfiguration(templatepath);
            template template = cfg.gettemplate(templatename);
            template.setencoding("utf-8");
            return template;
        }
        
        /** 
         * @title: getwriter 
         * @description: todo(获取缓冲输出流)
         * 
    @param file 输出文件
         
    */
        private  bufferedwriter getwriter(file file) throws exception{
            if(file!=null && file.exists()) file.delete();
            bufferedwriter bw = new bufferedwriter(new outputstreamwriter(new fileoutputstream(file),"utf-8"));
            return bw;
        }
    }






    名称: ♪4c.esl | .↗evon
    口号: 遇到新问题♪先要寻找一个方案乄而不是创造一个方案こ
    mail:


    网站地图