前言
今天复习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">