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;//钱包
}

相关推荐
人道领域10 分钟前
【LeetCode刷题日记】131.分割回文串,动态规划优化
java·开发语言·leetcode
z落落22 分钟前
C# 接口 interface (多接口实现、类+接口、成员重名)
java·开发语言
发际线向北27 分钟前
0x05 深入了解JVM虚拟机(JVM方法调用 -Ⅰ)
java
宋哥转AI30 分钟前
学了Spring AI Graph再看LangGraph,发现API几乎一模一样
java·人工智能·agent
AskHarries1 小时前
Workspace:文件系统、项目上下文和执行边界
java·服务器·前端
摇滚侠1 小时前
JavaWeb 全套教程 Servlet 66-74
java·servlet·tomcat·intellij-idea·jar
Solis程序员1 小时前
滑动窗口热键探测与三级缓存设计
java·spring·缓存
好家伙VCC1 小时前
区块链双向支付通道实战:从签名到结算
java·后端·区块链·asp.net
知识的宝藏1 小时前
Xpaht self::div 轴语法
开发语言
keykey6.1 小时前
卷积神经网络(CNN):让AI学会“看“
开发语言·人工智能·深度学习·机器学习