2 ivan2306 ivan2306 于 2016.01.25 17:22 提问

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" />




2个回答

devmiao
devmiao   Ds   Rxr 2016.01.25 21:09
Royal_lr
Royal_lr   Ds   Rxr 2016.01.26 14:14

不知道你指的不正常是什么样的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!