//关于参数传递接受
有@RequestBody方法上这个标签的,前台的参数(ajax)同时采用属性驱动,模型驱动,传到后台,写在方法名上,只能传递一对像不能是list(所以ajax传递的参数data只能是{}),写在参数上可以是list(这是data可以是【{}{}】),用【】要申明是复杂格式的json,详见下面。
这个标签方法return的就是返回回调函数的data
@RequestMapping(value = "/savemobile")
@RequestBody
public int saveMobile(@RequestBody List<User> user ,@RequestParam(value = "yzm", required = false) String yzm) {
@RequestMapping(value = "/savemobile")//这中不可以
public int saveMobile(@RequestBody List<User> user ,@RequestParam(value = "yzm", required = false) String yzm) {
@RequestMapping(value = "/savemobile")//这种可以
@RequestBody
public int saveMobile(@RequestBody List<User> user ) {//这种可以
@RequestMapping(value = "/savemobile")
@ResponseBody//这种可以
public String saveMobile(@RequestParam(value = "yzm", required = false) String yzm , User user ) {
@ResponseBody//卸载外面的时候里面的只能是单个实体
public PageInfo<Role> queryPageSupplier(HttpSession session,
@RequestParam(value = "pageNo", required = false) int pageNo,
@RequestParam(value = "pageSize", required = false) int pageSize,
Role role)
@RequestMapping(value = "/savemobile")
@ResponseBody
public String saveMobile(@RequestParam(value = "yzm", required = false) String yzm , User user ) {
$.ajax({
type: "post",
url: "<%=webPath%>/system/users/savemobile.do",
data: ndata,
dataType: "json",
///////////////////////////// contentType:"application/json",不用list之后这句去了【】是复杂格式标志
success: function (data) {
if (data = 1) {
alert("绑定成功,谢谢!");
} else if (data = 0) {
alert("操作失败,该记录可能已不存在。");
} else if (data > 1) {
alert("错误,有多条记录被删除。");
}
},
error: function (textStatus) {
alert("数据加载失败!!!");
}
});
========复杂格式json提交=========================
@RequestMapping(value = "/savetree")
public String saveTree( @RequestBody List<MenuDto> menuDtos, @RequestParam(value = "roleId", required = false) String roleId) {
$.ajax({
type: "post",
url: "<%=webPath%>/system/acount/savetree.do?roleId="+roleId,
data: JSON.stringify(events),
dataType: "json",
contentType:"application/json"
});
@RequestMapping(value = "/savecheck")
@ResponseBody
public String saveCheck(@RequestBody List<User> user) {//由于前台是【】不是{}
System.out.println("111");
return "redirect:index.do";
}
======================================================