bootstrapTable 获取选中CheckBox的所有数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bobyssssssssss/article/details/75045523
按钮
<button id="btn_print" type="button" class="btn btn-default">
	<span class="glyphicon glyphicon-print" ></span>获取BootstrapTable中CheckBox数据
</button>


向后台请求数据ajax:
$("#btn_print").click(function(){
            		var a= $("#tb_departments").bootstrapTable('getSelections');
            		 if(a.length<=0){
            			 alert("请选中一行")
            		}else{
            			var b=JSON.stringify( a );
            			  var url="${pageContext.request.contextPath}/login/datalist";
            	  		    $.ajax({
            	  		        dataType: "json",
            	  		        traditional:true,//这使json格式的字符不会被转码
            	  		        data: {"datalist":b},
            	  		        type: "post", 
            	  		        url: url,
            	  		        success : function (data) {
            	  		            alert("成功!");
            	  		        },
            	  		        error : function (data){
            	  		            alert(data.responseText);
            	  		        }
            	  		    });
            		} 
            		
            	});






前台发送json格式为:
datalist:[{"0":true,"uid":1,"ustatus":"12","uname":"admin","upwd":"1234"},{"0":true,"uid":2,"ustatus":"12","uname":"liangq","upwd":"liang123"}]
后台获取数据
@RequestMapping("/datalist")
	@ResponseBody
	public boolean listUserTable(@RequestParam("datalist") String list,HttpServletRequest request){
//		String parameter = request.getParameter("list");
		System.out.println("list:"+list);
		JSONArray jsonArray = JSONArray.fromObject(list);
		System.out.println("fromObject"+jsonArray);
		List<Map<String,Object>> mapListJson = (List)jsonArray;
        for (int i = 0; i < mapListJson.size(); i++) {
            Map<String,Object> obj=mapListJson.get(i);
             
            for(Entry<String,Object> entry : obj.entrySet()){
                String strkey1 = entry.getKey();
                Object strval1 = entry.getValue();
                if ("0".equals(strkey1)) {
					
				}else{
					System.out.println("KEY:"+strkey1+"  -->  Value:"+strval1+"\n");
				}
                
            }
        }
		
		
		return true;
	}
获取数据解析后json转map:
KEY:ustatus  -->  Value:12

KEY:uname  -->  Value:admin

KEY:upwd  -->  Value:1234

KEY:uid  -->  Value:2

KEY:ustatus  -->  Value:12

KEY:uname  -->  Value:liangq

KEY:upwd  -->  Value:liang123















            

没有更多推荐了,返回首页