標籤:boot mave 本地 star scope 標籤 方法 depend work
1、首先在pom.xml添加對HTML的相關依賴
/** * 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>**
2、在application.yml檔案添加SpringBoot相關配置
spring:
thymeleaf: prefix: classpath:/templates/
注意:application.yml 如果是空檔案,則預設視圖檔案存放在templates檔案下,資源檔存放在static目錄下,由於SpringBoot對jsp支援不太友好,一般使用內建的標籤實現資料的賦值
在Controller裡面寫跳轉HTML頁面方法
@Controller //注意這裡必須為Controllerpublic 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"; }}
SpringBoot---基本配置