校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

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

spring mvc整合freemarker基于注解方式

熱門標簽:百度ai地圖標注 同安公安400電話怎么申請流程 合肥電銷外呼系統哪家公司做的好 玉林市機器人外呼系統哪家好 蘋果手機凱立德地圖標注 申請400電話手續 南陽外呼系統定制化 預測式外呼系統使用說明 電話機器人軟件銷售工作
基于網絡改進為:最正常版本
復制代碼 代碼如下:

?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頁面渲染數據
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注解方式處理事務回滾實現
  • spring boot注解方式使用redis緩存操作示例
  • Spring AOP如何整合redis(注解方式)實現緩存統一管理詳解
  • Spring 使用注解方式進行事務管理配置方式
  • Spring-MVC異步請求之Servlet異步處理
  • springmvc處理異步請求的示例
  • 詳解spring mvc對異步請求的處理
  • SpringMVC環境下實現的Ajax異步請求JSON格式數據
  • Spring中注解方式的異步請求

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

巨人網絡通訊聲明:本文標題《spring mvc整合freemarker基于注解方式》,本文關鍵詞  spring,mvc,整合,freemarker,基于,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《spring mvc整合freemarker基于注解方式》相關的同類信息!
  • 本頁收集關于spring mvc整合freemarker基于注解方式的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 连山| 长寿区| 霸州市| 正宁县| 金华市| 嘉荫县| 丹棱县| 巫溪县| 三都| 水富县| 浠水县| 镇雄县| 丰顺县| 南康市| 武平县| 琼海市| 柞水县| 会理县| 冀州市| 松江区| 于都县| 芦溪县| 兴安县| 五峰| 临安市| 元谋县| 贞丰县| 威海市| 镇原县| 杂多县| 库车县| 花莲市| 肥西县| 旬阳县| 资溪县| 山东省| 福贡县| 静安区| 天气| 遂川县| 楚雄市|