一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務(wù)器之家 - 編程語言 - Java教程 - SpringBoot中關(guān)于static和templates的注意事項以及webjars的配置

SpringBoot中關(guān)于static和templates的注意事項以及webjars的配置

2021-07-13 15:48裴星宙 Java教程

今天小編就為大家分享一篇關(guān)于SpringBoot中關(guān)于static和templates的注意事項以及webjars的配置,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

1. 默認(rèn)情況下, 網(wǎng)頁存放于static目錄下, 默認(rèn)的"/"指向的是~/resouces/static/index.html文

2. 如果引入了thymeleaf, 則默認(rèn)指向的地址為~/resouces/templates/index.html

?
1
2
3
4
<dependency>
<groupid>org.springframework.boot</groupid>
<artifactid>spring-boot-starter-thymeleaf</artifactid>
</dependency>

代碼結(jié)構(gòu):

SpringBoot中關(guān)于static和templates的注意事項以及webjars的配置

3.在引入thymeleaf后, 如果仍需要訪問~/static/index.html, 則可以使用重定向

?
1
return "redirect:/index.html"

代碼樣例:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import org.springframework.stereotype.controller;
import org.springframework.ui.model;
import org.springframework.web.bind.annotation.getmapping;
import org.springframework.web.bind.annotation.requestmapping;
import javax.servlet.http.httpservletrequest;
import javax.servlet.http.httpservletresponse;
import java.io.ioexception;
@controller
public class homectrl {
  @getmapping("/")
  public string homepage(model model, httpservletrequest request, httpservletresponse response) throws ioexception {
    return "/index";
  }
  @requestmapping("/static")
  public string navigatortostatic() {
    return "redirect:/static.html";
  }
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!doctype html>
<html>
<head>
  <script src="webjars/jquery/3.1.1/jquery.min.js"></script>
  <script src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" />
</head>
<body>
<div class="container"><br/>
  <div class="alert alert-success">
    hello, <strong>bootstarp & webjars!</strong>
  </div>
</div>
</body>
</html>

4. html中引入webjars時, 需導(dǎo)入類似下面的包

?
1
2
3
4
5
6
7
8
9
10
<dependency>
 <groupid>org.webjars</groupid>
 <artifactid>bootstrap</artifactid>
 <version>3.3.7</version>
</dependency>
<dependency>
 <groupid>org.webjars</groupid>
 <artifactid>jquery</artifactid>
 <version>3.1.1</version>
</dependency>

5. html樣例

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<!doctype html>
<html>
<head>
  <script src="webjars/jquery/3.1.1/jquery.min.js"></script>
  <script src="webjars/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="webjars/bootstrap/3.3.7/css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" />
</head>
<body>
<div class="container"><br/>
  <div class="alert alert-success">
    hello, <strong>bootstarp & webjars!</strong>
  </div>
</div>
</body>
</html>

6. 結(jié)果:

SpringBoot中關(guān)于static和templates的注意事項以及webjars的配置

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對服務(wù)器之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

原文鏈接:https://blog.csdn.net/sanpic/article/details/79519070

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日本韩国一区二区三区 | 国内精品久久久久影院网站 | 高h孕交| 涩情主播在线翻车 | 亚洲美女aⅴ久久久91 | 9久热这里只有精品视频在线观看 | 国产精品日本一区二区不卡视频 | coolgay男男gayxxx| 赤坂丽女医bd无删减在线观看 | 成人欧美一区二区三区 | 人人揉揉香蕉 | 大胆私拍模特国模377 | 日韩欧美在线视频一区二区 | 秘书小说阿蛮 | 4444www免费看| 日本一道本视频 | 91看片在线观看 | 国产成人精品免费2021 | 色老板最新网站视频地址 | www免费插插视频 | 猥琐对着美女飞机喷到脸上 | 天天操夜夜操狠狠操 | 99在线视频精品费观看视 | 操好爽 | 青青草国产精品免费 | 欧美成人一区二区 | 俺来操| 妹妹你插的我好爽 | 精品成人一区二区 | 四虎伊人 | 60岁妇女毛片免费观看 | 亚洲激情在线 | 国产福利微拍精品一区二区 | 国产免费午夜 | 黑人干我| 大桥未久一区二区 | 边摸边吃奶玩乳尖视频 | 天天做天天爱天天爽综合区 | 国产一区二区三区四 | 精品国产91久久久久 | 免费视频专区一国产盗摄 |