spring boot integrated freemarker

The spring boot framework uses a specific way to configure, so that developers no longer need to define boilerplate configuration.

The first step is to create a maven project. The pom.xml configuration information is as follows:
<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>


In the second step, application.properties is configured as follows:

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


The third project structure is as follows:




Project address: https://github.com/zhangxia1030/spring-boot-example

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326698501&siteId=291194637