小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

JQuery以對象提交Form到Spring MVC的方法

 KyunraWang 2017-09-07
JQuery用POST方式直接將Form的數(shù)據(jù)提交給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,注意原生類型必須設(shè)置值:
<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">聯(lián)系人</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">板卡數(shù)</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口數(shù)</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">保存內(nèi)容</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);
  ……
}



    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約