栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

springboot整合thymeleaf

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

springboot整合thymeleaf

springboot整合thymeleaf
  • 1 依赖
  • 2 application.yml
  • 3 实体类
  • 4 controller
  • 5.$符号使用
  • 6.*符号的使用
  • 7.@符号的使用
  • 8.#符号的使用
  • 9.集合的遍历
  • 10.thymeleaf如何定义变量
  • 11.字面量
  • 12.字符串拼接方式
  • 13.比较运算符
  • 14.逻辑运算符
  • 15.三目运算符
  • 16.分支结构,th:if,th:unless,th:switch,th:case
  • 17.thymeleaf的一些常用的内置对象
  • 18.内联

1 依赖
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
2 application.yml
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
  thymeleaf:
    cache: false #开启模板缓存默认true
    check-template: true
    check-template-location: true
    servlet:
      content-type: text/html
    enabled: true
    encoding: UTF-8
    excluded-view-names:
    mode: HTML
    prefix: classpath:/templates/
    suffix: .html
  mvc:
    static-path-pattern: /static/**
  web:
    resources:
      static-locations: classpath:/static
3 实体类
public class User {
    private int id;
    private String name;
    private int age;

    public User() {
    }

    public User(int id, String name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
4 controller
@Controller
public class HelloController {

    @GetMapping("/hello")
    public String hello(Model model, HttpSession session) {
        session.setAttribute("name","javavue");
        List list = new ArrayList<>();
        for (int i = 0 ; i < 5; i++) {
            User user = new User();
            user.setId(i);
            user.setName("xiaolan"+i);
            user.setAge(18);
            list.add(user);
        }
        model.addAttribute("users",list);
        User user = new User();
        user.setId(11);
        user.setAge(18);
        user.setName("小白");
        model.addAttribute("user",user);
        return "hello";
    }
}
5.$符号使用

$符号主要是取对象中的数据



6.*符号的使用

*符号也可以取对象中的数据

    
        
        
        
    

    
    
    
7.@符号的使用

@符号主要是用于引入文件

    
    
    
    
    
    
    
    

 
8.#符号的使用

#符号主要是根据当前浏览器的语言去相对应的国际化配置文件中取值

 
9.集合的遍历 
 
        
10.thymeleaf如何定义变量
    
    
        
    
11.字面量
    
    
    
    
12.字符串拼接方式
   
    
    
13.比较运算符
    
        
        
        
        
        
        
        
    
14.逻辑运算符
    
    
    
    
    
    
    
    
15.三目运算符
    
        
    
16.分支结构,th:if,th:unless,th:switch,th:case
    
        
偶数 基数
17.thymeleaf的一些常用的内置对象

    
    
    
    
    
    
18.内联

    
    hello [[${user.name}]]
    hello [(${user.name})]
    
a better language'"> [[${str}]] [(${str})]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/878583.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号