前言
今天复习SpringMVC框架的时候发现页面返回List<Student>会报错提示无法找到合适的Json转换类.
参考SpringMVC返回JSON提示:HttpMessageNotWritableException: No converter found for return value of type文章
发现我的依赖和配置是都没有问题的.
引入了Jackson的相关依赖并且开启了mvc注解配置.
最终问题还是解决了.
错误原因
IDEA自动创建的配置类头部约束信息是错的.
解决方案
改成正确的约束就可以了
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
本文介绍了解决SpringMVC框架中返回List<Student>类型数据时报HttpMessageNotWritableException错误的方法。通过修正IDEA自动生成的配置文件中的XML声明部分,成功解决了找不到合适JSON转换器的问题。

被折叠的 条评论
为什么被折叠?



