本文共 1527 字,大约阅读时间需要 5 分钟。
但很多时候我们需要的不只是JSP做view,可能会引用velocity、freemarker等做为view引擎时,需要加入额外的配置。
下面是在配置文件中加入Freemarker的方法,与JSP并存:
3600 zh_CN yyyy-MM-dd HH:mm:ss yyyy-MM-dd #.##
在JSP和Freemarker的配置项中都有一个order property,上面例子是把freemarker的order设置为0,jsp为1。
意思是找view时,先找ftl文件,再找jsp文件做为视图。
测试:
Controller:
package com.my.controller;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@RequestMapping(value="ftl")public class TestFreemarker { @RequestMapping(method=RequestMethod.GET) public ModelAndView index() { ModelAndView view = new ModelAndView("TestFreemarker/index"); view.addObject("message", "Say hi for Freemarker."); return view; }}
index.ftl:
${message} ${message}
输出:
转载地址:http://pqcol.baihongyu.com/