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):
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é)果:
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對服務(wù)器之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
原文鏈接:https://blog.csdn.net/sanpic/article/details/79519070