spring boot: freemarket模板引擎

spring boot: freemarket模板引擎

freemarket模板引擎,可以和thymeleaf模板引擎共存

pom.xml引入

<!-- Freemarket  --> 
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
    

  

 

appliationContext.properties配置

#################################################
###FREEMARKET
#################################################
spring.freemarker.allow-request-override=false
spring.freemarker.cache=false
spring.freemarker.check-template-location=true
spring.freemarker.charset=UTF-8
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=false
#spring.freemarker.prefix=
#spring.freemarker.request-context-attribute=
#spring.freemarker.settings.*=
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/templates/ 
#comma-separated list
#spring.freemarker.view-names= # whitelist of view names that can be resolved

  

OrderController.JAVA控制器文件

package com.muyang.boot22.controller;

import java.util.Map;

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

@Controller
@RequestMapping(value="/order")
public class OrderController {

	
	
	@RequestMapping(value="/index")
	public String index(Map<String, Object>map)
	{
		map.put("name", "张三");
		return "order/index";
		
	}
	
	
	@RequestMapping(value="/list")
	public String list(Map<String, Object> map)
	{
		map.put("name", "张三");
		map.put("age", 25);
		map.put("gender", "男");
		return "order/list";		
	}
	
	
}

  

view文件

order/list.ftl

<!DOCTYPE html>
<html>
<head>freemark-list</head>
<body>

<h1>freemarket-list</h1>
name: ${name} <br>
age: ${age} <br>
gender: ${gender}

</body>
</html>

  

pom.xml参考

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.muyang</groupId>
  <artifactId>boot22</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>boot22</name>
  <url>http://maven.apache.org</url>
  
  
  <parent>
  	<groupId>org.springframework.boot</groupId>
  	<artifactId>spring-boot-starter-parent</artifactId>
  	<version>1.5.9.RELEASE</version>
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
  
  
  <!-- spring mvc,aop,restful,fastjson -->
  <dependency>
  	<groupId>org.springframework.boot</groupId>
  	<artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  
  
  <!-- jstl -->
  <dependency>
  	<groupId>javax.servlet</groupId>
  	<artifactId>jstl</artifactId>
  </dependency>
  
  <!-- tomcat的支持 -->
  <!-- dependency>
  	<groupId>org.springframework.boot</groupId>
  	<artifactId>spring-boot-starter-tomcat</artifactId>
  	<scope>provided</scope>
  </dependency>
  <dependency>
  	<groupId>org.apache.tomcat.embed</groupId>
  	<artifactId>tomcat-embed-jasper</artifactId>
  	<scope>provided</scope>
  </dependency-->
  
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
  </dependency>
  
  <!-- mysql支持 -->
  <dependency>
  	<groupId>mysql</groupId>
  	<artifactId>mysql-connector-java</artifactId>
  </dependency>
  
 <!-- 添加spring-data-jpa依赖 -->
 <!-- 引入了 spring-data-jpa就不需要引入spring-boot-starter-jdbc -->
 <dependency>
 	<groupId>org.springframework.boot</groupId>
 	<artifactId>spring-boot-starter-data-jpa</artifactId>
 </dependency>
 
    
  <!-- 添加thymeleaf的依赖 -->  
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
  </dependency>
    
    
   <!-- Freemarket  --> 
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-starter-freemarker</artifactId>
    </dependency>
    
    <!-- fastjson -->  
    <dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>fastjson</artifactId>
			<version>1.2.15</version>
		</dependency>
    
    <!-- 热部署 -->
    <dependency>
    	<groupId>org.springframework.boot</groupId>
    	<artifactId>spring-boot-devtools</artifactId>
    	<optional>true</optional>
    	<scope>true</scope>
    </dependency>
    
  </dependencies>
  
  <build>
  	<plugins>
  	
  		<!-- 热部署  -->
  		<plugin>
  			<groupId>org.springframework.boot</groupId>
  			<artifactId>spring-boot-maven-plugin</artifactId>
  			<configuration>
  				<!--fork :  如果没有该项配置,呢个devtools不会起作用,即应用不会restart -->
  				<fork>true</fork>
  			</configuration>
  		</plugin>
  		
  	</plugins>
  </build>
  
</project>

  

 

 

访问路径

http://localhost:8081/springboot/order/index

http://localhost:8081/springboot/order/list

 

posted @ 2018-07-27 11:37  穆晟铭  阅读(623)  评论(0编辑  收藏  举报