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>

鎶€鏈浘鐗? src=

 

 

Spring 鍚姩绫诲強MVC鐨?鎺у埗鍣ㄩ儴鍒嗕唬鐮侊細

鎶€鏈浘鐗? id=
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";
    }
}
View Code

娴忚鍣ㄨ闂細

鎶€鏈浘鐗? src=

以上是关于template might not exist or might not be accessible by any of the configured Template Resolvers 瀹岀編瑙的主要内容,如果未能解决你的问题,请参考以下文章

解决Error resolving template template might not exist or might not be accessible问题

异常:Error resolving template "xxx", template might not exist or might not be accessible...解

Error resolving template: template might not exist or might not be accessible是一句缩水报错?

Error resolving template “pages”, template might not exist or might not be accessible by any of the

SpringBoot+Thyemleaf报错Template might not exist or might not be accessible

Error resolving template [favicon.ico], template might not exist or might not be accessible by any o