关于springmvc返回json格式数据

1.引入maven依赖

 1 <dependency>
 2             <groupId>com.fasterxml.jackson.core</groupId>
 3             <artifactId>jackson-databind</artifactId>
 4             <version>2.9.3</version>
 5         </dependency>
 6         <dependency>
 7             <groupId>com.fasterxml.jackson.core</groupId>
 8             <artifactId>jackson-core</artifactId>
 9             <version>2.9.3</version>
10         </dependency>
11         <dependency>
12             <groupId>com.fasterxml.jackson.core</groupId>
13             <artifactId>jackson-annotations</artifactId>
14             <version>2.9.3</version>
15 </dependency>
maven依赖

2.配置注解

1 <!-- 使用默认的注解映射 -->
2 <mvc:annotation-driven />
注解配置

3.使用@ResponseBody

1  @RequestMapping("/getJson")
2     @ResponseBody
3     public Object getJson(){
4         User user = new User();
5         user.setId("123");
6         user.setName("里哈");
7         return user;
8     }
代码示例

 

posted on 2018-02-06 01:25  bluej  阅读(230)  评论(0编辑  收藏  举报

导航