标签:spring mvc json
import org.springframework.beans.factory.annotation.Autowired;}
注解配置!!!!!!!!!!!!!!!!!!!!
@RequestMapping(value="/Home/writeJson", method=RequestMethod.GET, produces = "text/html;charset=UTF-8")
@ResponseBody
public Object writeJson(HttpServletResponse response)
{
ObjectMapper mapper = new ObjectMapper();
HashMap<String,String> map = new HashMap<String,String>();
map.put("1","张三");
map.put("2","李四");
map.put("3","王五");
map.put("4", "Jackson");
String json = "";
try
{
json = mapper.writeValueAsString(map);
System.out.println(json);
}
catch(Exception e)
{
e.printStackTrace();
}
return json;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:spring mvc json
原文地址:http://blog.csdn.net/u010220089/article/details/48049343