SpringBoot-03-Web

SpringBoot-03-Web,第1张

SpringBoot-03-Web 一、静态资源

1. 咋Spring Boot,我们可以用一下方式处理静态资源

        webjars         访问:  localhost:8080/webjars/        (基本不用)

        public、        static、        /**、        resources

        访问:localhost:8080/webjars/

2. 优先级: resources> static:默认>public

二、thymeleaf

maven依赖

        
            org.thymeleaf
            thymeleaf-spring5
        
        
            org.thymeleaf.extras
            thymeleaf-extras-java8time
        

控制层、路径映射

  @RequestMapping("/test")
    public String hello(Model model){
        model.addAttribute("msg","你好阿");
        model.addAttribute("color","color:red");
        model.addAttribute("users", Arrays.asList("张三","李四","王二狗"));


        return "aaa";
    }

html代码

th命名空间引用:xmlns:th="http://www.thymeleaf.org"




    
    Title


首页


            
           
=======================================
哈哈哈
=======================================


=======================================
[[${user}]]





 测试结果

 三、themeleaf语法

1. 赋值

model.addAttribute("msg","你好阿");
            
           

2. 样式

model.addAttribute("color","color:red");
哈哈哈

3. 遍历

model.addAttribute("msg","你好阿");

=======================================
[[${user}]]

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5661478.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存