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

Thymeleaf的功能及使用

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

Thymeleaf的功能及使用

文章目录

一、Thymeleaf的使用二、Thymeleaf基本语法三、页面开发


一、Thymeleaf的使用

引入Starter


    org.springframework.boot
    spring-boot-starter-thymeleaf


自动配置好了thymeleaf

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ThymeleafProperties.class)
@ConditionalOnClass({ TemplateMode.class, SpringTemplateEngine.class })
@AutoConfigureAfter({ WebMvcAutoConfiguration.class, WebFluxAutoConfiguration.class })
public class ThymeleafAutoConfiguration {
    ...
}

自动配好的策略:
所有thymeleaf的配置值都在 ThymeleafProperties
配置好了 SpringTemplateEngine
配好了 ThymeleafViewResolver
我们只需要直接开发页面

public static final String DEFAULT_PREFIX = "classpath:/templates/";//模板放置处
public static final String DEFAULT_SUFFIX = ".html";//文件的后缀名
二、Thymeleaf基本语法

https://www.yuque.com/atguigu/springboot/vgzmgh#Ci7un

三、页面开发

引入命名空间:xmlns:th=“http://www.thymeleaf.org”




    
    Title


    

爱你

百度

@Controller
public class ViewTwstController {
    @GetMapping("/atguigu")
    public String atguigu(Model model){
        //model中的数据会被放在请求域中request.setAttribute("a",aa)
        model.addAttribute("msg","你好 同学!");
        model.addAttribute("link","http://www.baidu.com");
        return "success";

    }
}

th:href=@{/link}

server:
  servlet:
    context-path: /app #设置应用名

这个设置后,URL要插入/app, 如http://localhost:8080/app/hello.html。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/723802.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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