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

SpringBoot返回html界面的使用示例

 更新時間:2023年11月01日 09:41:29   作者:@ljn  
本文主要介紹了SpringBoot返回html界面的使用示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

方法一:

(1)html文件要放在resource下的static目錄下(沒有static 自己就創(chuàng)建一個文件夾)

(2)在application.yml 中配置視圖解析器

spring:
  mvc:
    view:
      prefix: /
      suffix: .html

(3)寫web層

    @RequestMapping("/show")
    public String show(){
        return "defain";
    }

注意:類前別是:@RestController 用@Controller 因為返回是界面 無需增強

方法二

使用Thymeleaf模板引擎:Thymeleaf是Spring Boot官方支持的一種模板引擎。它可以方便地和Spring Boot項目一起使用。我們可以用Thymeleaf編寫HTML模板,然后在后端填充模板里的數(shù)據(jù),這時Spring Boot就會自動把渲染好的HTML頁面發(fā)送給瀏覽器。

(1)將html文件放在resource下的templates目錄下

(2)在application.yml 中配置視圖解析器

  thymeleaf:
    cache: false
    prefix:
      classpath: /templates

(3)添加依賴

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
      <version>2.5.0</version>
    </dependency>

(4)書寫web層

    @RequestMapping("/show")
    public String show(){
        return "defain";
    }

 到此這篇關(guān)于SpringBoot返回html界面的使用示例的文章就介紹到這了,更多相關(guān)SpringBoot返回html界面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論