标签:
$.ajax({ url: "/rest/userController/login", type: "post", data: {"username": "chenhao", "password": "123456"} });
@RequestMapping("/login") public String login(@Valid User user){ if(userService.login(user)){ return "index"; } return "login"; }
$.ajax({ url: "/rest/userController/test", type: "post", dataType: "json", data: {"a":"b"} });
@RequestMapping("/test") @ResponseBody public Map<String, Object> test( Map<String, Object> user){ Map<String, Object> map = new HashMap<String, Object>(); map.put("user", user); return map; }
$.ajax({ url: "/rest/userController/test", type: "post", dataType: "json", contentType: "application/json", data: JSON.stringify({"a":"b"}) });
@RequestMapping("/test") @ResponseBody public Map<String, Object> test(@RequestBody Map<String, Object> user){ Map<String, Object> map = new HashMap<String, Object>(); map.put("user", user); return map; }
<!--json数据转换 --> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property value="application/json" name="supportedMediaTypes"/> </bean>
spring mvc 前后端数据交互笔记(解决415,400问题)
标签:
原文地址:http://www.cnblogs.com/chenhao1990/p/4797968.html