濮阳杆衣贸易有限公司

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

spring mvc整合freemarker基于注解方式

熱門標(biāo)簽:百度ai地圖標(biāo)注 同安公安400電話怎么申請流程 合肥電銷外呼系統(tǒng)哪家公司做的好 玉林市機(jī)器人外呼系統(tǒng)哪家好 蘋果手機(jī)凱立德地圖標(biāo)注 申請400電話手續(xù) 南陽外呼系統(tǒng)定制化 預(yù)測式外呼系統(tǒng)使用說明 電話機(jī)器人軟件銷售工作
基于網(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">

    !-- 針對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就會到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異步請求之Servlet異步處理
  • springmvc處理異步請求的示例
  • 詳解spring mvc對異步請求的處理
  • SpringMVC環(huán)境下實(shí)現(xiàn)的Ajax異步請求JSON格式數(shù)據(jù)
  • Spring中注解方式的異步請求

標(biāo)簽:南京 南昌 淄博 臺州 海南 揚(yáng)州 南京 嘉興

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《spring mvc整合freemarker基于注解方式》,本文關(guān)鍵詞  spring,mvc,整合,freemarker,基于,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《spring mvc整合freemarker基于注解方式》相關(guān)的同類信息!
  • 本頁收集關(guān)于spring mvc整合freemarker基于注解方式的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    德钦县| 航空| 金秀| 黄石市| 北海市| 金华市| 定远县| 全南县| 旅游| 筠连县| 江川县| 哈巴河县| 商城县| 延川县| 慈溪市| 新疆| 乌审旗| 兴城市| 镇江市| 扎鲁特旗| 高尔夫| 怀远县| 海兴县| 苗栗县| 辽源市| 汕头市| 龙南县| 图木舒克市| 阜宁县| 沂水县| 庆安县| 城步| 吐鲁番市| 萨迦县| 常山县| 新田县| 兴隆县| 山阳县| 冕宁县| 道孚县| 天镇县|