SpringBoot入门-15(springboot配置freemarker使用YML)
2017-12-23 14:50
691 查看
系列教程都是从网络上收集和本人的理解所编辑而成,仅供广大爱好者学习所用,请尊重本人的劳动成果。欢迎评论指正和转帖!(请保留连接谢谢!)
一、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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.fs</groupId>
<artifactId>springboot_freemarker_10_1</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>springboot_freemarker_10_1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<properties>
<spring-boot-version>1.5.3.RELEASE</spring-boot-version>
<junit-version>4.12</junit-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springboot_freemarker_10_1</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
9b82
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
二、Application.java
package com.fs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
三、FreemarkerController.java
package com.fs;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@Controller
public class FreemarkerController {
@RequestMapping("/demo")
public String demo(Map<String, Object> map) {
map.put("descrip", "It's a springboot integrate freemarker's demo!!!!");
return "demo";
}
}
四、application.yml
spring:
http:
encoding:
force: true
charset: UTF-8
freemarker:
allow-request-override: false
cache: false
check-template-location: true
charset: UTF-8
content-type: text/html; charset=utf-8
expose-request-attributes: false
expose-session-attributes: false
expose-spring-macro-helpers: false
suffix: .ftl
template-loader-path: classpath:/templates
一、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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>com.fs</groupId>
<artifactId>springboot_freemarker_10_1</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>springboot_freemarker_10_1 Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<properties>
<spring-boot-version>1.5.3.RELEASE</spring-boot-version>
<junit-version>4.12</junit-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>springboot_freemarker_10_1</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
9b82
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
二、Application.java
package com.fs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
三、FreemarkerController.java
package com.fs;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Map;
@Controller
public class FreemarkerController {
@RequestMapping("/demo")
public String demo(Map<String, Object> map) {
map.put("descrip", "It's a springboot integrate freemarker's demo!!!!");
return "demo";
}
}
四、application.yml
spring:
http:
encoding:
force: true
charset: UTF-8
freemarker:
allow-request-override: false
cache: false
check-template-location: true
charset: UTF-8
content-type: text/html; charset=utf-8
expose-request-attributes: false
expose-session-attributes: false
expose-spring-macro-helpers: false
suffix: .ftl
template-loader-path: classpath:/templates
相关文章推荐
- SpringBoot入门-13(springboot配置使用YML)
- SpringBoot入门-14(springboot配置thymeleaf使用YML)
- SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例
- SpringBoot-使用yml配置文件
- SpringBoot入门-10(springboot配置freemarker模板)
- 【转】SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)
- SpringBoot使用Yml配置文件
- 使用SpringBoot yml配置文件(三)
- SpringBoot 使用yml配置 mybatis+pagehelper+druid+freemarker实例
- SpringBoot启动报错 ApplicationStartingEvent,刚入门使用springboot
- springboot入门(三)-- springboot集成mybatis及mybatis generator工具使用
- 15、Spring Boot使用Druid和监控配置【从零开始学Spring Boot】
- 使用SpringBoot yml配置文件
- 15、Spring Boot使用Druid和监控配置【从零开始学Spring Boot】
- SpringBoot入坑笔记之spring-boot-starter-web 配置文件的使用
- SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)
- 使用SpringBoot的yml文件配置时踩的一个坑
- 使用SpringBoot yml配置文件(三)
- SpringBoot学习笔记(7) SpringBoot整合Dubbo(使用yml配置)
- (15)Spring Boot使用Druid和监控配置【从零开始学Spring Boot】