1.创建项目时选择web和thymeleaf,删除不需要的文件(选择文件,按delete)
2.js,css,img放在resource中的static中,页面放在resources中的templates
3.controller中的get请求方式
package com.cc.springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class ProviderController {
//@RequestMapping(value="/providers",method= RequestMethod.GET)
@GetMapping("/providers")
public String list(){
return "provider/list";
}
}
4.热部署依赖和配置文件
<!--热部署配置-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
spring.thymeleaf.cache=false
5.引入css,图片引入,引入webjars(先pom依赖包)
<link rel="stylesheet" th:href="@{/css/public.css}" />
<a href="view.html"><img th:src="@{/img/read.png}" alt="查看" title="查看"/></a>
<!--引入 jquery webjars-->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
<script th:src="@{/webjars/jquery/3.3.1/jquery.js}" src="../js/jquery.js"></script>
<script th:src="@{/js/js.js}" src="../js/js.js"></script>
访问页中,查看页面源代码,点击jquery链接出现代码,则说明webjars成功