springmvc velocity toolbox 配置

1.springmvc

<!-- 设置视图解析工具 -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver">
        <property name="suffix" value=".vm"/>
        <!-- 避免乱码 -->
        <property name="contentType" value="text/html;charset=UTF-8"/>
        <!--<property name="toolboxConfigLocation" value="/WEB-INF/views/layout/toolbox.xml" />-->
        <property name="dateToolAttribute" value="dateTool"/>
        <property name="numberToolAttribute" value="numberTool"/>
        <property name="exposeRequestAttributes" value="true"/>
        <property name="exposeSessionAttributes" value="true"/>
        <property name="layoutUrl" value="layout/layout.vm"/>
        <property name="order" value="0"/>
        <property name="toolboxConfigLocation" value="/WEB-INF/views/layout/toolbox.xml" />
        <property name="viewClass" value="com.tanbao.common.VelocityToolbox20View" />
    </bean>

2.VelocityToolbox20View

public class VelocityToolbox20View extends VelocityLayoutView {

    @Override
    protected Context createVelocityContext(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ViewToolContext ctx;

        ctx = new ViewToolContext(getVelocityEngine(), request, response,
                getServletContext());

        ctx.putAll(model);

        if (this.getToolboxConfigLocation() != null) {
            ToolManager tm = new ToolManager();
            tm.setVelocityEngine(getVelocityEngine());
            tm.configure(getServletContext().getRealPath(
                    getToolboxConfigLocation()));
            if (tm.getToolboxFactory().hasTools(Scope.REQUEST)) {
                ctx.addToolbox(tm.getToolboxFactory().createToolbox(
                        Scope.REQUEST));
            }
            if (tm.getToolboxFactory().hasTools(Scope.APPLICATION)) {
                ctx.addToolbox(tm.getToolboxFactory().createToolbox(
                        Scope.APPLICATION));
            }
            if (tm.getToolboxFactory().hasTools(Scope.SESSION)) {
                ctx.addToolbox(tm.getToolboxFactory().createToolbox(
                        Scope.SESSION));
            }
        }
        return ctx;
    }
}

3.toolbox.xml

<?xml version="1.0" encoding="UTF-8"?>
<tools>
<toolbox scope="application">
    <!-- <tool key="map" class="java.util.HashMap"/> -->
    <tool key="env" class="com.tanbao.common.EnvContext"/>
</toolbox>
</tools>
时间: 2024-07-29 16:56:19

springmvc velocity toolbox 配置的相关文章

SpringMVC框架入门配置 IDEA下搭建Maven项目

,初衷:本人初学SpringMVC的时候遇到各种稀奇古怪的问题,网上各种技术论坛上的帖子又参差不齐,难以一步到位达到配置好的效果,这里我将我配置的总结写到这里供大家初学SpringMVC的同僚们共同学习使用! 关于SpringMVC的介绍我就不在此赘述了,想必每一个配置Spring的人都已经或多或少了解过一些SpringMVC的基础知识,可能有的人用的myeclipse或者eclipse进行项目的搭建,我会告诉你这里步骤是很相似的,在myeclipse里面需要建立web项目,然后加入Spring

SpringMVC+springSecurity+flexPaper 配置--类似百度文库在线预览

背景:现在项目需要做一个类似百度文库的在线预览功能,在网上找了下很多人推荐使用FlexPaper,所以今天尝试学习了FlexPaper顺便集成到现有的框架中 由于网上目前的说的都不是很详细,所以现在记录在此,希望对需要的人有所帮助 准备:1. FlexPaper_2.2.4.zip 下载地址:http://flexpaper.devaldi.com/download/             2.swftools 下载地址:http://www.swftools.org/download.htm

idea spring+springmvc+mybatis环境配置整合详解

idea spring+springmvc+mybatis环境配置整合详解 1.配置整合前所需准备的环境: 1.1:jdk1.8 1.2:idea2017.1.5 1.3:Maven 3.5.2 2.查看idea中是否安装Maven插件: 2.1:File --> Settings --> Plugins 2.2:如下图所示的步骤进行操作(注:安装完插件,idea会重新启动) 3.idea创建Maven项目的步骤 4.搭建目录结构 下图就是我搭建Maven项目之后,添加对应的目录和文件 5.p

SpringMVC加载配置Properties文件的几种方式

最近开发的项目使用了SpringMVC的框架,用下来感觉SpringMVC的代码实现的非常优雅,功能也非常强大, 网上介绍Controller参数绑定.URL映射的文章都很多了,写这篇博客主要总结一下SpringMVC加载配置Properties文件的几种方式 通过读取Config文件的配置例如: Map<String, String> group = ConfigurationManager.GetConfiguration("config1"); this.setBcp

springmvc web.xml配置之SpringMVC IOC容器初始化

SpringMVC IOC容器初始化 首先强调一下SpringMVC IOC容器初始化有些特别,在SpringMVC中除了生成一个全局的spring Ioc容器外,还会为DispatcherServlet生成一个容器,具体的下一篇有讲述. 我们知道spring中单纯使用main函数就可以生成一个容器,如下: public class MainTest { public static void main(String[] args){ ApplicationContext appContext =

022 修改springmvc的默认配置

一 .概述 在springboot之中,springmvc的默认配置都是配置好的,但是在我们使用的过程之中需要对默认的配置进行修改. 本节,我们完成对springmvc的默认配置的修改, [1]了解springmvc的自动配置原理 [2]修改springmvc的默认配置. 二 .springmvc的自动配置原理 springboot在默认情况进行对springmvc进行了配置,我们首先看一下自动配置类. WebMvcAutoConfiguration在这个类之中帮助我们配置好了springmvc

7、springmvc的自动配置

1.springmvc的自动配置 文档:https://docs.spring.io/spring-boot/docs/2.1.1.RELEASE/reference/htmlsingle/#boot-features-spring-mvc WebMvcAutoConfiguration.java Spring Boot 自动配置好了SpringMVC 以下是SpringBoot对SpringMVC的默认配置:(WebMvcAutoConfiguration) * Inclusion of Co

为什么springboot中引入WebMvcConfigurationSupport后SpringMvc的自动配置失效了

在SpringBoot的官方文档中,可以看到, 如果想保持Spring Boot MVC原本的配置(自动配置)并且又想增加自己的配置,那么add your own @Configuration class of type WebMvcConfigurer but without @EnableWebMvc 当使用@EnableWebMvc,在这个类中可以看到 可以看到EnableWebMvc这个类里通过import引入 @Configuration 注解的类——DelegatingWebMvcC

springMVC:为MultipartFilte配置了上传文件解析器,报错或不能使用

一.问题描述为支持restful风格请求,并且应对可能上传文件的情况,需要在配置hiddenHttpMethodFilter过滤器之前配置MultipartFilter.目的是让MultipartFilter过滤器先将带文件上传的请求,进行解析.以便hiddenHttpMethodFilter可以取到”_method”参数,转化为相应的http动作. 既然multipartFilter要进行上传文件的解析,那么必然需要MutipartResolver,那么问题发生了! 二.报错:Unable t