freemarker 模版静态化
来源:互联网 发布:校园网络安全教育讲座 编辑:程序博客网 时间:2024/06/06 03:13
- public void consultaionToHtml(String cid) {
- try {
- this.publicOpenId= PropertiesUtils.getPropertiesValue("aloan.openid");
- String cityHtml="";
- GDSMConsultaion vo = gdsmconsultaionService.getObjectById(GDSMConsultaion.class, cid);
- String remarks="";
- if(null!=vo&&null!=vo.getRemarks()){
- if(vo.getRemarks().equals("0")){
- remarks="以上文章内容来源于网络,不代表本公司立场和观点,如有侵权请与我们联系。";
- }else if(vo.getRemarks().equals("1")){
- remarks="以上文章内容来源于宜信月刊(微信ID:yixinyuekan)。";
- }else if(vo.getRemarks().equals("2")){
- remarks="以上内容为原创内容,转发请注明来自宜信普惠金融家。";
- }
- }
- if(null!=vo&&vo.getConsultaionType().equals("cheats")&&vo.getContentLink()==null){
- Map map = new HashMap();
- map.put("consultaionId",vo.getId());
- map.put("title",vo.getTitle());
- map.put("time",StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM-dd"));
- map.put("content",vo.getContent().replaceAll(ResourceLocator.GEDAI_CONSULTAION_PIC_PATH,getSiteUrl()+"/"+ResourceLocator.GEDAI_CONSULTAION_PIC_PATH));
- map.put("path",getSiteUrl());
- map.put("remarks",remarks);
- String path = ResourceLocator.getResourceAbsoluteLocationPath(ResourceLocator.GEDAI_CONSULTAION_HTML_PATH);
- this.ouputFile("comCheats.ftl", vo.getId()+".html", map,path+"/cheats/"+StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM"));
- }else if(null!=vo&&!vo.getConsultaionType().equals("cheats")){
- String functiontype="";
- if(vo.getConsultaionType().equals("essay")){
- functiontype="ESSAY";
- }else if(vo.getConsultaionType().equals("info")){
- functiontype="CONSULTAION";
- }
- List<GDSMCity> cityList=gdManagerService.getGDCityLevel1();
- for(GDSMCity city : cityList){
- cityHtml=cityHtml+"<option value='"+city.getCityCode()+"'>"+city.getCityName()+"</option>";
- }
- String imgurl="";
- if(vo!=null&&vo.getLogoUrl()!=null){
- imgurl=getSiteUrl() +"/"+ ResourceLocator.GEDAI_CONSULTAION_PIC_PATH +"/"+vo.getLogoUrl();
- }else{
- imgurl=getSiteUrl() + "/img/weixin/gdSelfMarketing/logo1.png";
- }
- Map map = new HashMap();
- map.put("publicOpenId",publicOpenId);
- map.put("consultaionId",vo.getId());
- map.put("title",vo.getTitle());
- map.put("time",StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM-dd"));
- map.put("content",vo.getContent().replaceAll(ResourceLocator.GEDAI_CONSULTAION_PIC_PATH,getSiteUrl()+"/"+ResourceLocator.GEDAI_CONSULTAION_PIC_PATH));
- map.put("cityHtml",cityHtml);
- map.put("path",getSiteUrl());
- map.put("shareImageUrl",imgurl);
- map.put("shareDesc","宜信为没有受到传统金融体系重视的高成长性人群提供普惠金融服务宜信普惠。");
- map.put("remarks",remarks);
- map.put("functiontype",functiontype);
- String path = ResourceLocator.getResourceAbsoluteLocationPath(ResourceLocator.GEDAI_CONSULTAION_HTML_PATH);
- for(GDSMCity city : cityList){
- this.ouputFile("comProduct.ftl", vo.getId()+".html", map,path+"/"+city.getCityCode()+"/"+StaticMethod.formatDateToString(vo.getCreateTime(), "yyyy-MM"));
- }
- logger.info("资讯【ID={}】静态化生成成功。", cid);
- }
- } catch (Exception e) {
- logger.info("资讯【ID={}】静态化生成失败。",cid);
- logger.error(e.getMessage(), e);
- }
- }
- public void ouputFile(String ftlName, String fileName, Map<String, Object> map,String path) throws Exception{
- //创建fm的配置
- Configuration config = new Configuration();
- //指定默认编码格式
- config.setDefaultEncoding("UTF-8");
- //设置模板的包路径
- config.setClassForTemplateLoading(this.getClass(), "/com/yixin/gdSelfMarketing/ftl");
- //获得包的模板
- Template template = config.getTemplate(ftlName);
- //指定文件输出的路径
- File file=new File(path+"/"+fileName);
- File parent = file.getParentFile();
- if (!parent.exists()) {
- parent.mkdirs();
- }
- //定义输出流,注意的必须指定编码
- Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path+"/"+fileName)),"UTF-8"));
- //生成模板
- template.process(map, writer);
- writer.close();
- }
3.访问生成的html文件
阅读全文
0 0
- freemarker 模版静态化
- freemarker 模版静态化
- freemarker页面静态化
- freemarker 静态化使用
- FreeMarker页面静态化
- freemarker静态化例子
- freemarker静态化页面
- freemarker静态化页面
- 使用freemarker静态化
- Freemarker 页面静态化
- freemarker静态化网页
- 页面静态化 Freemarker
- Freemarker页面静态化
- 网页静态化freemarker
- Freemarker网页静态化
- 网页静态化--Freemarker
- Freemarker 页面静态化
- 利用freemarker 静态化网页
- 简单写个好理解的Builder设计模式
- sql时间参数输出
- Pie
- 数据结构与算法分析(Java语言描述)(30)—— 有权图的实现
- HDFS实现其高可靠性的策略及机制
- freemarker 模版静态化
- “敲代码”学编程的正确方式
- 《HTTP权威指南》学习笔记(1)第1章HTTP概述(关键词:计算机网络/HTTP)
- 【Tensorflow slim】 slim.arg_scope的用法
- Android L版本上codegen.dws文件的路径.docx
- 木乃伊迷宫
- C语言编程之函数调用规则
- YuvI420转Jpeg
- 匠牛社区AM5728 CannyOpencl实例