流程目录
1.添加相关jar配置
2.添加模板
3.修改控制器HelloWorldController
4.修改模板helloworld.ftl
5.启动测试
1.添加相关jar配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.添加模板
在src/main/resources下templates添加模板
查找html关键词
next,取名helloworld.ftl
finish之后发现html跑到如图那里去了,手动拖拽到templates去
3.修改控制器HelloWorldController
package com.helloworld.web;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/")
@Controller
public class HelloWorldController {
@RequestMapping("/hello")
public String helloworld(Model model) {
System.err.println(1111);
model.addAttribute("msg", "我是模板来的HelloWorld");
return "helloworld";
}
}
4.修改模板helloworld.ftl
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- msg取Controller里的msg -->
${msg}
</body>
</html>
5.启动测试
注意点:如果模板分包
使用如下方式