第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

【SpringBoot2.0系列02】SpringBoot之使用Thymeleaf視圖模板

標(biāo)簽:
SpringBoot

前言

Thymeleaf 是Java服务端的模板引擎,与传统的JSP不同,前者可以使用浏览器直接打开,因为可以忽略掉拓展属性,相当于打开原生页面,给前端人员也带来一定的便利。如果你已经厌倦了JSP+JSTL的组合,Thymeleaf或许是个不错的选择!

一、目标

使用thymeleaf视图模板,并且于SpringBoot进行整合。

二、实现

首先创建一个SpringBoot项目,添加如下依赖

 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- springboot web 依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- thymeleaf 依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

添加完依赖以后,就需要编写对应的Controllerview

resource目录下新建templates文件夹并且在该目录下新建文件index.html

<!DOCTYPE html><html lang="en"><head>
    <meta charset="UTF-8">
    <title>Title</title></head><body>
    <h1>你好</h1>
    <h1 th:text="${name}">  </h1></body></html>

src/main/java/com/yukong/chapter目录下新建IndexController

@Controllerpublic class IndexController {    @GetMapping("/hello")    public String hello(@RequestParam(defaultValue = "world", required = false) String name, Model model) {
        model.addAttribute("name", name);        return "index";
    }

}

注意这里使用的是@Controller

然后在src/resource/application.yml配置一下thymeleaf相关配置

server:
  port: 8989
spring:
  thymeleaf:    # 配置视图路径前缀
    prefix: classpath:/templates/    # 配置视图路径后缀
    suffix: .html
    mode: html    # 关闭缓存 修改视图 刷新浏览器就显示 开发阶段务必关闭缓存 (=false)
    cache: false

启动Chapter21Application.java并且访问http://localhost:8989/hello

结果如图:

webp

image.png

再次访问http://localhost:8989/hello?name=yukong

结果如图


webp

image.png



作者:余空啊
链接:https://www.jianshu.com/p/66d1be96ea1e


點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消