赞
踩
前端发出的请求:path?id=1;
@RequestMapper(value="path")
public void test(@RequestParam("id") int id){
System.out.println(id);
}
获取前端传来的非json格式的数据
// 单个数据,@RequestParam中的值一定要与前端属性名一致
public void test(@RequestParam("name)" String name){
System.out.println(params);
}
// 数组数据
@RequestMapper(value="path")
public void test(@RequestParam Map<String,Object> params){
System.out.println(params);
}
前端发出的请求:path/{id};
@RequestMapper(value="path/{id}")
public void test(@PathVariable("id") int id){
System.out.println(id);
}
获取前台出来的json格式的数据
$.ajax({ type: 'POST',//方法类型 url: url, contentType: 'application/json', data: { "username":"小明", "sex":"男", "age":"18" }, success: function (result) { if (result == 200) { $('#goodsModal').modal('hide'); swal({ title: swlMessage, type: 'success', showCancelButton: false, confirmButtonColor: '#1baeae', confirmButtonText: '返回商品列表', confirmButtonClass: 'btn btn-success', buttonsStyling: false }).then(function () { window.location.href = "/admin/goods"; }) } else { $('#goodsModal').modal('hide'); swal(result.message, { icon: "error", }); } ; } });
// bean
public class User{
private String username;
private String sex;
..
}
// Controller中代码片段
@RequestMapper(value="path/{id}",method = RequestMethod.POST)
public void test(@RequestBody User user){
System.out.println(user);
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。