Fork me on GitHub

springmvc之返回json类型的数据给前端

1、加入三个Jar包

2、为方法加上@ResponseBody注解,方法直接返回相关信息。

使用ResponseBody注解需要在springmvc.xml文件中配置:

<mvc:annotation-driven></mvc:annotation-driven>
    @ResponseBody
    @RequestMapping("/testJson")
    public Collection<Employee> testJson() {
        return employeeDao.getAll(); 
    }
posted @ 2020-01-13 15:54  西西嘛呦  阅读(680)  评论(0编辑  收藏  举报