1.pom.xmlcss
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--引入webjars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
2.控制類
複製代碼
/**
* @Author: soul
* @Date: 2019/4/14 19:48
*/
@Controller
public class ControllerClass {
@RequestMapping("/man")
public String man(){
return "man";
}
}
複製代碼
咱們能夠打開springboot的配置類
@ConfigurationProperties(
prefix = "spring.resources",
ignoreUnknownFields = false
)
public class ResourceProperties {
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = new String[]{"classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/"};
private String[] staticLocations;
private boolean addMappings;
private final ResourceProperties.Chain chain;
private final ResourceProperties.Cache cache;
複製代碼
咱們能夠看到springboot加載資源的路徑爲默認爲classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/html
@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING = Charset.forName("UTF-8");
private static final MimeType DEFAULT_CONTENT_TYPE = MimeType.valueOf("text/html");
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
複製代碼
只要咱們將html頁面放到classpath:/templates/下,thmeleaf就能自動渲染前端
1.禁用掉thymeleaf的緩存功能 #禁用模板引擎的緩存 spring.thymeleaf.cache=false 2.在idea中修改 html代碼 時記得按 ctrl +f9刷新一下