1、使用HttpServletResponse来处理
@RequestMapping("/ajax") public void ajax(String name,HttpServletResponse resp) throws IOException { if("qqq".equals(name)) { resp.getWriter().print("true"); }else{ resp.getWriter().print("false"); } } |
2、spring处理json数据
>导入jar包:
>在mvc中配置json转换器
>Controller代码
@Controller public class JsonController { @RequestMapping("/json") @ResponseBody public List<String> json() { List<User> list = new ArrayList<User>(); list.add(new User(1,"zhangsan","男")); return list; } } |