问题现象
后台返回List,前端页面无法接受
查找原因
1.使用@RestController注解
2.Maven添加依赖
3.配置文件开启注解驱动
通过查找,发现是 注解驱动选择错误,使用了:
xmlns:mvc="http://www.springframework.org/schema/tx"
应该使用:
xmlns:mvc="http://www.springframework.org/schema/mvc"
更正后查询结果
使用postman显示正确
更正后配置文件
<?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 https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.lw.cn.controller"/>
<mvc:annotation-driven/>
</beans>