国产女人18毛片水真多18精品, 一区二区三区中文字-亚洲精品女国产, 欧美熟妇老熟妇88888久久久久, 一级毛片免费观看亚洲欧美国产精品,大波霸美女视频,日韩欧美激情V影院,熟女人伦21p,亚洲精品女国产,国产 乱子伦 在线

java Spring整合Freemarker的詳細(xì)步驟

時(shí)間:2025-09-20 20:56:22 java語言 我要投稿

關(guān)于java Spring整合Freemarker的詳細(xì)步驟

  我的開發(fā)環(huán)境

  框架:springmvc

  開發(fā)工具:springsource-tool-suite-2.9.0

  版本:1.6.0_29

  tomcat版本:apache-tomcat-7.0.26

  前言:FreeMarker是一個(gè)用Java語言編寫的模板引擎,它基于模板來生成文本輸出。FreeMarker與Web容器無關(guān),即在Web運(yùn)行時(shí),它并不知道Servlet或HTTP。它不僅可以用作表現(xiàn)層的實(shí)現(xiàn)技術(shù),而且還可以用于生成XML,JSP或Java 等。

  簡而言之,F(xiàn)reemarker就是在Jave Web開發(fā)中以模板的方式在頁面展示從服務(wù)端獲取的信息。

  step1.引入jar包

  Maven代碼:

  復(fù)制代碼 代碼如下:

  org.freemarker

  freemarker

  2.3.20

  org.springframework

  spring-context-support

  3.2.4.RELEASE

  step2.在src/main/resources/conf目錄下新建Freemarker屬性文件freemarker.properties,此屬性文件定義了Freemarker常用的編碼轉(zhuǎn)換,代碼如下:

  tag_syntax=auto_detect

  template_update_delay=2

  default_encoding=UTF-8

  output_encoding=UTF-8

  locale=zh_CN

  date_format=yyyy-MM-dd

  time_format=HH:mm:ss

  datetime_format=yyyy-MM-dd HH:mm:ss

  step3.在DispatcherServlet上下文配置文件spring-servlet.xml中添加Freemarker所需的配置,代碼如下:

  復(fù)制代碼 代碼如下:

  *.ftl

  step4.編寫controller文件和ftl文件

  在src/main/java目錄下新建包www.asuan.com.controller,在包下新建HelloWorldController.java,代碼如下:

  復(fù)制代碼 代碼如下:

  package www.asuan.com.controller;

  import org.springframework.stereotype.Controller;

  import org.springframework.ui.Model;

  import org.springframework.web.bind.annotation.RequestMapping;

  @Controller

  public class HelloWorldController {

  @RequestMapping("/helloWorld")

  public String helloWorld(Model model) {

  String word0 = "Hello ";

  String word1 = "World!";

  /pic/p>

  model.addAttribute("word0",word0);

  model.addAttribute("word1",word1);

  return "helloWorld.ftl";

  }

  }

  在step3中配置的WEB-INF/ftl路徑下新建helloWorld.ftl,代碼如下:

  復(fù)制代碼 代碼如下:

  ${word0}${word1}

  step5.運(yùn)行與調(diào)試

  將工程部署到tomcat并運(yùn)行,在瀏覽器中訪問:/pic/你設(shè)置的工程名/helloWorld.htm

  運(yùn)行結(jié)果:

【java Spring整合Freemarker的詳細(xì)步驟】相關(guān)文章:

Java的Spring框架知識10-17

springmvc如何整合freemarker 并且兼容jsp 視圖11-11

linux配置java環(huán)境變量詳細(xì)步驟教程02-17

Java中的Spring入門實(shí)例02-27

java內(nèi)存的詳細(xì)介紹12-06

講解Java的Spring框架中的AOP實(shí)現(xiàn)08-31

Java基礎(chǔ)學(xué)習(xí)步驟02-05

新手開車詳細(xì)步驟02-06

如何學(xué)好Java 學(xué)習(xí)Java的步驟介紹08-10

  • 相關(guān)推薦