当前位置:Gxlcms > 数据库问题 > template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决

template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决

时间:2021-07-01 10:21:17 帮助过:734人阅读

=true spring.thymeleaf.enabled=true spring.thymeleaf.encoding=utf-8 spring.thymeleaf.prefix=/resources/templates/ spring.thymeleaf.suffix=.html #文件后缀为.html或.jsp都可以,取决于/resources/templates/下对应的文件

有了以上这两步就没问题了,如下是项目的目录结构

技术图片

 

 

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";
    }
}
View Code

浏览器访问:

技术图片

template might not exist or might not be accessible by any of the configured Template Resolvers 完美解决

标签:click   app   event   resolve   mode   spring   dem   display   项目   

人气教程排行