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

spring mvc整合freemarker基于注解方式

熱門標簽:百度ai地圖標注 同安公安400電話怎么申請流程 合肥電銷外呼系統(tǒng)哪家公司做的好 玉林市機器人外呼系統(tǒng)哪家好 蘋果手機凱立德地圖標注 申請400電話手續(xù) 南陽外呼系統(tǒ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中注解方式的異步請求

標簽:南京 南昌 淄博 臺州 海南 揚州 南京 嘉興

巨人網(wǎng)絡通訊聲明:本文標題《spring mvc整合freemarker基于注解方式》,本文關鍵詞  spring,mvc,整合,freemarker,基于,;如發(fā)現(xiàn)本文內容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《spring mvc整合freemarker基于注解方式》相關的同類信息!
  • 本頁收集關于spring mvc整合freemarker基于注解方式的相關信息資訊供網(wǎng)民參考!
  • 推薦文章