《spring-boot学习》-14-spring boot整合freeMarker模板
2017-03-03 10:35
120 查看
1.新建一个maven web项目
2.pox.xml中配置
3.文件结构如下
4.各个文件内容如下
Application.java
HelloWorldController.java
/springweb/src/main/resources/templates/index.ftl
/springweb/src/main/resources/application.properties
5.访问 http://localhost:8080/welcome 正确
2.pox.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>springweb</groupId> <artifactId>springweb</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>springweb Maven Webapp</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.1.RELEASE</version> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 引入freeMarker的依赖包. --> < 100ed span class="hljs-tag"><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <fork>true</fork> </configuration> </plugin> </plugins> </build> </project>
3.文件结构如下
4.各个文件内容如下
Application.java
package com.neo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication @EnableScheduling public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
HelloWorldController.java
package com.neo.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloWorldController { @RequestMapping("/welcome") public String welcome(Model model) { /* Map model = new HashMap(); model.put("message", "这是测试的内容。。。"); model.put("toUserName", "张三"); model.put("fromUserName", "老许"); */ model.addAttribute("message", "这是测试的内容。。。"); return "index" ; } }
/springweb/src/main/resources/templates/index.ftl
<html> <body> 亲爱的 ${message} tuuuuuuuuuuuuuuu </body> </html>
/springweb/src/main/resources/application.properties
spring.freemarker.allow-request-override=false spring.freemarker.cache=true spring.freemarker.check-template-location=true spring.freemarker.charset=UTF-8 spring.freemarker.content-type=text/html spring.freemarker.expose-request-attributes=true spring.freemarker.expose-session-attributes=true spring.freemarker.expose-spring-macro-helpers=false #spring.freemarker.prefix= spring.freemarker.request-context-attribute=request #spring.freemarker.settings.*= spring.freemarker.suffix=.ftl spring.freemarker.template-loader-path=classpath:/templates/ #spring.freemarker.view-names= # whitelist of view names that can be resolved
5.访问 http://localhost:8080/welcome 正确
相关文章推荐
- spring中AOP基本概念(14)
- (14)Spring AOP Advisor
- Spring整理系列(14)——基于注解的AspectJ风格实现spring AOP
- 14、spring和spring mvc整合
- Spring Boot---(14)Spring Boot 整合EhCache做缓存
- Quartz入门实例14-让Quartz的Job使用Spring注入的Bean
- 14-spring的事务管理(配置文件实现)
- MyBatis14--MyBatis和Spring整合
- 【Spring学习14】延迟初始化lazy-init与depends-on
- Java之Spring Boot学习
- springcloud实战之14动态刷新分布式配置中心属性配置(config)
- 14、Spring工具类之Resource
- (14)spring boot中@SpringBootApplication注解
- Spring 3.x企业应用开发实战(14)----事务
- springMVC(14) springMVC+spring+hibernate增删改查实例
- Java 学习笔记14:Spring 数据库数据源DBCP配置说明
- Spring学习-14:Spring整合web开发
- Java 学习笔记14:Spring 数据库数据源DBCP配置说明
- [译]14-spring 集合元素的注入
- MyBatis整合Spring的实现(14)