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

spring mvc整合freemarker基于注解方式

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

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

    !-- 針對(duì)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建立
復(fù)制代碼 代碼如下:

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就會(huì)到WEB-INF/view/welcom.ftl頁面渲染數(shù)據(jù)
welcom.ftl頁面
復(fù)制代碼 代碼如下:

!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注解方式處理事務(wù)回滾實(shí)現(xiàn)
  • spring boot注解方式使用redis緩存操作示例
  • Spring AOP如何整合redis(注解方式)實(shí)現(xiàn)緩存統(tǒng)一管理詳解
  • Spring 使用注解方式進(jìn)行事務(wù)管理配置方式
  • Spring-MVC異步請(qǐng)求之Servlet異步處理
  • springmvc處理異步請(qǐng)求的示例
  • 詳解spring mvc對(duì)異步請(qǐng)求的處理
  • SpringMVC環(huán)境下實(shí)現(xiàn)的Ajax異步請(qǐng)求JSON格式數(shù)據(jù)
  • Spring中注解方式的異步請(qǐng)求

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

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

    • 400-1100-266