Freemarker作为SSM前端展现

Freemarker具有丰富前端界面表示能力,在SSM项目中使用Freemarker作为前台页面展现层。

POM.xml文件


  4.0.0
  com.test
  freemarkerweb
  war
  0.0.1-SNAPSHOT
  freemarkerweb Maven Webapp
  http://maven.apache.org
  
    
      junit
      junit
      3.8.1
      test
    
	
		org.freemarker
		freemarker
		2.3.23
	
	
	  org.springframework
	  spring-webmvc
	  4.3.7.RELEASE
	  pom
	
	
	  org.springframework
	  spring-tx
	  4.3.7.RELEASE
	
	
	  org.springframework
	  spring-webmvc
	  4.3.7.RELEASE
	
	
	  org.springframework
	  spring-context-support
	  4.3.7.RELEASE
	
	
	  javax.servlet
	  servlet-api
	  2.5
	  test
	
	
	  com.alibaba
	  druid
	  1.0.29
	
	
	  org.mybatis
	  mybatis-spring
	  1.3.0
	
	
	  org.springframework
	  spring-aop
	  4.3.7.RELEASE
	
	
	  org.aspectj
	  aspectjweaver
	  1.8.10
	
	
	  org.mybatis
	  mybatis
	  3.4.2
	
	
	  org.springframework
	  spring-jdbc
	  4.3.10.RELEASE
	
	
	  commons-fileupload
	  commons-fileupload
	  1.3.3
	
  
  
    freemarkerweb
	
		
			org.apache.maven.plugins
			maven-compiler-plugin
			3.7.0
			
				1.8
				1.8
			
		

		
			org.apache.tomcat.maven
			tomcat7-maven-plugin
			2.2
			
				8080
				/
			
		
	
  


SpringMVC.xml




	
	

	
	
	
	

	
	
	
		
		
		
			
				#.##
			
		
	

	
		
		
		
		
	

	
	
	
			
	

	
	
	



jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8
jdbc.uname=root
jdbc.pwd=root
``


SqlMapConfig.xml




	
		
		
		 
	

	
		
	



Spring.xml




	
	
	
	
	
	
	
	
		
		
		
		
	
	
	
	 
		
		
		
		
	
	
	
	
		
		
	
	
	
	
		
	
	
	
	
		
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
	
		
		
	
	
	

	

UserInfo.java

package com.test.bean;

import java.sql.Date;

public class UserInfo {
	private Integer id = null;
	private String name = null;
	private Date dt = new Date(System.currentTimeMillis());
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Date getDt() {
		return dt;
	}
	public void setDt(Date dt) {
		this.dt = dt;
	}
	
}

FreemarkerCtrl.java

package com.test.freemarker;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

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

import com.test.bean.UserInfo;

@Controller
@RequestMapping("/free")
public class FreemarkerCtrl {
	
	@RequestMapping("test")
	public String test(HttpServletRequest req)
	{
		UserInfo ui = new UserInfo();
		ui.setId(100);
		ui.setName("Oracle");
		Map m = new HashMap();
		m.put("name","java");
		m.put("user", ui);
		
		req.setAttribute("data",m);
		return "test";
	}
}

test.ftl Freemarker模板


	First freemarker demo
	
<#function sum i j>
	<#return i+j>

${data.name}


${sum(19,20)}
${data.user.dt}
<#function sumTotal para...> <#local total=0> <#list para as p> <#local total=total+p> <#return total> ${sumTotal(1,2,19,20)}

代码下载
https://pan.baidu.com/s/1jk1MzyDAP2K3joPVgVA7GA

你可能感兴趣的:(Freemarker)