欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

spring boot集成freemarker

程序员文章站 2022-06-22 18:18:26
...
spring boot框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置。

第一步创建maven项目,pom.xml配置信息如下:
<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>


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

#\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


第三部项目结构如下:

spring boot集成freemarker
            
    
    博客分类: spring boot freemarkerspringjavawebspring boot 


项目地址:https://github.com/zhangxia1030/spring-boot-example
  • spring boot集成freemarker
            
    
    博客分类: spring boot freemarkerspringjavawebspring boot 
  • 大小: 18.3 KB