zoukankan      html  css  js  c++  java
  • beetl 配置多视图解析器

    如下配置,指定了三个视图解析器,一个用于beetl页面渲染,一个用于cms,采用了beetl技术,另外一个一些遗留的页面采用jsp

    <bean name="beetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init">
            <property name="configFileResource" value="/WEB-INF/beetl.properties"/>
    </bean>
    
    
    <bean name="cmsbeetlConfig" class="org.beetl.ext.spring.BeetlGroupUtilConfiguration" init-method="init">
            <property name="configFileResource" value="/WEB-INF/cms-beetl.properties"/>
    </bean>
    
    
    <!-- Beetl视图解析器1 -->
    <bean name="beetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
            <!-- 多视图解析器,需要设置viewNames和order -->
            <property name="viewNames">
                    <list>
                            <value>/template/**</value>
                    </list>
            </property>
            <property name="suffix" value=".btl"/>
            <property name="contentType" value="text/html;charset=UTF-8"/>
            <property name="order" value="0"/>
            <!-- 多GroupTemplate,需要指定使用的bean -->
            <property name="config" ref="beetlConfig"/>
    
    </bean>
    
    <!-- Beetl视图解析器2 -->
    <bean name="cmsBeetlViewResolver" class="org.beetl.ext.spring.BeetlSpringViewResolver">
            <!-- 多视图解析器,需要设置viewNames和order -->
            <property name="viewNames">
                    <list>
                            <value>/cmstemplate/**</value>
                    </list>
            </property>
            <property name="contentType" value="text/html;charset=UTF-8"/>
            <property name="order" value="1"/>
            <!-- 多GroupTemplate,需要指定使用的bean -->
            <property name="config" ref="cmsbeetlConfig"/>
    
    </bean>
    
    <!-- JSP视图解析器 -->
    <bean name="JSPViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- 注意JSP的这个视图解析器order必须在最后 -->
            <property name="order" value="256"/>
            <!-- beetl配置不支持前缀,这不同于jsp 和 freemaker -->
            <property name="prefix" value="/WEB-INF/"/>
            <property name="suffix" value=".jsp"/>
            <property name="contentType" value="text/html;charset=UTF-8"/>
    </bean>

    Beetl视图解析器属性同spring自带的视图解析器一样,支持contentType,order,prefix,suffix等属性。

    注意视图解析器里属性viewNames,这个用于判断controller返回的path到底应该交给哪个视图解析器来做。

    • 以/template开头的是beetlViewResolver来渲染。

    • 以/cmstemplate是交给cmsBeetlViewResolver渲染。

    • 如果都没有匹配上,则是jsp渲染

    如果你想更改此规则,你只能增加canHandle方法指定你的逻辑了。详情参考org.springframework.web.servlet.view.UrlBasedViewResolver.canHandle

    对于仅仅需要redirect和forward的那些请求,需要加上相应的前缀

    • 以"redirect:"为前缀时:表示重定向,不产生BeetlView渲染模版,而直接通过Servlet的机制返回重定向响应.redirect:前缀后面的内容为重定向地址,可以采用相对地址(相对当前url),绝对地址(完整的url),如果采用/开头的地址,会自动的在前面接上当前Web应用的contextPath,即contextPath为test的Web应用中使用redirect:/admin/login.html 实际重定向地址为 /test/admin/login.html

    • 以"forward:"为前缀时:表示转发,不产生BeetlView渲染模版。而是直接通过Servlet的机制转发请求(关于转发和重定向的区别,请自行查看Servlet API) forward:前缀后面的内容为转发地址,一般都是以/开头相对于当前Web应用的根目录

    其他集成需要注意的事项:

    • spring集成,请不要使用spring的 前缀配置,改用beetl的RESOURCE.ROOT 配置,否则include,layout会找不到模板

  • 相关阅读:
    c#文件操作
    c#关于udp远程关闭一个连接问题
    c#面向对象之多态
    在Eclipse上安装Activiti插件
    引入Activiti配置文件activiti.cfg.xml
    mysql笔记(暂时)
    MySQL创建用户与授权方法
    javaweb学习总结(五)——Servlet开发(一)
    Linux常用命令1
    Eureka注册中心高可用集群配置
  • 原文地址:https://www.cnblogs.com/go-skill/p/6106562.html
Copyright © 2011-2022 走看看