Java中@Controller注解和@ResponseBody注解,报错找不到template

 

报错信息:org.thymeleaf.exceptions.TemplateInputException: Error resolving template "xxxxx", template might not exist or might not be accessible by any of the configured Template Resolvers

运行提示找不到模板时,

在controller类上加注解@Controller 和@RestController都可以在前端调通接口,但是二者的区别在于,当用前者的时候在方法上必须添加注解@ResponseBody,如果不添加@ResponseBody,就会报上面错误,因为当使用@Controller 注解时,spring默认方法返回的是view对象(页面)。而加上@ResponseBody,则方法返回的就是具体对象了。@RestController的作用就相当于@Controller+@ResponseBody的结合体
————————————————
版权声明:本文为CSDN博主「你瞅啥瞅你咋地」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/PubliclyAccessible/article/details/79726360

posted @ 2021-04-21 10:20  panchanggui  阅读(390)  评论(0编辑  收藏  举报