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

相关推荐
橘颂TA几秒前
C++ 信号量
java·开发语言
程序猿20231 分钟前
Java Thread
java·开发语言·python
梅梅绵绵冰2 分钟前
springboot初步1
java·前端·spring boot
jason.zeng@15022074 分钟前
POM构造Spring boot多模块项目
java·spring boot·后端
嫂子开门我是_我哥9 分钟前
第五节:字符串处理大全:文本操作的“万能工具箱”
开发语言·python
indexsunny10 分钟前
互联网大厂Java面试实录:Spring Boot微服务在电商场景中的应用与挑战
java·spring boot·redis·mysql·security·microservices·interview
编程彩机11 分钟前
互联网大厂Java面试:从分布式缓存到微服务架构的技术场景解析
java·redis·微服务·分布式事务·分布式缓存·面试解析
独自破碎E12 分钟前
【字节面试手撕】大数加法
java·算法
鱼跃鹰飞14 分钟前
LeetCode热题100: 49.字母异位词分组
java·数据结构·算法·leetcode
studyForMokey19 分钟前
【Android面试】Java & Kotlin语言
android·java·面试