template might not exist or might not be accessible by any of the configured Template Resolvers 瀹岀編瑙
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了template might not exist or might not be accessible by any of the configured Template Resolvers 瀹岀編瑙相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/click' title='click'>click
app event resolve mode spring dem display 椤圭洰鍒濆鑰呭湪maven spring boot web椤圭洰涓娇鐢╰hymeleaf 妯℃澘锛岀粡甯镐細閬囧埌 “template might not exist or might not be accessible by any of the configured Template Resolvers”杩欎釜闂锛岃浜哄緢澶寸柤銆傚叾瀹炶繖涓敊璇殑鎻忚堪寰堟竻妤氾細
绗竴銆佹ā鏉夸笉瀛樺湪 锛岀浜屻€佹ā鏉挎棤娉曡瑙f瀽鍣ㄨВ鏋?/p>
甯︾潃杩欎袱涓棶棰樻潵鎵剧瓟妗堬細
棣栧厛纭畾鍦∕aven鐨勮祫婧愮鐞嗘枃浠朵腑 pom.xml纭繚寮曞叆 spring-boot-starter-thymeleaf杩欎釜jar鍖咃紝濡傛灉閰嶇疆涓湁锛屽畠浼氳嚜鍔ㄤ笅杞藉埌鏈湴搴撱€?/p>
<!-- 寮曞叆 thymeleaf 妯℃澘渚濊禆 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
鎺ヤ笅鏉ュ湪application.properties 涓坊鍔犲涓嬮厤缃細
spring.thymeleaf.mode=html spring.thymeleaf.cache=true spring.thymeleaf.enabled=true spring.thymeleaf.encoding=utf-8 spring.thymeleaf.prefix=/resources/templates/ spring.thymeleaf.suffix=.html #鏂囦欢鍚庣紑涓?html鎴?jsp閮藉彲浠ワ紝鍙栧喅浜?resources/templates/涓嬪搴旂殑鏂囦欢
鏈変簡浠ヤ笂杩欎袱姝ュ氨娌¢棶棰樹簡锛屽涓嬫槸椤圭洰鐨勭洰褰曠粨鏋?/p>
Spring 鍚姩绫诲強MVC鐨?鎺у埗鍣ㄩ儴鍒嗕唬鐮侊細

package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.example.bean.User; @Controller @SpringBootApplication public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); System.out.print("app init"); } @RequestMapping("/hello") @ResponseBody String home() { System.out.print("hello"); return "Hello ,spring boot!"; } @RequestMapping("/") public String index() { System.out.print("index"); return "index"; } @RequestMapping("/userLogin") public String userLogin(Model model) { User user = new User("guozhong",30); model.addAttribute("user",user); return "userLogin"; } }
娴忚鍣ㄨ闂細
以上是关于template might not exist or might not be accessible by any of the configured Template Resolvers 瀹岀編瑙的主要内容,如果未能解决你的问题,请参考以下文章