论坛首页 Java企业应用论坛

spring boot集成freemarker

浏览 3494 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2017-03-12  
spring boot框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

第一步创建maven项目,pom.xml配置信息如下:
<pre name="code" class="java"><parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<dependencies>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>

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

<!-- common -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.2.1</version>
</dependency>

</dependencies></pre>

第二步,application.properties配置如下:

<pre name="code" class="java">#\u670D\u52A1\u5668\u914D\u7F6E\u4FE1\u606F
server.port=8080
server.address=127.0.0.1 
server.sessionTimeout=30 
server.contextPath=/springboot

#spring boot\u9ED8\u8BA4\u542F\u52A8tomcat\u7684\u8D26\u53F7\u548C\u5BC6\u7801
security.basic.enabled=false

#LOG
logging.config=classpath:log4j2.xml

#MVC
spring.mvc.view.prefix=/WEB-INF/views/
spring.resources.static-locations=classpath:/static/

# FREEMARKER (FreeMarkerAutoConfiguration)
spring.freemarker.allow-request-override=false
spring.freemarker.allow-session-override=false
spring.freemarker.cache=true
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.enabled=true
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.expose-spring-macro-helpers=true
spring.freemarker.prefer-file-system-access=true
spring.freemarker.suffix=.ftl
spring.freemarker.template-loader-path=classpath:/freemarker/
spring.freemarker.settings.template_update_delay=0
spring.freemarker.settings.default_encoding=UTF-8
spring.freemarker.settings.classic_compatible=true
spring.freemarker.order=1</pre>

第三部项目结构如下:




项目地址:https://github.com/zhangxia1030/spring-boot-example
  • 大小: 18.3 KB
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics