Springboot的Web开发

SpringBoot web开发

1. 静态资源

总结:

  • 在SpringBoot中,我们可以使用以下方式处理静态资源
    • webjars
    • public,static,/**,resources
  • 优先级:reousrces > static(默认) > public



2. 首页定制

  • 首页index.html在public、resources、static、templates四个文件夹下均生效
  • 放在templates下需要加入thymeleaf引擎



3. thymeleaf

  • 导入依赖

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring5</artifactId>
    </dependency>
    
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-java8time</artifactId>
    </dependency>
    
  • 将html页面放入templates目录下即可(源码规定)

    ·

  • 导入约束:

    <html lang="en" xmlns:th="https://www.thymeleaf.org">
    
  • 实现页面传值

    <!--所有的html元素都可以thymeleaf接管替换:th:元素名-->
    <h1 th:text="${msg}"></h1>
    
  • 基本语法

    • 转义和非转义

      model.addAttribute("msg","<h1>helloSpringBoot</h1>");
      
      <!--所有的html元素都可以thymeleaf接管替换:th:元素名-->
      <div th:text="${msg}"></div>
      
      <div th:utext="${msg}"></div>
      </hr>
      
    • 遍历数组

      model.addAttribute("users", Arrays.asList("ranhaifeng","yunqianlan"));
      
      <h3 th:each="user:${users}" th:text="${user}"></h3>
      
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值