springmvc集成Freemarke配置的几点
项目结构图

废话不多说, 集成步骤:
1.web.xml spring-mvc配置
<?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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><welcome-file-list><welcome-file>upload.jsp</welcome-file></welcome-file-list><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:com/springfreemark/config/spring/spring-core.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><servlet><servlet-name>spring-mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:com/springfreemark/config/spring/springmvc-servlet.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet><description>This is the description of my J2EE component</description><display-name>This is the display name of my J2EE component</display-name><servlet-name>FreekMarkerServlet</servlet-name><servlet-class>com.springfreemark.web.servlet.FreekMarkerServlet</servlet-class></servlet><servlet-mapping><servlet-name>spring-mvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><servlet-mapping><servlet-name>FreekMarkerServlet</servlet-name><url-pattern>*.ftl</url-pattern></servlet-mapping></web-app>
2. spring-mvc 配置文件
<?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:p="http://www.springframework.org/schema/p"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.0.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc-3.0.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><context:component-scan base-package="com.springfreemark.web" /><mvc:annotation-driven /><mvc:default-servlet-handler /><bean id="fmXmlEscape"class="freemarker.template.utility.XmlEscape" /><bean id="freemarkerConfig"class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer"><property name="templateLoaderPath" value="/WEB-INF/ftl/" /><property name="freemarkerVariables"><map><entry key="xml_escape" value-ref="fmXmlEscape" /><entry key="webRoot" value="${webRoot}"></entry><entry key="jsRoot" value="${jsRoot}"></entry></map></property><!-- FreeMarker默认每隔5秒检查模板是否被更新,如果已经更新了,就会重新加载并分析模板。 但经常检查模板是否更新可能比较耗时。如果你的应用运行在生产模式下,而且你预期模板不会经常更新,则可以将更新的延迟时间延长至一个小时或者更久。 可以通过为freemarkerSettings属性设置template_update_delay达到这一目的 --><property name="freemarkerSettings"><props><prop key="template_update_delay">3600</prop><prop key="tag_syntax">auto_detect</prop><!-- 设置标签类型 两种:[] 和 <> 。[] 这种标记解析要快些 --><prop key="default_encoding">UTF-8</prop><prop key="output_encoding">UTF-8</prop><prop key="locale">zh_CN</prop><prop key="date_format">yyyy-MM-dd</prop><prop key="time_format">HH:mm:ss</prop><prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop><prop key="number_format">#</prop><!-- 设置数字格式 以免出现 000.00 --><prop key="classic_compatible">true</prop><!-- 可以满足一般需要。默认情况变量为null则替换为空字符串,如果需要自定义,写上${empty!"EmptyValue of fbysss"}的形式即可 --><prop key="template_exception_handler">html_debug</prop><!-- ignore,debug,html_debug,rethrow --></props></property><!-- 一下语句可以也可以配置freemarkerSettings属性,代码更为简洁 --><!-- <property name="freemarkerSettings" ref="freemarkerConfiguration"></property> --></bean><!-- 配置freeMarker视图解析器 --><bean id="viewResolver"class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver"><property name="viewClass"value="org.springframework.web.servlet.view.freemarker.FreeMarkerView" /><property name="viewNames" value="*.ftl" /><property name="contentType" value="text/html; charset=utf-8" /><property name="cache" value="true" /><property name="suffix" value="" /><property name="order" value="2" /></bean><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"><property name="maxUploadSize" value="104857600"/><property name="maxInMemorySize" value="4096"/></bean></beans>
3.DataController.java 逻辑控制
package com.springfreemark.web.controller;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Component;import org.springframework.web.bind.annotation.RequestMapping;@Component@RequestMapping("/main/")public class DataController extends BaseController {@RequestMapping("go")public String exec(HttpServletRequest request){request.getSession().setAttribute("name", "springfreemark集成成功");return "/demo.ftl";}}
输入地址 : http://localhost:8080/SpringFreeMarker/main/go
ok 大功告成

附件列表
springmvc集成Freemarke配置的几点的更多相关文章
- spring-mvc集成 swagger
问题1:spring-mvc集成 swagger, 配置好后界面 404, 原因: dispatcher-servlet.xml 文件中, 要在这上面 <!-- 启用spring mvc 注解 ...
- EhCache WebCache 与 SpringMVC集成时 CacheManager冲突的问题
转自:点击打开链接 http://www.cnblogs.com/daxin/p/3560989.html EhCache WebCache 与 SpringMVC集成时 CacheManager冲突 ...
- SpringMVC 集成velocity
前言 没有美工的时代自然少不了对应的模板视图开发,jsp时代我们用起来也很爽,物极必反,项目大了,数据模型复杂了jsp则无法胜任. 开发环境 idea2016.jdk1.8.tomcat8.0.35 ...
- SpringMVC集成rabbitmq:优化秒杀下单环节
前言 上一篇在springboot中基于自动配置集成了rabbitmq.那么回到最初的话题中就是想在秒杀下单环节增加排队机制,从而达到限流的目的. 优化秒杀下单流程 之前是在控制器里拿到客户端请求后直 ...
- SpringMVC集成springfox-swagger2自动生成接口文档
本节内容: 什么是Swaggger Springfox与Swagger的关系 SpringMVC集成springfox-swagger2 一.什么是Swaggger Swagger是一个流行的API开 ...
- MP实战系列(十)之SpringMVC集成SpringFox+Swagger2
该示例基于之前的实战系列,如果公司框架是使用JDK7以上及其Spring+MyBatis+SpringMVC/Spring+MyBatis Plus+SpringMVC可直接参考该实例. 不过建议最好 ...
- spring集成mybatis配置多个数据源,通过aop自动切换
spring集成mybatis,配置多个数据源并自动切换. spring-mybatis.xml如下: <?xml version="1.0" encoding=" ...
- Spring学习之旅(六)--SpringMVC集成
对大多数 Java 开发来说,基于 web 的应用程序是我们主要的关注点. Spring 也提供了对于 web 的支持,基于 MVC 模式的 Spring MVC 能够帮助我们灵活和松耦合的完成 we ...
- 从零开始学 Java - Spring 集成 ActiveMQ 配置(一)
你家小区下面有没有快递柜 近两年来,我们收取快递的方式好像变了,变得我们其实并不需要见到快递小哥也能拿到自己的快递了.对,我说的就是类似快递柜.菜鸟驿站这类的代收点的出现,把我们原来快递小哥必须拿着快 ...
随机推荐
- 如何架设部署V2EX社区/论坛(Google App Engine版)
1.What's V2EX? 关于这个问题,我们可以看看其作者Livid早期自己的V2EX社区的介绍: What's V2EX? 这是很多人都问过的问题,而我一直都没有做出一个明确的解答.因为我实在觉 ...
- MySQL-关于并发下的mysql_insert_id()
我们在写数据库程序的时候, 经常会需要获取某个表中的最大序号数, 或者刚插入的数据的ID值, 一般情况下获取刚插入的数据的id, 使用select max(id) from table 是可以的, 但 ...
- 【C++】关于带const的指针问题
区分const出现在*前还是*后 前: 例如const int *p,这种表示情况下,p本身可以改变,即p可以指向不同的地址, 但是p指向的内容不可改变. 就像你喜欢看书,图书馆规定你可以任意借阅及更 ...
- Google C++单元测试框架
一.概述 Google C++单元测试框架(简称Gtest),可在多个平台上使用(包括Linux, Mac OS X, Windows, Cygwin和Symbian),它提供了丰富的断言.致命和非致 ...
- Python学习笔记020——数据库基本操作
本数据库的操作是Linux虚拟机平台下进行的 1 启动和链接MySQL服务 1.1 服务端 (1)查看服务状态 sudo /etc/init.d/mysql stauts (2)启动服务端 sudo ...
- epoll 系列函数简介、与select、poll 的区别
一.epoll 系列函数简介 #include <sys/epoll.h> int epoll_create(int size); int epoll_create1(int flags) ...
- MySQL Proxy 实现 MySQL 读写分离提高并发负载
还在学习,学完了在写笔记 (这个先安装lua:https://www.cnblogs.com/fps2tao/p/9163959.html ) 工作拓扑: MySQL Proxy有一项强大功能是实现“ ...
- textureCache中的等价路径问题
自己的引擎里做了个简单的TextueCache,每次新创建一个纹理,先到TextureCache里查找有没有路径相同的,如果有就直接返回纹理,如果没有加载图片创建纹理并将图片路径缓存起来.另外为了标准 ...
- Windows上怎么安装ELK
In this guide I will show that it is also possible to run Logstash on a Windows Server 2012 machine ...
- Linux内存管理机制中buffer和cache的区别
Linux内存管理机制中buffer和cache的区别理解linux内存管理,需要深入了解linux内存的各个参数含义和规则,下面介绍一下Linux操作系统中内存buffer和cache的区别. Fr ...