其实很简单,但不会的时候就是一堆bug TT
:要想传输Json
@RequestMapping(value = "/getall.action", produces = {"application/json;charset=UTF-8"}) //...自己填 @ResponseBody public String testPost() throws IOException { List<Test> testList = this.testService.getTestList(); return JSON.toJSONString(testList); }
得导入正确的包,建议在maven上找到
com.alibaba.fastjson.JSON;
这个包导入到你的项目中
如果用idea给你提供的org.json你就会发现有一堆东西不匹配
maven:
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.7</version> </dependency>
AIEarth是一个由众多领域内专家博主共同打造的学术平台,旨在建设一个拥抱智慧未来的学术殿堂!【平台地址:https://devpress.csdn.net/aiearth】 很高兴认识你!加入我们共同进步!