后端 传输 json 数据(导包错误)

来源:互联网 发布:淘宝正品潮牌店 编辑:程序博客网 时间:2024/06/05 10:43

其实很简单,但不会的时候就是一堆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>
原创粉丝点击