FreeMarker与SpringMVC整合

完整版见https://jadyer.github.io/




This is FreeMarker-2.3.19 and Spring-framework-3.1.1.RELEASE


This is the index.jsp

<%@ page language="java" pageEncoding="UTF-8"%>
访问FreeMarker效果页面


访问JSP效果页面

This is the web.xml



	
		jadyer
		org.springframework.web.servlet.DispatcherServlet
		1
	
	
		jadyer
		/
	

This is SpringMVC Config File----jadyer-servlet.xml



	
	
	
	
	
	
	
		
		
	
	
		
		
		
	
	
	
	
		
		
	

This is //WEB-INF//jsp//username.jsp

<%@ page language="java" pageEncoding="UTF-8"%>

${myname}


这是FreeMarker效果页面//WEB-INF//ftl//myfree.ftl

${myname}


最后是SpringMVC的控制器UserController.java

package com.jadyer.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class UserController {
	@RequestMapping("/getUser")
	public String getUser(Model model){
		model.addAttribute("myname", "I am 玄玉");
		return "myfree";
	}
	
	@RequestMapping("/getUserName")
	public String getUserName(Model model){
		model.addAttribute("myname", "I am Jadyer");
		return "username";
	}
}

你可能感兴趣的:(FreeMarker,试炼FreeMarker)