首页 > 数据库技术 > 详细

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

时间:2018-08-29 18:35:15      阅读:2358      评论:0      收藏:0      [点我收藏+]

简单表述:控制台出现了这个异常: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...解决办法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!