freemarkershi使用
静态数据渲染
1.加入pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
2.项目结构
## 3.application.yml配置文件
spring:
application:
name: free
freemarker:
cache: false #关闭模板缓存,方便测试
settings:
template_update_delay: 0
server:
port: 9023
4.People实体类
@Data
public class People {
private Integer age;
private String name;
private Date birth;
List<People> list =new ArrayList<People>();
}
5.controller中的静态数据
@Controller
@RequestMapping("/freestatic")
public class FreeStaticController {
@RequestMapping("/test")
public String generate(Map<String,Object> map){
People p1=new People();
p1.setAge(18);
p1.setBirth(new Date());
p1.setName("lisi");
People p2=new People();
p2.setAge(19);
p2.setBirth(new Date());
p2.setName("wangwu");
// 1.简单数据
map.put("name","zhangsan");
map.put("birth",new Date());
// 2.list数据
List list=new ArrayList();
list.add(p1);
list.add(p2);
// 3.map数据
Map mapNew=new HashMap();
mapNew.put("po",p1);
mapNew.pu