1.转为bean
前台页面
<form method="post" class="x-layout-center " id="theform">
<div class="archives-form" style="text-align: center;">
<h4 class="text-center archives-title">新增试题</h4>
<table border="0" align="center" width="100%" class="archives-table" style="margin-top: 20px;">
<tr>
<td style="width: 100px; text-align: center;">
<label class="x-form-label">名 称</label>
<span style="color: red;">*</span>
</td>
<td>
<input class="x-form-text form-control" id="topicName" name="topicName" placeholder="请输入试题名称" x-form-validate="isNull<试题名称不能为空>;max[30]<试题名称长度不能超过30个字符>;"/>
</td>
</tr>
<tr>
<td style="width: 100px; text-align: center;">
<label class="x-form-label">题库组</label>
<span style="color: red;">*</span>
</td>
<td>
<div class="input-group" id="customer" style="width: 100%;">
<input type="hidden" id="topicGroupName" name="topicGroupName"/>
<div class="x-form-combobox-group" x-form-validate="selectNum[1]<请选择或新增题库>" style="width: 100%;">
<input class="x-form-text" id="topicGroupId" name="topicGroupId" placeholder="请选择或新增题库" />
</div>
<div class="input-group-addon">
<span class="fa fa-book" style="cursor: pointer; border-left: 0px;" οnclick="addTopicGroup()"> 新增</span>
</div>
</div>
</td>
</tr>
</table>
<button type="button" class="btn btn-success" οnclick="onSave()" style="margin-top: 25px; width: 120px;">保 存</button>
</div>
</form>
js
var data = formValidate.serializeObject("#theform");//注意,这里序列化表单,表单元素的name要与实体bean对应。
$.post(url, data, function(result) {
if (result.success == true) {
//成功
}, "x-panel-success");
} else {
//失败
}
}, "json");
后台代码
@RequestMapping("/deleteTopicFlat.do")
@ResponseBody
public JsonMsg deleteTopicFlat(HttpServletResponse response, HttpServletRequest request,
@ModelAttribute Bean bean) {
}
2. 转为list
注意,转为list,则需要前台传的是一个数组,后台则直接用List接收,如下
后台接收
@RequestMapping("/aaa")
@ResponseBody
public Object aaa(@RequestBody List<SysUser> syss){
SysDepart model= sysDepartService.findById(guid);
return model;
}