Json对象转为实体对象
1、Bean中申明 trainTypeList:
public class TrainTypeQueryParam implements Serializable { private static final long serialVersionUID = 1L; private String id; private String name; private Integer sortIndex; private String parentId; private Integer corpId; private Integer createrId; // 创建人ID private Date createTime; // 创建时间 private Integer modifierId; // 修改人ID private Date modifyTime; // 修改时间 private String orderBy = null; private String sortType = "ASC"; private PageBean pageBean = new PageBean(); private List<TrainType> trainTypeList = new ArrayList<TrainType>(); public TrainTypeQueryParam() { } //getter、setter方法 }
2、java代码:
/** * @Title: updateSort * @Description: 排序 * @param @param itemjson * @param @param request * @param @return * @return MessageResp * @throws */ @RequestMapping("updateSort") @ResponseBody public MessageResp updateSort(String itemjson, HttpServletRequest request) { MessageResp resp = new MessageResp(); User u = SessionUtils.getUser(request.getSession()); TrainTypeQueryParam params; ObjectMapper mapper = new ObjectMapper(); try { params = mapper.readValue(itemjson,TrainTypeQueryParam.class);//Json对象转为实体对象 List<TrainType> trainTypeList = params.getTrainTypeList(); if(trainTypeList!=null && trainTypeList.size()>0){ for(int i=0;i<trainTypeList.size();i++){ TrainType trainType = new TrainType(); trainType.setId(trainTypeList.get(i).getId()); //ID trainType.setSortIndex(trainTypeList.get(i).getSortIndex()); // trainType.setParentId(trainTypeList.get(i).getParentId()); trainTypeService.update(trainType); //排序 } } resp.setResult("true"); resp.setResultDesc("修改成功!"); } catch (Exception e) { resp.setResult("false"); resp.setResultDesc("修改出错!"); } return resp; }
3、jsp页面传参:
//拖拽大类 function dragBigData(){ $(".coursecate_list").sortable({ stop:function(){ var i=0; var itemjson ={trainTypeList:[]}; $(".coursecate_list").find("div").each(function(){ i++; $(this).attr("data-sortIndex",i); var arr = { "id":$(this).attr("data-id"), "sortIndex":$(this).attr("data-sortIndex") } itemjson.trainTypeList.push(arr); //此处要与Bean中申明list同名 }); var param = {itemjson : JSON.stringify(itemjson)}; $.ajax({ url:"${ctx}/td/trainType/updateSort.do ", type:"get", data:param, success:function(data){ } }); } }).disableSelection(); } //拖拽小类 function dragSmallData(){ $(".coursesmallcate_list").sortable({ stop:function(){ var i=0; var itemjson ={trainTypeList:[]}; $(".coursesmallcate_list").find("div").each(function(){ i++; $(this).attr("data-sortIndex",i); var arr = { "id":$(this).attr("data-id"), "sortIndex":$(this).attr("data-sortIndex") } itemjson.trainTypeList.push(arr); //此处要与Bean中申明list同名 }); var param = {itemjson : JSON.stringify(itemjson)}; $.ajax({ url:"${ctx}/td/trainType/updateSort.do ", type:"get", data:param, success:function(data){ } }); } }).disableSelection(); }