spring mvc3.2.16+freemarker+tiles3为什么不能正常工作

controller

 @Controller
@RequestMapping("/welcome")
public class WelcomeController {

    @RequestMapping(value = "/index")
    public ModelAndView welcomeIndex(HttpServletRequest request) {

    String param = request.getParameter("param");
    if("1".equals(param)) {
        ModelAndView mav = new ModelAndView("index");
        return mav;
    } else {
        ModelAndView mav = new ModelAndView("welcome.index.def");
        return mav;
    }


}

}

spring-mvc.xml

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass">
        <value>org.springframework.web.servlet.view.tiles2.TilesView</value>
    </property>
</bean>

<bean id="tilesConfigurer"
    class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions">
        <list>
            <value>/WEB-INF/tiles-defs.xml</value>
        </list>
    </property>
</bean>

<bean id="viewResolverFtl" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
    <property name="prefix" value="/" />
    <property name="suffix" value=".ftl" />
    <property name="contentType" value="text/html;charset=utf-8" />
    <property name="viewClass">
        <value> com.unicompay.framework.basedata.web.common.FreeMarkerView </value>
    </property>
</bean> 

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="defaultEncoding" value="UTF-8" />
    <property name="templateLoaderPath" value="/WEB-INF/views/" />
    <property name="freemarkerSettings" ref="freemarkerConfiguration" />
</bean>

<bean id="freemarkerConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="classpath:conf/freemarker.properties" />
</bean>


tiles-defs,xml
<?xml version="1.0" encoding="UTF-8" ?> 

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<!-- 基础模版定义 -->
<definition name="mt.base.def" template="/WEB-INF/views/common/layout.ftl"  >
    <put-attribute name="content" value="/WEB-INF/views/common/content.ftl" type="freemarker"/>
    <put-attribute name="footer" value="/WEB-INF/views/common/footer.ftl" />
</definition>

<definition name="welcome.index.def" extends="mt.base.def">
    <put-attribute name="content" value="/WEB-INF/views/index.ftl" type="freemarker" />
</definition>

layout,ftl

 <#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"]>
<@tiles.insertAttribute name="content" />
<@tiles.insertAttribute name="footer" />




查看全部
ivan2306
Ivan2306
2016/01/25 09:22
  • spring
  • 点赞
  • 收藏
  • 回答
    私信

2个回复