一、首先在pom.xml添加對HTML的相關依賴java
/**
* pom.xml文件
*/
<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> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>**
二、在application.yml文件添加SpringBoot相關配置web
spring:
spring
thymeleaf: prefix: classpath:/templates/
注意:application.yml 若是是空文件,則默認視圖文件存放在templates文件下,資源文件存放在static目錄下,因爲SpringBoot對jsp支持不太友好,通常使用自帶的標籤實現數據的賦值
![](http://static.javashuo.com/static/loading.gif)
在Controller裏面寫跳轉HTML頁面方法ruby
@Controller //注意這裏必須爲Controller public class HelloController { /** * 本地訪問內容地址 :http://localhost:8080/lmycc/hello * @param map 傳遞參數 * @return */ @RequestMapping("/hello") public String helloHtml(HashMap<String, Object> map) { map.put("hello", "歡迎進入HTML頁面"); return "/index"; } }