1.idea2018,1版本-file-new-project
2.
3.
4.配置pom文件
<?xml version="1.0" encoding="UTF-8"?>
<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>com.King</groupId>
<artifactId>testSpringBoot</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>2.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.0.1.RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
5.在resources目录下面分别添加 webapp目录 和application.yml文件
server:
port: 10001
spring:
profiles: default
freemarker:
template-loader-path: classpath:/webapp/WEB-INF/ftl/
cache: true
check-template-location: true
content-type: text/html; charset=UTF-8
expose-request-attributes: true
expose-session-attributes: true
request-context-attribute: request
suffix: .ftl
6.建立包目录,并建立相应的类
package com.king.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* create by wu 2018/5/29
*/
@Controller
@RequestMapping("/index/")
public class IndexController {
@RequestMapping(value = "test/")
public String test(Model model){
String s= "this is from Server";
model.addAttribute("str",s);
return "index";
}
}
7.在web目录下 新建springboot启动类
package com.king.web;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* create by wu 2018/5/29
*/
@SpringBootApplication
public class WebIndexApplication {
public static void main(String[] args){
SpringApplication.run(WebIndexApplication.class,args);
}
}
8.在webapp目录下新建WEB-INF 目录和子目录ftl 在ftl目录下新建 index.ftl文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
${str}
</div>
</body>
</html>
9.启动springboot应用
10.在浏览器中输入localhost:10001/index/test/ 查看效果
11.最终文件目录结构
成功之后记得点赞!