佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > spring mvc整合freemarker基于注解方式

spring mvc整合freemarker基于注解方式

熱門標簽:Linux服務器 電子圍欄 Mysql連接數(shù)設置 阿里云 銀行業(yè)務 團購網(wǎng)站 科大訊飛語音識別系統(tǒng) 服務器配置
基于網(wǎng)絡改進為:最正常版本
復制代碼 代碼如下:

?xml version="1.0" encoding="UTF-8"?>
beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    !-- 針對freemarker的視圖配置 -->
    bean id="viewResolver"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        property name="order" value="5" />
        property name="suffix" value=".ftl" />
        property name="contentType" value="text/html;charset=UTF-8" />
    /bean>

     
bean id="freemarkerConfig"
        class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        property name="templateLoaderPath" value="/WEB-INF/view/" />
        property name="freemarkerSettings">
            props>
                prop key="template_update_delay">0/prop>
                prop key="default_encoding">UTF-8/prop>
                prop key="number_format">0.##########/prop>
                prop key="datetime_format">yyyy-MM-dd HH:mm:ss/prop>
                prop key="classic_compatible">true/prop>
                prop key="template_exception_handler">ignore/prop>
            /props>
        /property>
    /bean>

Controller建立
復制代碼 代碼如下:

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SpringMvcController {

    @RequestMapping(value="/welcome",method={RequestMethod.GET}) 
    public ModelAndView getFirstPage(HttpServletRequest request) {
        //welcom就是視圖的名稱(welcom.ftl)
        ModelAndView mv = new ModelAndView("welcom");
        mv.addObject("name", "My First Spring Mvc");
        return mv;
    }
}


在url上敲http://localhost:8080/welcome就會到WEB-INF/view/welcom.ftl頁面渲染數(shù)據(jù)
welcom.ftl頁面
復制代碼 代碼如下:

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
title>Insert title here/title>
/head>
body>
Hello ${name}
/body>
/html>

頁面出來的效果:
Hello My First Spring Mvc
您可能感興趣的文章:
  • 使用SpringBoot注解方式處理事務回滾實現(xiàn)
  • spring boot注解方式使用redis緩存操作示例
  • Spring AOP如何整合redis(注解方式)實現(xiàn)緩存統(tǒng)一管理詳解
  • Spring 使用注解方式進行事務管理配置方式
  • Spring-MVC異步請求之Servlet異步處理
  • springmvc處理異步請求的示例
  • 詳解spring mvc對異步請求的處理
  • SpringMVC環(huán)境下實現(xiàn)的Ajax異步請求JSON格式數(shù)據(jù)
  • Spring中注解方式的異步請求

標簽:棗莊 廣元 衡水 大理 衢州 江蘇 蚌埠 萍鄉(xiāng)

巨人網(wǎng)絡通訊聲明:本文標題《spring mvc整合freemarker基于注解方式》,本文關鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    贵南县| 阿拉善盟| 饶平县| 启东市| 长岭县| 汉阴县| 大化| 隆安县| 太和县| 紫阳县| 贵溪市| 故城县| 钦州市| 南投县| 沙洋县| 峡江县| 华亭县| 且末县| 饶阳县| 乌拉特中旗| 邹平县| 宿迁市| 卢氏县| 遂平县| 泰州市| 星座| 嘉定区| 邓州市| 昌图县| 贵南县| 乐昌市| 双鸭山市| 凉山| 怀集县| 太仆寺旗| 朝阳区| 肇庆市| 海口市| 镇坪县| 文水县| 新乐市|