<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"><!--<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/templates/" /><property name="suffix" value=".ftl" /></bean>--><mvc:annotation-driven /><context:component-scan base-package="com.bingco" /><!--配置freemarker视图解析器 --><bean id="freemarkerConfig"class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"><property name="templateLoaderPath" value="/WEB-INF/templates/" /></bean><bean id="viewResolver"class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"><property name="suffix" value=".ftl" /><property name="contentType" value="text/html; charset=UTF-8" /></bean></beans>

  这是单独使用的Demo:

@GetMapping("/getHtml")public String method2() throws IOException, TemplateException {Configuration configuration = new Configuration(Configuration.VERSION_2_3_22);configuration.setDirectoryForTemplateLoading(Paths.get(templates_path + File.separator).toFile());configuration.setDefaultEncoding("UTF-8");configuration.setTemplateExceptionHandler(TemplateExceptionHandler.DEBUG_HANDLER);String tempName = "test.ftl";Template template = configuration.getTemplate(tempName);Map<String, Object> map = new HashMap<>();map.put("message", "Hello World Java !");File file = new File("D:/temp/" + tempName.substring(0, tempName.indexOf(".") + 1) + "html");if (!file.exists()) {try (Writer out = new OutputStreamWriter(new FileOutputStream(file))) {template.process(map, out);out.flush();System.out.println("\t-- over --");}}return "redirect:/index.jsp";}

转载于:https://www.cnblogs.com/bingco/p/8716568.html

spring mvc + freemarker 整合相关推荐

  1. Spring+ Spring mvc+MyBatis整合

    Spring+ Spring mvc+MyBatis整合 目录结构 (1) 修改web.xml配置文件的内容 (2) 添加mybatis.spring mvc.spring database的xml文 ...

  2. Spring Spring MVC Hibernate 整合备忘

    以下为此三种框架整合配置的详细备注,以及部分问题备忘 项目结构和配置文件可访问 Github 查看 1. pom.xml 尽量使用 Maven 管理项目依赖以减少包引入时的麻烦,以及避免跨开发工具问题 ...

  3. ssm整合说明与模板-Spring Spring MVC Mybatis整合开发

    ssm整合说明 spring+spring mvc+mybatis 说明 源码下载 由于之前存在ssh框架,spring+struts+hibernate,其中spring负责aop与ioc,所以一般 ...

  4. Spring注解驱动开发第53讲——Servlet 3.0与Spring MVC的整合分析

    写在前面 在前两讲中,我们说了一下ServletContainerInitializer机制以及如何利用ServletContext向web容器中注册Servlet.Listener以及Filter这 ...

  5. shiro +spring + spring mvc+ mybatis整合【转】

    2019独角兽企业重金招聘Python工程师标准>>> CREATE TABLE `sys_permission` ( `id` bigint(20) NOT NULL COMMEN ...

  6. 【jeecg-mybatis版本】 mybatis+spring mvc 完美整合方案 查询,保存,更新,删除自动生成

      Jeecg-mybatis-framework 版本 简要说明 JEECG[J2EE Code Generation]是一款基于代码生成器的J2EE智能开发框架,借助该框架可以节省50%的工作量, ...

  7. mybatis+spring mvc 完美整合方案 查询,保存,更新,删除自动生成

    Jeecg-Mybatis版本代码生成器演示视频 代码下载:JEECG-mybatis参考学习版本 简要说明  JEECG[J2EE Code Generation]  代码生成:根据表生成对应的Be ...

  8. 【jeecg-mybatis版本】 mybatis+spring mvc 完美整合方案 查询,保存,更新,删除自动生成...

    Jeecg-Mybatis版本代码生成器演示视频 http://pan.baidu.com/share/link?shareid=243717&uk=2668473880   简要说明  JE ...

  9. spring mvc项目中利用freemarker生成自定义标签

    2019独角兽企业重金招聘Python工程师标准>>> spring mvc项目中利用freemarker生成自定义标签 博客分类: java spring mvc +freemar ...

最新文章

  1. PHP爬取企业详情(百度信用)
  2. 在路上---学习篇(一)Python 数据结构和算法 (4) --希尔排序、归并排序
  3. 6264:走出迷宫(DFS和BFS)
  4. java 微信退款接口_java版微信和支付宝退款接口
  5. 金蝶云星空操作手册_金蝶国际CFO林波谈云业务:金蝶云·星空预计今年可以实现盈利...
  6. 总的秒数等于几小时几分钟几秒(Python)
  7. 查找最接近的元素c语言,查找最接近的元素
  8. 模块间同步消息队列的设计
  9. android studio:aar文件出现问号,导入不生效解决
  10. 18 张图彻底弄懂 HTTPS 的原理!
  11. Linux 给用户 赋某个文件夹操作的权限
  12. 班级学生总成绩和平均成绩计算
  13. linux中iptables乱码,xshell连接CentOS6.5 iptables或ls 输出乱码-Go语言中文社区
  14. 2021黑龙江人高考成绩查询,2021年黑龙江高考成绩查询网站查分网址:https://www.lzk.hl.cn/...
  15. ILSVRC-ImageNet历年竞赛冠军
  16. 2021 IT运维调查报告
  17. 一文搞懂移动端单位em、rem、vh、vw
  18. 高斯投影正反算C语言程序代码,一个老师给的高斯投影正反算c++源码.doc
  19. 程序阅读_全面详解LTE:MATLAB建模仿真与实现_自学笔记(1)调制与编码_程序阅读
  20. 为intent添加FLAG_EXCLUDE_STOPPED_PACKAGES标记

热门文章

  1. 最常用最好记Linux命令
  2. 会声会影如何渲染高清视频
  3. 老男孩学习之亲身经历心得
  4. kettle 遇到 解决Incorrect integer value: '' for column 'id' at row 1 完美解决-费元星
  5. 不仅仅是虚拟化--Windows 7 SP1 Windows 2008R2 SP1解析
  6. win7(64)与samba不兼容
  7. 配置System Center Data Protection Manager 2007
  8. DataGrid 中的特殊应用
  9. what should you do if you want to become an expert in one domain
  10. formal method lecture 11