• Json对象转为实体对象


    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();
        }      
  • 相关阅读:
    CVE-2014-6271 Shellshock 破壳漏洞 复现
    0ctf-ezdoor-复现分析
    phpinfo中敏感信息记录
    未授权访问总结学习
    关于PHP内部类的一些总结学习
    PHP反序列化总结
    SSRF和XSS-filter_var(), preg_match() 和 parse_url()绕过学习
    Java14:你需要知道的新特性
    结构型设计模式
    项目总结
  • 原文地址:https://www.cnblogs.com/mingyue1818/p/4825488.html
Copyright © 2020-2023  润新知