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

相关推荐
烤麻辣烫1 分钟前
23种设计模式(新手)-3接口隔离原则
java·开发语言·学习·设计模式·intellij-idea
程序猿_极客10 分钟前
【2025最新】 Java 入门到实战:数组 + 抽象类 + 接口 + 异常(含案例 + 语法全解析+巩固练习题)
java·开发语言·后端·java基础·java入门到实战
yzx99101318 分钟前
一个嵌入式存储芯片质量评估系统的网页界面设计
开发语言·javascript·ecmascript
树在风中摇曳19 分钟前
数据结构与算法基础入门 —— 从概念到复杂度理解
开发语言·c
v***431727 分钟前
spring.profiles.active和spring.profiles.include的使用及区别说明
java·后端·spring
艾莉丝努力练剑1 小时前
【C++:哈希表封装】用哈希表封装unordered_map和unordered_set
java·c++·stl·哈希算法·散列表·平衡二叉树·哈希
Moe4881 小时前
@SpringBootApplication 注解(Spring Boot 自动配置)详解
java·后端
是苏浙1 小时前
零基础入门C语言之C语言实现数据结构之栈
c语言·开发语言·数据结构
后端小张1 小时前
【JAVA 进阶】SpringBoot 事务深度解析:从理论到实践的完整指南
java·开发语言·spring boot·后端·spring·spring cloud·事务
合作小小程序员小小店1 小时前
web网页开发,在线%宠物销售%系统,基于Idea,html,css,jQuery,java,ssh,mysql。
java·前端·数据库·mysql·jdk·intellij-idea·宠物