要在pom中 添加两个jar包
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.4</version>
</dependency>
继续在spring-mvc.xml文件中添加如下代码,开启注解,这个代码里面包含了json的转换
<mvc:annotation-driven/>
然后在controller中正常使用即可,例子如下
@RequestMapping(value="/query")
@ResponseBody
public Object query(String name,String pass){
System.out.println(name);
System.out.println(pass);
Kaoqin k = new Kaoqin();
k.setWorktest("新的 ");
return k;
}