前端jsp页面发请求如下:
$.ajax({
url: $(form).attr("action"),
type: $(form).attr("method"),
data: {
tel:$("#tel").val(),
schoolMainId : $("#hidd").val()
},
datatype: "json",
success: function (data) {
if(data.flag == '1'){ // 选择成功
layer.msg("选择成功",{icon: 1,shade: [0.1, '#393D49'],time:2000},function () {
parent.layer.close(index);
});
}
},
error: function (error) {
}
})
后端Controller 接受值并且返回响应:
@RequestMapping(value="/chooseShopAlre")
@ResponseBody
public void chooseShopAlre(String schoolMainId,String tel,HttpServletResponse response) {
PrintWriter out;
try {
Map<String,String> map = new HashMap<String,String>();
UserShop userShop = eduSchoolMainService.getUsersShopByTel(tel);
EduSchoolMain eduSchoolMain = eduSchoolMainService.getEduSchoolMiain(schoolMainId);
eduSchoolMain.setUser_shop_id(userShop.getId());
int flag = eduSchoolMainService.updateEduSchoolMainUserShopId(eduSchoolMain);
if(flag == 1) {
map.put("flag", "1");
}
out = response.getWriter();
response.setContentType("application/json; charset=utf-8");
JSONObject responseJSONObject = JSONObject.fromObject(map);
out.print(responseJSONObject.toString());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}