打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JQuery以对象提交Form到Spring MVC的方法
JQuery用POST方式直接将Form的数据提交给Spring MVC的方法,最大的坑就是原生类型(long,int)必须要有值,否则就出错。
实体类(注意有原生类型)
public class OltInfo {
long id;
String oltSN;
……
int cards;
int pons;
……
提交的JS:
$(function() {  var s = $("#submitId");
$("#submitId").click(function() {
$.ajax({
url : '/olt/new',
type : 'POST',
dateType : "json",
data : $("#formId").serialize(),
contextType : "application/x-www-form-urlencoded",
success : function(data) {
console.log("success");
}
});
})
});
JSP,注意原生类型必须设置值:
<form id="formId" method="get" action="" class="form-horizontal">  <input type="hidden" name="id" value="0">
<div class="form-group">
<label class="col-sm-2 control-label">序列号</label>
<div class="col-sm-10">
<input type="text" name="oltSN" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">联系人</label>
<div class="col-sm-10">
<input type="text" name="contact" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">手机</label>
<div class="col-sm-4">
<input type="text" name="mobile" class="form-control">
</div>
<label class="col-sm-2 control-label">电话</label>
<div class="col-sm-4">
<input type="text" name="tel" class="form-control">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<label class="col-sm-2 control-label">板卡数</label>
<div class="col-sm-4">
<input type="text" name="cards" value="0" class="form-control">
</div>
<label class="col-sm-2 control-label">PON口数</label>
<div class="col-sm-4">
<input type="text" name="pons" value="0" class="form-control">
</div>
</div>
<div class="hr-line-dashed"></div>
<div class="form-group">
<div class="col-sm-4 col-sm-offset-2">
<button id="submitId" class="btn btn-primary">保存内容</button>
<button class="btn btn-white" type="submit">取消</button>
</div>
</div>
</form>
Spring的Controller,直接接受对象:
@RequestMapping(value = "/new", method = RequestMethod.POST)@ResponseBody
public Map newOlt(OltInfo o) {
logger.info("newOlt..." + o);
……
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
jquery动态增加html
第四节,Bootstrap表单和图片
ASP.NET MVC下Bundle的使用方法
bootstrap怎么才能在点击链接时把那条记录的ID传给modal模态框?
register .jsp
bootsrtap表单
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服