• jsp 页面传多个id 到java后台的处理方式


    java 开发中经常遇到 jsp 页面传多个id 到后台处理的情况。比如:批量删除选择内容等.......

    我使用的解决的方法两种:

    jsp 传多个id:使用easyui datagrid 选择多行方式

    var rows = $("#classids").datagrid('getSelections'); // 选择多行
    var class_id= [];
    for(var i=0; i<rows.length; i++){
          class_id.push(rows[i].classid);// 传id到数组
    }
    // 使用 Ajax 传到后台
    $.ajax({
    	    url : "${ctx}/class/selectClass?class_id="+class_id,
    	    type : 'post',
    	    success:function(data){
    	    	layer.closeAll();
    	    	if(data.flag==true||data.flag=='true'){
    	    		parent.layer.alert(data.msg,{icon: 1, title:'提示'});
    	    		selectAll();
    	    	}else{
    	    		parent.layer.alert(data.msg,{icon: 2, title:'提示'});
    	    	}
    	    }
    	});   	    
    

      

    1:后台解决方法第一种

    直接在后台Controller 中拆开ids:      

    String class_ids= request.getParameter("class_id");// 获取选择内容ids

    String[] ids= class_ids.split(","); // 拆开 ids

    for (int i = 0; i < ids.length; i++) {
      map.put("ids", ids[i]); // 一个一个传
      sCloudApplyService.updateSchoolApplyStatus(map);// 我这里是修改状态,也可以删除操作等等。根据个人的业务逻辑修改。
    }

    2:后台解决方法第二种

    把多个id不做处理,直接传到数据库操作 sql中。

     @RequestMapping(value = "/batch_update_subjectiveuser_score",produces = "application/json;charset=UTF-8")
        @ResponseBody
        public String updateSchoolApplyStatus(@RequestParam(value = "class_id", required = true)List<String> classids   // 一定不要忘了 这个参数:required = true。含义是:class_id不能为空,若是为空就会提示
        ,HttpServletRequest request, HttpServletResponse response){

        Map<String, Object> map = new HashMap<>();
        map.put("classids",classids);

        sCloudApplyService.updateSchoolApplyStatus(map);// 我这里是修改状态,也可以删除操作等等。根据个人的业务逻辑修改。

    }



    mysql  sql:修改班级类型
    <update id="updateSchoolApplyStatus" parameterType="map">
            update class
            set
              type=1
     		where
     			subject_answer_id in
            <foreach collection="classids" item="ids" open="(" separator="," close=")">
                ${ids}
            </foreach>
        </update>
    

        

    如果有比我这更容易的方法,欢迎在下面留言!!!!!谢谢

  • 相关阅读:
    eclipse中的Invalid text string (xxx).
    在jsp文件中出现Unknown tag (c:out)
    eclipse 界面复原
    ecilpse 纠错插件
    Multiple annotations found at this line:- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path
    Port 8080 required by Tomcat v9.0 Server at localhost is already in use. The server may already be running in another process, or a system process may be using the port.
    调用第三方https接口
    调用第三方http接口
    创建带值枚举
    spring整合redis之Redis配置文件
  • 原文地址:https://www.cnblogs.com/bb1008/p/9962733.html
Copyright © 2020-2023  润新知