欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot配置templates直接訪(fǎng)問(wèn)的實(shí)現(xiàn)

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

springboot配置templates直接訪(fǎng)問(wèn)

springboot下的templates目錄的資源默認(rèn)是受保護(hù)的,類(lèi)似于javaweb項(xiàng)目的WEB-INF目錄,但是給每個(gè)springboot的html頁(yè)面都配置控制器跳轉(zhuǎn)過(guò)于麻煩

配置公有訪(fǎng)問(wè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測(cè)試</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的依賴(lài)

當(dāng)你導(dǎo)入了templates依賴(lài),

在這里插入圖片描述

就會(huì)直接識(shí)別出來(lái)文件下的test,簡(jiǎn)單方便

 <!--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">

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

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

在這里插入圖片描述

在這里插入圖片描述

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

相關(guān)文章

最新評(píng)論