<?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.xsd
http://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";
}

spring mvc + freemarker 整合的更多相关文章

  1. Thymeleaf 3与Spring MVC 4 整合配置

    Thymeleaf 3与Spring MVC 4 整合配置 Maven 依赖配置 Spring 相关依赖就不说了 <dependency> <groupId>org.thyme ...

  2. 玩转spring mvc(四)---在spring MVC中整合JPA

    关于在Spring MVC中整合JPA是在我的上一篇关于spring mvc基本配置基础上进行的,所以大家先参考一下我的上一篇文章:http://blog.csdn.net/u012116457/ar ...

  3. Spring MVC freemarker使用

    什么是 FreeMarker? FreeMarker 是一款 模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页,电子邮件,配置文件,源代码等)的通用工具. 它不是面向最终用 ...

  4. Spring MVC+FreeMarker简介

    最近做项目,刚接触到SpringMVC与FreeMarker框架,就简单介绍一下自己的理解,不正确的地方请大家指教!! 1.Spring MVC工作原理: 用户发送请求--->前端服务器去找相对 ...

  5. spring mvc + freemarker优雅的实现邮件定时发送

    1. spring mvc工程中引入相关freemarker\mail的包 如:pom.xml中加入类似 <dependency> <groupId>javax.mail< ...

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

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

  7. Spring + Spring MVC + MyBatis 整合

    1.所需要Jar包 ? <!-- Spring3.0.1包 -->   org.springframework.web-3.0.1 系列   <!-- 公共包 -->   sl ...

  8. Spring+MVC+Mybatis整合

    本文是对慕课网上"搞定SSM开发"路径的系列课程的总结,详细的项目文档和课程总结放在github上了.点击查看 什么是秒杀业务 网站售卖某产品时,规定在某个日期开始售卖限量的产品, ...

  9. Spring4+Spring MVC+MyBatis整合思路

    1.Spring框架的搭建 这个很简单,只需要web容器中注册org.springframework.web.context.ContextLoaderListener,并指定spring加载配置文件 ...

随机推荐

  1. linux和windows下安装python拓展包及requirement.txt安装类库

    python拓展包安装 直接安装拓展包默认路径: Unix(Linux)默认路径:/usr/local/lib/pythonX.Y/site-packagesWindows默认路径:C:\Python ...

  2. 30个php操作redis常用方法代码例子【转】

    背景:redis这个新产品在sns时很火,而memcache早就存在, 但redis提供出来的功能,好多网站均把它当memcache使用,这是大才小用,这儿有30个方法来使用redis,值得了解. 这 ...

  3. 洛谷P3768 简单的数学题(莫比乌斯反演+狄利克雷卷积+杜教筛)

    传送门 不会…… 两篇加在一起都看不懂…… https://www.cnblogs.com/cellular-automaton/p/8241128.html https://www.luogu.or ...

  4. from appium import webdriver 报错

    from appium import webdriver 报错 看看你的文件是不是就叫appium

  5. CF914D Bash and a Tough Math Puzzle 线段树+gcd??奇怪而精妙

    嗯~~,好题... 用线段树维护区间gcd,按如下法则递归:(记题目中猜测的那个数为x,改动次数为tot) 1.若子区间的gcd是x的倍数,不递归: 2.若子区间的gcd是x的倍数,且没有递归到叶子结 ...

  6. Codeforces Round #561 (Div. 2) A. Silent Classroom

    链接:https://codeforces.com/contest/1166/problem/A 题意: There are nn students in the first grade of Nlo ...

  7. Django -- 权限初识

    待 需求分析-场景 假设需要为公司设计一个人员管理系统,并为各级领导及全体员工分配系统登录账号.有如下几个要求: 1.权限等级不同 公司领导登录后可查看所有员工的信息,部门领导登陆后之可查看本部门员工 ...

  8. PHP全国省市区地址分割提取脚本程序

    github地址: https://github.com/zmxfree/addressapart 比如将 浙江省杭州市江干区XX路X号 分割成 浙江省 杭州市 江干区 XX路X号,方便excel操作 ...

  9. 事务&数据库连接池&DBUtils

    事务的特性 原子性 指的是 事务中包含的逻辑,不可分割. 一致性 指的是 事务执行前后.数据完整性 隔离性 指的是 事务在执行期间不应该受到其他事务的影响 持久性 指的是 事务执行成功,那么数据应该持 ...

  10. mysql 中unsigned

    整型的每一种都分有无符号(unsigned)和有符号(signed)两种类型(float和double总是带符号的),在默认情况下声明的整型变量都是有符号的类型(char有点特别),如果需声明无符号类 ...