我是靠谱客的博主 兴奋大米,这篇文章主要介绍使用thymeleaf遇到Cannot resolve MVC View ‘index‘解决方法问题描述原因分析:解决方案:,现在分享给大家,希望可以做个参考。

问题描述

第一次使用SpringMVC+Thymeleaf时,在Controller中的return “index”;遇到Cannot resolve MVC View 'index’提示。

@Override
    @RequestMapping(value = "/")
    public String index() {
        return "index";
    }
	}

原因分析:

可能一:是配置文件中templateResolver前后缀路径不对
可能二:你没有引用ognl,测试以下代码,如果出现 java.lang.NoClassDefFoundError: ognl/PropertyAccessor。

    @Test
    public void test1(){
        TemplateEngine te=new TemplateEngine();
        String s="<input type='text' th:value='hello'/>";
        Context c1=new Context();
        System.out.println(te.process(s,c1));
        }

解决方案:

可能一解决方法:首先检查templateResolver的前后缀是否正确
可能二解决方法:在pom.xml文件中添加ognl依赖

<dependency>
    <groupId>ognl</groupId>
    <artifactId>ognl</artifactId>
    <version>3.1.12</version>
</dependency>

ps:如果没有Cannot resolve MVC View 'index’了,但网页报404,如果路径全对,记得看看是不是war包,再看看是不是Artifacts配错了,war和web记得区分。
感谢前辈Springboot + thymeleaf 生成静态页面。

最后

以上就是兴奋大米最近收集整理的关于使用thymeleaf遇到Cannot resolve MVC View ‘index‘解决方法问题描述原因分析:解决方案:的全部内容,更多相关使用thymeleaf遇到Cannot内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部