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

相关推荐
菜鸟小芯几秒前
OpenHarmony环境搭建——02-JDK17安装教程
java
我命由我123452 分钟前
Python 开发 - OpenAI 兼容阿里云百炼平台 API
开发语言·人工智能·后端·python·阿里云·ai·语言模型
GokuCode5 分钟前
【GO高级编程】02.GO接收者概述
开发语言·后端·golang
Aotman_7 分钟前
JavaScript去除对象字段空格
开发语言·前端·javascript
云和数据.ChenGuang10 分钟前
Zabbix 6 与 PHP 5 版本**完全不兼容
运维·开发语言·php·zabbix·运维工程师
csbysj202011 分钟前
Ruby 范围(Range)
开发语言
原来是好奇心14 分钟前
深入Spring Boot源码(二):启动过程深度剖析
java·源码·springboot
听风吟丶15 分钟前
Spring Boot 自动配置原理深度解析与实战
java·spring boot·后端
原来是好奇心16 分钟前
深入Spring Boot源码(一):环境搭建与初探项目架构
java·gradle·源码·springboot