Freemarker

html 复制代码
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello World!</title>
</head>
<body>
<b>普通文本 String 展示:</b><br><br>
Hello ${name} <br>
<hr>
<b>对象Student中的数据展示:</b><br/>
姓名:${stu.name}<br/>
年龄:${stu.age}
<hr>
</body>
</html>

yml

XML 复制代码
server:
  port: 8881 #服务端口
spring:
  application:
    name: freemarker-demo #指定服务名
  freemarker:
    cache: false  #关闭模板缓存,方便测试
    settings:
      template_update_delay: 0 #检查模板更新延迟时间,设置为0表示立即检查,如果时间大于0会有缓存不方便进行模板测试
    suffix: .ftl               #指定Freemarker模板文件的后缀名

controller

java 复制代码
package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HelloController {

    @GetMapping("/hello")
    public String hello(Model model){

        model.addAttribute("name","freemarker");
        Student student = new Student();
        student.setName("基哥");
        student.setAge(19);
        model.addAttribute("stu",student);

        return "01-basic";
    }


}

主启动类

java 复制代码
package com.heima.freemarker;

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

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

实体类

java 复制代码
package com.heima.freemarker.entity;

import lombok.Data;

import java.util.Date;

@Data
public class Student {
    private String name;//姓名
    private int age;//年龄
    private Date birthday;//生日
    private Float money;//钱包
}

相关推荐
努力努力再努力wz1 小时前
【Linux网络系列】:JSON+HTTP,用C++手搓一个web计算器服务器!
java·linux·运维·服务器·c语言·数据结构·c++
魂梦翩跹如雨1 小时前
死磕排序算法:手撕快速排序的四种姿势(Hoare、挖坑、前后指针 + 非递归)
java·数据结构·算法
带刺的坐椅8 小时前
Solon AI Skills 会是 Agent 的未来吗?
java·agent·langchain4j·solon-ai
jacGJ8 小时前
记录学习--文件读写
java·前端·学习
哈哈不让取名字8 小时前
基于C++的爬虫框架
开发语言·c++·算法
花间相见8 小时前
【JAVA开发】—— Nginx服务器
java·开发语言·nginx
扶苏-su9 小时前
Java---Properties 类
java·开发语言
cypking9 小时前
四、CRUD操作指南
java
魔芋红茶10 小时前
Spring Security 学习笔记 2:架构
笔记·学习·spring
2301_7806698610 小时前
文件字节流输出、文件复制、关闭流的方法
java