代码中的注释太难看所以// 全部换成\
动态网页太酷了!!!
动态方法的作用:
1.从数据库读出数据
2.读出的数据需要显示到前端页面
模版的作用:
1.静态页面
2.实现某些需要变化的数据或者需要进行交互的数据自动展现页面

文件位置
实现动态的类在"src/main/java"的包下
存放模版的地方在"src/main/resources/templates"文件夹下
首先在模版配置文件(src/main/resouces/application.properties)添加两行语句
spring.freemarker.suffix=.html
spring.freemarker.template-loader-path=classpath:/templates/
后端调用的方法
package com.p1k0.P1k0_springboot2;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import freemarker.core.ReturnInstruction.Return;
@Controller \\运用模版
public class Showindex {
@RequestMapping("/index.html") \\告诉浏览器应该访问哪一个地址文件
public String Getdata(Map<String, String> map) \\map容器
{
\\一般为获取数据库的数据
\\假设获取了数据库中的data
String data="template show";
map.put("mapname",data); \\将要输出到网页上的内容放到map容器里,前面为容器的名字,后面为赋值给容器的数据。
return "index"; \\模版文件名称,告诉浏览器用的是哪一个模版,模版不需要后缀.html,因为配置文件已经命名过了后缀是.html
}
}
模版的代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>this is a Template</h1>
<h2>${mapname}</h2> \\调用容器里的内容
</body>
</html>