码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2018-08-29 18:43:42      阅读:1554      评论:0      收藏:0      [点我收藏+]

标签:单表   list   个人   回调函数   rest   article   erro   The   理解   

简单表述:控制台出现了这个异常:Error resolving template "xxx", template might not exist or might not be accessible by any of the configured Template Resolvers

解决办法:在报出这个异常的方法上添加注解@ResponseBody

讲一下个人理解:这个注解就是用来区别 方法的返回值字符串 和 视图解析器解析的页面名字字符串 的冲突的,举个例子:方法A返回的字符串success,如果和ajax的回调函数里的msg匹配,就弹出一个“执行成功”,因为success只是普通的字符串,所以要在方法上边加上@ResponseBody。   方法B的返回值是“/contextList”,而这个就是一个页面contextList.jsp或者是contextList.html(具体是什么看配置,反正是个页面)。

网上找的资料(博客链接:https://blog.csdn.net/Ocean_tu/article/details/80989584):

controller层加注解@Controller 和@RestController都可以在前端调通接口,但是二者的区别在于,当用前者的时候在方法上必须添加注解@ResponseBody,如果不添加@ResponseBody,就会报上面错误,因为当使用@Controller 注解时,spring默认方法返回的是view对象(页面)。而加上@ResponseBody,则方法返回的就是具体对象了。@RestController的作用就相当于@Controller+@ResponseBody的结合体

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

标签:单表   list   个人   回调函数   rest   article   erro   The   理解   

原文地址:https://www.cnblogs.com/xuchao0506/p/9556130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!