spring mvc + freemarker 整合
<?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 整合的更多相关文章
- Thymeleaf 3与Spring MVC 4 整合配置
Thymeleaf 3与Spring MVC 4 整合配置 Maven 依赖配置 Spring 相关依赖就不说了 <dependency> <groupId>org.thyme ...
- 玩转spring mvc(四)---在spring MVC中整合JPA
关于在Spring MVC中整合JPA是在我的上一篇关于spring mvc基本配置基础上进行的,所以大家先参考一下我的上一篇文章:http://blog.csdn.net/u012116457/ar ...
- Spring MVC freemarker使用
什么是 FreeMarker? FreeMarker 是一款 模板引擎: 即一种基于模板和要改变的数据, 并用来生成输出文本(HTML网页,电子邮件,配置文件,源代码等)的通用工具. 它不是面向最终用 ...
- Spring MVC+FreeMarker简介
最近做项目,刚接触到SpringMVC与FreeMarker框架,就简单介绍一下自己的理解,不正确的地方请大家指教!! 1.Spring MVC工作原理: 用户发送请求--->前端服务器去找相对 ...
- spring mvc + freemarker优雅的实现邮件定时发送
1. spring mvc工程中引入相关freemarker\mail的包 如:pom.xml中加入类似 <dependency> <groupId>javax.mail< ...
- ssm整合说明与模板-Spring Spring MVC Mybatis整合开发
ssm整合说明 spring+spring mvc+mybatis 说明 源码下载 由于之前存在ssh框架,spring+struts+hibernate,其中spring负责aop与ioc,所以一般 ...
- Spring + Spring MVC + MyBatis 整合
1.所需要Jar包 ? <!-- Spring3.0.1包 --> org.springframework.web-3.0.1 系列 <!-- 公共包 --> sl ...
- Spring+MVC+Mybatis整合
本文是对慕课网上"搞定SSM开发"路径的系列课程的总结,详细的项目文档和课程总结放在github上了.点击查看 什么是秒杀业务 网站售卖某产品时,规定在某个日期开始售卖限量的产品, ...
- Spring4+Spring MVC+MyBatis整合思路
1.Spring框架的搭建 这个很简单,只需要web容器中注册org.springframework.web.context.ContextLoaderListener,并指定spring加载配置文件 ...
随机推荐
- qscoj#19D(单调队列)
题目链接:http://qscoj.cn/problem/130/ 题意:中文题诶- 思路:直接用单调栈搞一下就好了 代码: #include <bits/stdc++.h> using ...
- vjudge个人赛 复习1
A - 大鱼吃小鱼(栈) 有N条鱼每条鱼的位置及大小均不同,他们沿着X轴游动,有的向左,有的向右.游动的速度是一样的,两条鱼相遇大鱼会吃掉小鱼.从左到右给出每条鱼的大小和游动的方向(0表示向左,1表示 ...
- django 模版 语法与使用
目录 django 模版语法与使用 django模板语言介绍 (摘自官方文档) 链接 什么是模板? 模板语句的 注释 变量 {{ 变量 }} 点(.)在模板语言中有特殊的含义,用来获取对象的相应属性值 ...
- tableview中用动画效果改变cell的高度
我们要的效果大概就是如下效果: 当我们选择一个cell的时候,我们就要改变它的高度,并且以动画的形式. 我们该如何实现这个效果呢?我们主要需要使用以下这两个方法: - (CGFloat)tableVi ...
- 源码分析(一) 进程cleos的命令解析
EOS版本:4.0 一.进程cleos的作用 cleos,即为client eos.从名字就可以猜出来,它是一个标准的客户端程序,而实际上,它也确实为一个标准的client^_^ 准确地说 ...
- day2逻辑运算作业详解
1.day2题目 1.判断下列逻辑语句的True,False. 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 &l ...
- CF438D The Child and Sequence 线段树
给定数列,区间查询和,区间取模,单点修改. n,m小于10^5 ...当区间最值小于模数时,就直接返回就好啦~ #include<cstdio> #include<iostream& ...
- 2019湘潭校赛 G(并查集)
要点 题目传送 题目本质是每个点必属于两个集合中的一个,伴随的性质是:如果一个人说别人true,则他们一定属于同一阵营:如果说别人fake,一定不属于同一阵营. 每个点拆为\(i\)和\(i + n\ ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) C
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two poi ...
- Django - CRM项目(3)
一.CRM项目的业务逻辑与表结构梳理 1.分析业务逻辑 (1) 引流(sem) (2) 网络咨询师(客服):添加客户信息和查看客户,分配销售 (3) 销售:查看私户 添加跟进记录 失败:加入公户 成功 ...