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

相关推荐
野生的编程萌新8 分钟前
从冒泡到快速排序:探索经典排序算法的奥秘(二)
c语言·开发语言·数据结构·c++·算法·排序算法
Full Stack Developme9 分钟前
Java后台生成多个Excel并用Zip打包下载
java·开发语言·excel
Brookty11 分钟前
【Java学习】锁、线程死锁、线程安全2
java·开发语言·学习·java-ee
weixin_3077791333 分钟前
VS Code配置MinGW64编译backward库
开发语言·c++·vscode·算法
百锦再35 分钟前
.NET 的 WebApi 项目必要可配置项都有哪些?
java·开发语言·c#·.net·core·net
耳东哇1 小时前
spring ai-openai-vl模型应用qwen-vl\gpt-文字识别-java
java·人工智能·spring
花开富贵ii2 小时前
代码随想录算法训练营四十三天|图论part01
java·数据结构·算法·深度优先·图论
布朗克1683 小时前
Java 10 新特性及具体应用
java·开发语言·新特性·java10
ZZHow10246 小时前
JavaWeb开发_Day05
java·笔记·web
CHEN5_026 小时前
【Java虚拟机】垃圾回收机制
java·开发语言·jvm