Spirng MVC 和Jquery easyui实现添加多个MODEL 博客分类: Spring MVCjquery-easyui SpringMVCjquery-easyuijquery
JAVA
SpringMVC @Controller
中的add方法 添加前台JSP传过来的MODEL
@RequestAttribute(value = "detailModel") DetailModel detailModel,
Service方法 把model里 “,”分割的属性取出来 重新放到MODEL里,新增
private void addDetailModel(DetailModel detailModel){
if(detailModel != null){
if(detailModel.getCustomName()!= null){
String b[] = detailModel.getCustomName().split(",");
for(int i=0;i<b.length;i++){
DetailModel detailModelTemp = new DetailModel();
long detaileId2 = IdUtil.nextId("DetailModel");
detailModelTemp.setDetaileId(detaileId2+"");
detailModelTemp.setProId(detailModel.getProId());
detailModelTemp.setCreateTime(DateUtils.getCurrentTime());
//单据类型-收费
detailModelTemp.setBillType(BillEType.FEEIN);
//受让方
detailModelTemp.setCustomType(detailModel.getCustomType());
//交款单位
detailModelTemp.setCustomName(detailModel.getCustomName().split(",")[i]);
// uniBillType收费科目
detailModelTemp.setUniBillTypeName(detailModel.getUniBillTypeName().split(",")[i]);
//应收总金额
detailModelTemp.setDetailTotalShould(detailModel.getDetailTotalShould().split(",")[i]);
//实收总金额
detailModelTemp.setDetailTotal(detailModel.getDetailTotal());
detailModelTemp.setBillId(detailModel.getBillId());
comissionPageDao.saveAddDetailModel(detailModelTemp);
}
}
}
}
JSP==========
<!-- 转让方列表 -->
<div id="addDiv">
<div>
<td>转让方</td>
<td>
<table border="1" id="addTable">
<thead>
<tr >
<td width="23%" class="datagrid-header">交款单位</td>
<td width="15%" class="datagrid-header">收费科目</td>
<td width="18%" class="datagrid-header">应收总金额</td>
<td width="18%" class="datagrid-header">实收总金额</td>
<td class="datagrid-header">操作</td>
</tr>
</thead>
<tbody>
<c:if test="${not empty detailModelList}">
<c:forEach items="${detailModelList}" var="a">
<tr class="myTr">
<td><input type="text" value="${a.customName}" name="detailModel.customName"/></td>
<td><input type="text" value="${a.uniBillTypeName}" name="detailModel.uniBillTypeName" size="10"/></td>
<td><input type="text" value="${a.detailTotalShould}" name="detailModel.detailTotalShould" size="10"/></td>
<td><input type="text" value="${a.detailTotal}" name="detailModel.detailTotal" size="10"/></td>
<td>
<input type="button" value="+" onclick="addDiv()">
<input type="button" value="-" id="rt" onclick="removeTr(this)">
</td>
</tr>
</c:forEach>
</c:if>
</tbody>
</table>
</td>
</div>
</div>
</tr>
JS======
<style type="text/css">
td{
border: 1px solid silver ;
height: 30px;
font-size:12px;
padding-left: 10px;
padding-right: 10px;
}
.td1{
background-color: #d3e8fa;
font-weight:bold;
}
.yin{
display: none;
}
</style>
function addDiv(){
var tr = '<tr class="myTr">'
+' <td><input type="text" name="detailModel.customName"/></td>'
+' <td><input type="text" name="detailModel.uniBillTypeName" size="10"/></td>'
+' <td><input type="text" name="detailModel.detailTotalShould" size="10"/></td>'
+' <td><input type="text" name="detailModel.detailTotal" size="10"/></td>'
+' <td>'
+' <input type="button" value="+" onclick="addDiv()">'
+' <input type="button" value="-" id="rt" onclick="removeTr(this)">'
+' </td>'
+'</tr>'
if($('#addDiv').hasClass('yin')){
$('#addDiv').removeClass('yin');
}
$('#addTable tbody').append($(tr));
$.parser.parse($('#addTable'));
}
function removeTr(o){
var tr = $(o).parent().parent();
tr.remove();
if($('.myTr').size() == 0){
$('#addDiv').addClass('yin');
}
}