thymeleaf.exceptions.TemplateInputException: Error resolving template和500.HttpMediaTypeNotAccept

在这里插入图片描述

最近在写demo的时候出现了这个异常,这个坑之前踩过一次,所以这里记录一下
出现的原因是控制层返回了JSON数据没有页面数据,也就是返回的不是ModelAndView,所以抛出了这个异常
解决方案一
控制层加上@ResponseBody注解,注明返回是JSON数据
例如:
@RequestMapping(value= “/findWxmpType”, method = RequestMethod.POST,produces=“application/json”)

解决方案二
控制层类的注解不要使用**@Controller**,因为这个注解是springMVC的处理器handler,根据MVC的流程执行处理handler返回的是modelAndView,而要使用**@RestController的注解,关于@RestController 的解释官方文档是这样说的@RestController is astereotype annotation that combines @ResponseBody and @Controller.**就是说@RestController注解相当于@ResponseBody加 @Controller合在一起的作用。

按照上面的方案一二改了以后,又爆了新的错误
org.springframework.http.converter.HttpMessageNotWritableException: No converter for [class org.json.JSONObject] with preset Content-Type

解决方案:
配置jackson转换器,指定返回数据类型;
也就是缺少转换的jar包:jackson-core-asl-1.9.12.jar,jackson-mapper-asl-1.9.12.jar
下载地址:http://mvnrepository.com/artifact/org.codehaus.jackson/jackson-core-asl/1.9.12

            http://mvnrepository.com/artifact/org.codehaus.jackson/jackson-mapper-asl/1.9.12

在这里插入图片描述

https://blog.youkuaiyun.com/weixin_41382994/article/details/80196410

参考链接:https://blog.youkuaiyun.com/weixin_42324034/article/details/108299204

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值