最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

springboot配置templates直接訪問的實現(xiàn)

 更新時間:2021年12月15日 16:35:15   作者:morganEngineer  
這篇文章主要介紹了springboot配置templates直接訪問的實現(xiàn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

springboot配置templates直接訪問

springboot下的templates目錄的資源默認是受保護的,類似于javaweb項目的WEB-INF目錄,但是給每個springboot的html頁面都配置控制器跳轉(zhuǎn)過于麻煩

配置公有訪問方式如下

在配置文件加如下:

spring.resources.static-locations=classpath:/META-INF/resources/, classpath:/resources/, classpath:/static/, classpath:/templates/, classpath:/public/

附上spring 各種配置的官方url:方便后期查閱

springboot的templates用法

@Controller
public class HelloController {
    @RequestMapping("/test")
    public String test(Model model){
        model.addAttribute("msg","<h1>templates測試</h1>");
        model.addAttribute("users", Arrays.asList("lishao","liyuan"));
        return "/test";
    }
}

在controller中添加視圖

在html中調(diào)用

<body>
<h3>test</h3>
<!--不轉(zhuǎn)義-->
<div th:text="${msg}"></div>
<!--轉(zhuǎn)義h1-->
<div th:utext="${msg}"></div>
<hr>
<h3 th:each="user : ${users}" th:text="${user}"></h3>

</body>

記得要導(dǎo)入templates的依賴

當你導(dǎo)入了templates依賴,

在這里插入圖片描述

就會直接識別出來文件下的test,簡單方便

 <!--templates-->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

html中也要導(dǎo)入

<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">

一個是轉(zhuǎn)義一個是不轉(zhuǎn)義

以下是運行的結(jié)果

在這里插入圖片描述

在這里插入圖片描述

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

延川县| 揭西县| 保山市| 饶河县| 运城市| 资溪县| 卢湾区| 剑阁县| 胶州市| 兰坪| 大竹县| 霍邱县| 宝坻区| 南召县| 玉屏| 尉犁县| 农安县| 桃园县| 尤溪县| 化州市| 台北市| 巴林左旗| 邵东县| 乌鲁木齐县| 岢岚县| 赤城县| 喀什市| 铜陵市| 乌兰县| 玛纳斯县| 博湖县| 牙克石市| 苍梧县| 石柱| 磐石市| 伊宁市| 三亚市| 叙永县| 南涧| 乌恰县| 浑源县|