在springboot中整合bootstrap
阿新 • • 發佈:2019-01-09
比較簡單,不要想的太複雜了。
首先匯入依賴bootstrap與jquery:
- <!-- https://mvnrepository.com/artifact/org.webjars/bootstrap -->
- <!-- bootstrap -->
- <dependency>
- <groupId>org.webjars</groupId>
- <artifactId>bootstrap</artifactId>
- <version>3.3.5
- </dependency>
- <dependency>
- <groupId>org.webjars</groupId>
- <artifactId>jquery</artifactId>
- <version>3.1.1</version>
- </dependency>
- <!DOCTYPE html>
- <html>
- <
- <scriptsrc="webjars/jquery/3.1.1/jquery.min.js"></script>
- <scriptsrc="webjars/bootstrap/3.3.5/js/bootstrap.min.js"></script>
- <linkrel="stylesheet"href="webjars/bootstrap/3.3.5/css/bootstrap.min.css"/>
- <metacharset="UTF-8">
- <title>Insert title here</title>
- </head
- <body>
- <h2>hello zhangyan</h2>
- <divclass="container">
- <h2>Button</h2>
- <p>.btn 類是按鈕的基本樣式:</p>
- <buttontype="button"class="btn-warning">基本按鈕</button>
- </div>
- </body>
- </html>
<script src="webjars/jquery/3.1.1/jquery.min.js"></script>
<script src="webjars/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="webjars/bootstrap/3.3.5/css/bootstrap.min.css" />
專案結構圖:
然後就可以了。
不要在poi.xml中加build那些,嘗試會有問題。
注:Spring Boot 會從以下路徑尋找靜態檔案:
- /META-INF/resources/
- /resources/
- /static/
- /public/
Controller程式碼如下:
- @Controller
- publicclass BackIndexController {
- @RequestMapping(value = "/",method = RequestMethod.GET)
- public String index() {
- return"backindex.html";
- }
- }