谁能给我指点 Spring MVC、Tiles、Freemarker 集成示例?

发布于 2024-07-07 19:14:36 字数 169 浏览 8 评论 0原文

在我基于 Spring MVC 的应用程序中,我使用 Freemarker 并且非常喜欢它,但它缺乏复合视图模式提供的优势。

我正在考虑尝试将 Tiles2 与 Freemarker 一起使用 - 有谁知道我在哪里可以找到 SpringMVC 与 Tiles2+Freemarker 一起使用的简单示例?

In my Spring MVC based applications i use Freemarker and i like it very much, but it's lacking advantages provided by Composite View pattern.

I'm thinking of trying to use Tiles2 together with Freemarker - does anyone know where do i find a simple example of SpringMVC together with Tiles2+Freemarker?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

折戟 2024-07-14 19:14:37

没关系,我已经解决了。 我只需在图块定义文件中指定 freemarker 模板

<definition name="template" template="/WEB-INF/ftl/main.ftl">

,并将 freemarker servlet/映射添加到

<servlet>
    <servlet-name>freemarker</servlet-name>
    <servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>

    <!-- FreemarkerServlet settings: -->
    <init-param>
        <param-name>TemplatePath</param-name>
        <param-value>/</param-value>
    </init-param>
    <init-param>
        <param-name>NoCache</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>ContentType</param-name>
        <param-value>text/html</param-value>
    </init-param>

    <!-- FreeMarker settings: -->
    <init-param>
        <param-name>template_update_delay</param-name>
        <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
    </init-param>
    <init-param>
        <param-name>default_encoding</param-name>
        <param-value>ISO-8859-1</param-value>
    </init-param>
    <init-param>
        <param-name>number_format</param-name>
        <param-value>0.##########</param-value>
    </init-param>

    <load-on-startup>5</load-on-startup>
</servlet>  

 <servlet-mapping>
    <servlet-name>freemarker</servlet-name>
    <url-pattern>*.ftl</url-pattern>
 </servlet-mapping>

spring 配置中的 web.xml 中,将图块指定为我的主要视图引擎

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

nevermind, i've solved it. i just had to specify freemarker templates in tiles definitions file

<definition name="template" template="/WEB-INF/ftl/main.ftl">

and add freemarker servlet/maping to web.xml

<servlet>
    <servlet-name>freemarker</servlet-name>
    <servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>

    <!-- FreemarkerServlet settings: -->
    <init-param>
        <param-name>TemplatePath</param-name>
        <param-value>/</param-value>
    </init-param>
    <init-param>
        <param-name>NoCache</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>ContentType</param-name>
        <param-value>text/html</param-value>
    </init-param>

    <!-- FreeMarker settings: -->
    <init-param>
        <param-name>template_update_delay</param-name>
        <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
    </init-param>
    <init-param>
        <param-name>default_encoding</param-name>
        <param-value>ISO-8859-1</param-value>
    </init-param>
    <init-param>
        <param-name>number_format</param-name>
        <param-value>0.##########</param-value>
    </init-param>

    <load-on-startup>5</load-on-startup>
</servlet>  

 <servlet-mapping>
    <servlet-name>freemarker</servlet-name>
    <url-pattern>*.ftl</url-pattern>
 </servlet-mapping>

in spring configuration specify tiles as my primary view engine

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/defs/definitions.xml</value>
            </list>
        </property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>
臻嫒无言 2024-07-14 19:14:37

另一种可以代替 Tiles 的产品是 SiteMesh,我在一些应用程序中使用过它。 值得一看。

Another product you could use instead of Tiles is SiteMesh, which I've used in some apps. It's worth checking out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文