The business needs to transfer the data of several selected rows in the front-end jQuery easyUI DataGrid list to the background for update operation
Normally we will get the ID of the selected row object through a loop And simply encapsulate it into a long String and send it to the service layer, and then use findByID to get the instance and update
But this time we need to completely transmit the entire object group to the background
The structure is as follows
Use Google's GSON plug-in and json2.js together
The front-end code is as follows, some simple verification codes have been removed for the sake of simplicity:
var rows = $('#dg1').datagrid('getSelections');
$.ajax({
cache : false,
type : "POST",
url : _basePath '/sectionGroup/pair',
data : {rows : JSON.stringify(rows ), group_id : group_id, group_name : group_name},
success : function(data) {
if(data.success == true){
$.messager.confirm('Configuration successful','whether Refresh the list? ', function(r){
if (r){
$('#dg').datagrid('reload');
$('#dg1').datagrid(' reload');
$('#dg2').datagrid('reload');
}
});
}else{
$.messager.show({
title:'Prompt',msg:'Configuration failed',
showType:'fade',style:{right:'',bottom:''}
});
}
}
});
This page needs to introduce json2.js
The background Controller receives the following:
@RequestMapping(value = "/pair")
@ResponseBody
public ResponseData pair(String rows, String group_name , String group_id, HttpServletRequest request) {
User user = (User) SecurityContextUtil.getCurrentUser();
if (user == null) {
user = (User) request.getSession().getAttribute( Constants.USER_OS);
}
Gson gson = new Gson();
List list = gson.fromJson(rows, new TypeToken>() {}.getType ());
for (SectionGroup sectionGroup : list) {
sectionGroup.setRegion(user.getRegion_id());
sectionGroup.setCompany_id(user.getOrg_id());
sectionGroup.setGroup_id( group_id);
sectionGroup.setGroup_name(group_name);
service.insertEntity(sectionGroup);
}
return ResponseData.SUCCESS_NO_DATA;
}
where GSON And TypeToken is a class introduced in the GSON package
The input parameter rows should be of String type
After Gson conversion, the List is still a normal interface, and the complete Object object at the front end is loaded internally.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn