您的位置:首页 > 编程语言 > Java开发

spring-boot搭建简单web(整合freemarker)(二)

2017-02-17 23:30 661 查看
一、maven引入jar包(spring-boot-starter.jar和spring-boot-starter-web.jar和spring-boot-starter-freemarker.jar)

<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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<groupId>demo_boot</groupId>
<artifactId>demo_boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>1.3.0.RELEASE</version>
</dependency>
</dependencies>
</
4000
project>


二、启动引导应用程序

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}


三、freemarker配置信息配置到application.properties

###server
server.port=8081
server.contextPath=/demo_boot

###FREEMARKER (FreeMarkerAutoConfiguration)
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=false
spring.freemarker.expose-spring-macro-helpers=false
#spring.freemarker.prefix=
spring.freemarker.request-context-attribute=rc
#spring.freemarker.settings.*=
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/views/


server.port,server.contextPath对应配置 服务端口号,和项目名

spring.freemarker.template-loader-path配置自定义模板加载路径,springboot默认加载路径为src/main/resources/templates

四、index.html页面

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
Hello world!
</body>
</html>


文件目录结构如图示:



浏览器访问http://localhost:8081/demo_boot/demo/index获取相应的index.html页面信息
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: