小编mUB*_*NTU的帖子

解析模板 [home] 时出错,模板可能不存在或可能无法被任何配置的模板解析器访问

第一次发帖,所以当我表述错误时请纠正我。虽然我没有偏离文件夹结构的默认映射,但我认为我会在设置中添加。

每当我请求 /home 映射时,我都会收到TemplateInputException

家庭控制器类

@Controller
public class HomeController {
    @GetMapping("/home")
    public String home(Model model, @RequestParam(value = "name", required = false, defaultValue = "World") String name) {
        model.addAttribute("name", name);
        return "home";
    }
}
Run Code Online (Sandbox Code Playgroud)

网络配置:

@Configuration
@ComponentScan(basePackages = "be.mubuntu.dev.cbrapi")

public class WebConfig implements WebMvcConfigurer {
    @Bean
    public ClassLoaderTemplateResolver yourTemplateResolver() {
        ClassLoaderTemplateResolver configurer = new ClassLoaderTemplateResolver();
        configurer.setPrefix("templates/");
        configurer.setSuffix(".html");
        configurer.setTemplateMode(TemplateMode.HTML);
        configurer.setCharacterEncoding("UTF-8");
        configurer.setOrder(0);  // this is important. This way spring //boot will listen to both places 0 and 1
        configurer.setCacheable(false);
        configurer.setCheckExistence(true);
        return …
Run Code Online (Sandbox Code Playgroud)

spring controller thymeleaf spring-boot

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

controller ×1

spring ×1

spring-boot ×1

thymeleaf ×1