在springboot中集成bootstrap

比较简单,不要想的太复杂了。

首先导入依赖bootstrap与jquery:

[html]  view plain  copy
  1. <!-- https://mvnrepository.com/artifact/org.webjars/bootstrap -->  
  2.         <!-- bootstrap -->  
  3.         <dependency>  
  4.             <groupId>org.webjars</groupId>  
  5.             <artifactId>bootstrap</artifactId>  
  6.             <version>3.3.5</version>  
  7.         </dependency>  
  8.         <dependency>  
  9.             <groupId>org.webjars</groupId>  
  10.             <artifactId>jquery</artifactId>  
  11.             <version>3.1.1</version>  
  12.         </dependency>  
然后在html文件中加入相应版本:

[html]  view plain  copy
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4. <script src="webjars/jquery/3.1.1/jquery.min.js"></script>  
  5. <script src="webjars/bootstrap/3.3.5/js/bootstrap.min.js"></script>  
  6. <link rel="stylesheet" href="webjars/bootstrap/3.3.5/css/bootstrap.min.css" />    
  7. <meta charset="UTF-8">  
  8. <title>Insert title here</title>  
  9. </head>  
  10. <body>  
  11.     <h2>hello zhangyan</h2>  
  12.     <div class="container">  
  13.         <h2>Button</h2>  
  14.         <p>.btn 类是按钮的基本样式:</p>  
  15.         <button type="button" class="btn-warning">基本按钮</button>  
  16.     </div>  
  17. </body>  
  18. </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代码如下:

[java]  view plain  copy
  1. @Controller  
  2. public class BackIndexController {  
  3.   
  4.     @RequestMapping(value = "/",method = RequestMethod.GET)  
  5.     public String index() {  
  6.           
  7.         return "backindex.html";  
  8.     }  
  9.       
  10. }  
需要加入后缀。

猜你喜欢

转载自blog.csdn.net/m0_37443464/article/details/79970425