Submission of tree-structured data

tree structure data submission problem

(1) Marking, the association work is carried out in jsp

The complex association problem of submitting data based on the tree structure, the name and value of a control cannot contain all the associated information and its own information, so the hidden field is used.

Since the hidden fields are all submitted, the hidden field value is used as the key, and the one that can get the selected value is selected.

Therefore, when organizing the hidden field and selection box data, follow the key-value-key-value (the middle key-value is the same)

All the keys to see if they are selected are submitted in the hidden field, and the hidden field is obtained through the request as the value of the value, and the description that can be obtained is selected.

when assembled

1. As long as the button can get (K), the currently traversed menuId is used as menuId, and part of the information in the current button value is used as value

2. There is no button but the description by get(K)=1 is a single selected page

 

(2) Submit the selected value directly, and put the relationship in the background (check the database) (so that the rendering of the tree structure (the organization of data values ​​is also simple))

 

1, the submitted value parent node is not 100000 (excluding folders)

2. The submitted node is found in the menu table (the page is selected)

3. The submitted node is found in the menuLIst button table (the button is selected)

 That is: A: The traversal is that the button is selected, and the page id of this button is checked out at the same time (the data record addition menu can be checked more) (just the button)

 B: It is the page that is traversed that is selected (just the page)

   

   In order to reduce the traversal of the database, you can mark which level (page, button, value = "100000; 1") or mark its parent at the button level (value = ("100000; 110000")) to detect it; it is the button level ,

   no; just the page

First use all the outermost layers as keys (traverse the existing outermost layers of the database), get all the selected values, and then process as above

request.getParameter("Outer Key")

 

I only have pages and buttons with name here

 

///////Use $("<table></table>") in this way to facilitate dynamic tree building.

In the tree structure selection, jsp submits data, a feature used: the input of the same name (such as all domain values, various controls) submitted to the background will be a string separated by ",",

This kind of domain with the same name needs to undertake comma-separated values ​​1, using model-driven attributes (can be string, string[]), 2, attribute-driven (can be String, String[]), 3, if using String[] a=request.getParameterValues("subsystem");

To have this otherwise, using getparamet() will only be a

 For example, the following example: I only have pages and buttons with names here (pages of the same general category, buttons have the same name)

 String initialization String[] a=new String[]{};

other:

Press the installed third-party software to access directly with ip + the port of the software

 

The insert operation of the general mapper automatically returns the id

opmRoleMapper.insert(role);

OpmRolelimit roleLimt1 = new OpmRolelimit();

roleLimt1.setRoleid(role.getId());

 

//The request parameter cannot be passed in when the @control layer calls the method in @service, otherwise it will not be called (nor will ServletRequests)

 

int updateRole(String organid,OpmRolelimit opmLimt,HttpServletRequest request) throws Exception;

 

 

The maintenance of third parties like role permissions should first be deleted according to the role ID, and then added according to the role ID.

 

Example:

 

jsp:================

<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>

<%@ include file="../common/include.inc.jsp"%>

<c:import url="../common/pagerForm.jsp"></c:import> 

 

<div class="pageContent">

<form method="post" action="<c:url value='/system/opmRole/update'/>" class="pageForm required-validate" onsubmit="return validateCallback(this,navTabAjaxDone);">

<input type="hidden" name="id" value="${vo.id}"/>

<input type="hidden" name="inUrl" value="${inUrl}"/>

<input type="hidden" name="roleId" value="${roleId}"/>

<input type="hidden" name="leave" value="${leave}"/>

<input type="hidden" name="pId" value="100000"/>

<input type="hidden" name="organid" value="${organid}"/>

<input type="hidden" name="pId1" value="100000"/>

<input type="hidden" name="pId1" value="110000"/>

<div class="pageFormContent" layoutH="57">

 <fieldset>

     <dl style="width: 23%">

       <dt>Market:</dt>

       <dd>${organName}</dd>

     </dl>

     <dl style="width: 33%">

       <dt>名称:</dt>

       <dd><input type="text" name="name" value="${vo.name}" class="required alphanumeric"  maxlength="16"/></dd>

     </dl>

     <dl style="width: 44%">

       <dt style="width: 14%">描述:</dt>

       <dd style="width: 84%"><input type="text" name="memo" value="${vo.memo}"   maxlength="100"/>最多100个汉字</dd>

     </dl>

   </fieldset>

<div id="div1" style="width:100%;float: left;" >

</div>

</div>

<div class="formBar">

<ul>

<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>

<li><div class="button"><div class="buttonContent"><button type="button" class="reset">重置11</button></div></div></li>

<li><div class="button"><div class="buttonContent"><button type="button" class="close">关闭11</button></div></div></li>

<li><div class="button"><div class="buttonContent"><button type="button" onclick="appendTable();">test</button></div></div></li>

</ul>

</div>

    </form>

</div>

 

 

 

 

<script type="text/javascript">

 

 

 

$(function(){

appendTable();

});

function appendTable() {

var roleId=$("input[name='roleId']").val();

var leave=$("input[name='leave']").val();

var pId=$("input[name='pId']").val();

var dataParent = {

roleId: roleId,

leave:leave,

pId:pId

 

   };

$.ajax({

        type: "post",

        url: "${pageContext.request.contextPath}/system/opmRole/Auths",

        data: dataParent,

        success: function (data) {

        if(data!=''&&data!=null){

        var div1=$("#div1");

        var table1=$("<table></table>");

        var arr = eval (data);

        for(j=0;j<arr.length;j++){

        if(arr[j].leave=='1'){

        var row =$("<tr></tr>");

        var td =$("<td></td>");

        td.append($(arr[j].str));

        row.append(td);

        table1.append(row);

        }

        var row2;

        if(arr[j].leave=='2'){

        row2 =$("<tr></tr>");

        var td =$("<td></td>");

        td.append(arr[j].str);

        row2.append(td);

        table1.append(row2);

        }if(arr[j].leave=='3'){

        var td =$("<td></td>");

        td.append(arr[j].str);

       

        table1.find("tr:last").append(td);

        }

        }

        div1.html(table1);

        }else{

        alert("The member number you entered does not exist!");

        }

       

        },

        error:function(data){

        alert("Data loading exception!");

       

        }

    }); 

 

 

}

 

 

//select all check box

function checkedAllBox(obj) {

if(obj.checked){

var a = document.getElementsByName(obj.value);

for (i = 0; i < a.length; i++) {

a[i].checked=true;

}

}else{

var a = document.getElementsByName(obj.value);

for (i = 0; i < a.length; i++) {

a[i].checked=false;

}

}

}

</script>

 

 

@control:================================

 

@SuppressWarnings("unused")

@RequestMapping(value = "/system/opmRole/update", method = RequestMethod.POST)

public ModelAndView opmUpdate(OpmRole opmRole,HttpServletRequest request,Model modle) throws Exception {

int flag=0;

OpmMenufolder folder = new OpmMenufolder();

folder.setParentid("100000");

List<OpmMenufolder> opmMenufolders= opmMenufolderService.getOpmMenufolder(folder);

String[] a=new String[]{};

List<String> list = new ArrayList<String>();

try{

for(OpmMenufolder o: opmMenufolders){

a=request.getParameterValues(o.getId());

if(a==null||"".equals(a)){

continue;

}

list.addAll(Arrays.asList(a));

}

Map<String,Object> param = new HashMap<String,Object>();

OpmRolelimit opmLimt = new OpmRolelimit();

String org= opmRole.getOrganid();

flag = opmRoleService.updateRole(opmRole, list);

//

 

return ajaxDoneOpm("/commonuntil/ajaxDone",200,"操作成功!","opmRoleNavUi","/system/opmRole/editUi","closeCurrent");

}catch (Exception e){

return ajaxDoneOpm("/commonuntil/ajaxDone",300,"添加失败!","opmRoleNavUi","/system/opmRole/editUi","closeCurrent");

//throw new Exception("Operation failed!");

}

 

 

}

 

 

 

@SuppressWarnings("rawtypes")

@RequestMapping(value="/system/opmRole/Auths")

@ResponseBody

public JSONArray treeRead(@RequestParam(value="leave") String leave,@RequestParam(value="roleId") String roleId,@RequestParam(value="pId")  String pId,@RequestParam(value="groupId",required=false)  String groupId1){

List<String> strl= new ArrayList<String>();

String str="";

JSONArray JsonArray = new JSONArray();

Map<String,Object> param = new HashMap<String,Object>();

param.put("pId", pId);

List<Map> map= opmMenufolderService.getfordMenuLimt(param);

Map<String,Object> param1 = new HashMap<String,Object>();

String groupId=groupId1;

for(Map p: map){

 

param1.put("pId", p.get("ID"));

String l= (String) p.get("LEAVE");

if("1".equals(l)){

if("100000".equals(p.get("PARENTID")+"")){

groupId=(String)p.get("ID");

   str+="<label style=\"float:left\"><input type=\"checkbox\" class=\"checkboxCtrl\" value="+p.get("ID")+" group="+groupId+" selectType=\"invert\" />"+p.get("NAME")+"</label>"+"\n";

   strl.add(str);

   JSONObject Json = new JSONObject();

   Json.put("ID", p.get("ID")+"");

   Json.put("NAME", p.get("NAME")+"");

   Json.put("groupId", groupId);

   Json.put("parentId", p.get("PARENTID"));

   Json.put("leave", l);

   Json.put("str", "<label style=\"float:left;width:150px;\"><input type=\"checkbox\" class=\"checkboxCtrl\" value="+p.get("ID")+"  onclick=\"checkedAllBox(this);\" group="+groupId+" //>"+p.get("NAME")+"</label>"+"\n");

   JsonArray.add(Json);

   

   

}else{

str+="<label><input type=\"checkbox\" value="+p.get("ID")+" name="+groupId+"/>"+p.get("NAME")+"</label>"+"\n";

strl.add(str);

JSONObject Json = new JSONObject();

   Json.put("ID", p.get("ID")+"");

   Json.put("NAME", p.get("NAME")+"");

   Json.put("groupId",groupId);

   Json.put("parentId", p.get("PARENTID"));

   Json.put("leave", l);

   Json.put("str","<label style=\"width:150px;\">   "+p.get("NAME")+"</label>"+"\n");

   JsonArray.add(Json);

}

}

if("2".equals(l)){

if(Integer.valueOf(leave)<0){

if(Integer.valueOf(p.get("LEAVE1")+"") >=Integer.valueOf(leave)){

str+="<label><input type=\"checkbox\" value="+p.get("ID")+"  name="+groupId+"/>"+p.get("NAME")+"</label>"+"\n";

strl.add(str);

JSONObject Json = new JSONObject();

   Json.put("ID", p.get("ID")+"");

   Json.put("NAME", p.get("NAME")+"");

   Json.put("groupId", groupId);

   Json.put("parentId", p.get("PARENTID"));

   Json.put("leave", l);

   Json.put("str","<label style=\"width:150px;\">      <input type=\"checkbox\" value="+p.get("ID")+"  name='"+groupId+"'/>"+p.get("NAME")+"</label>"+"\n");

   JsonArray.add(Json);

}

}else{

//EVERYTHING

Map<String,Object> param2 = new HashMap<String,Object>();

param2.put("menuItemId", p.get("ID"));

param2.put("menuItemLimitId", null);

param2.put("roleId", roleId);

param2.put("displayOrder", Integer.valueOf(-1));

List <OpmRolelimit> rl = opgRolelimitService.getRoleLimitByTJ (param2);

if(rl!=null&&rl.size()>0&&Integer.valueOf(p.get("LEAVE1")+"") >=Integer.valueOf(leave)){

str+="<label><input type=\"checkbox\" value="+p.get("ID")+" name="+groupId+"/>"+p.get("NAME")+"</label>"+"\n";

strl.add(str);

JSONObject Json = new JSONObject();

   Json.put("ID", p.get("ID")+"");

   Json.put("NAME", p.get("NAME")+"");

   Json.put("groupId", groupId);

   Json.put("parentId", p.get("PARENTID"));

   Json.put("leave", l);

   Json.put("str","<label style=\"width:150px;\">      <input type=\"checkbox\" value="+p.get("ID")+" name='"+groupId+"'/>"+p.get("NAME")+"</label>"+"\n");

   JsonArray.add(Json);

}

}

}

if("3".equals(l)){

Map<String,Object> param2 = new HashMap<String,Object>();

param2.put("menuItemId", p.get("PARENTID"));

param2.put("menuItemLimitId", p.get("ID"));

param2.put("roleId", roleId);

param2.put("displayOrder", null);

List <OpmRolelimit> rl2 = opgRolelimitService.getRoleLimitByTJ (param2);

String tempg=groupId;

if(rl2!=null&&rl2.size()>0){

str+="<label><input type=\"checkbox\"  value="+p.get("ID")+" name="+groupId+"/>"+p.get("NAME")+"</label>"+"\n";

strl.add(str);

JSONObject Json = new JSONObject();

   Json.put("ID", p.get("ID")+"");

   Json.put("NAME", p.get("NAME")+"");

   Json.put("groupId", groupId);

   Json.put("parentId", p.get("PARENTID"));

   Json.put("leave", l);

   Json.put("str","<label style=\"width:150px;\"><input type=\"checkbox\"  value="+p.get("ID")+" name='"+groupId+"'/>"+p.get("NAME")+"</label>"+"\n");

   JsonArray.add(Json);

}

}

//str+=treeRead(leave,roleId,p.get("ID")+"",groupId);

JsonArray.addAll(treeRead(leave,roleId,p.get("ID")+"",groupId));

}

return JsonArray;

}

 

 

 

@service:=========================================

 

@Override

@Transactional(rollbackFor=Exception.class)

public int updateRole(OpmRole opmRole,List<String> list) throws Exception {

// TODO Auto-generated method stub

System.out.println("==========================213213213===================");

if("".equals(opmRole.getOrganid())||null==opmRole.getOrganid()){

throw new Exception("The incoming parameter is empty!");

}

TbCusMark tbCusMark = new TbCusMark();

   tbCusMark.setMarketKey(BigDecimal.valueOf(Long.valueOf(opmRole.getOrganid())));

   TbCusMark mark= tbCusMarkMapper.selectOne(tbCusMark);

   if(mark==null){

   throw new Exception("The market cannot be found!");

   }

OpmRole role =new OpmRole();

if(opmRole.getId()==null||"".equals(opmRole.getId())){

role.setOrganid(opmRole.getOrganid());

role.setLevel1(Short.valueOf("0"));

role.setName(opmRole.getName());

role.setMemo(opmRole.getMemo());

opmRoleMapper.insert(role);

}else{

OpmRolelimit opmRolelimit = new OpmRolelimit();

opmRolelimit.setRoleid(opmRole.getId());

   opmRolelimitMapper.deletRoleLimts(opmRolelimit);

}

OpmMenuitemlimit opmMenuitemlimit = new OpmMenuitemlimit();

List<OpmMenuitemlimit> opmLimits= opmMenuitemlimitMapper.select(opmMenuitemlimit);

OpmMenuitem item = new OpmMenuitem();

List<OpmMenuitem> items= opmMenuitemMapper.select(item);

try{

 

for(String l :list){

OpmRolelimit opmLimt = new OpmRolelimit();

int up=0;

for(OpmMenuitem i: items){

if(i.getId().equals(l)){

opmLimt.setMenuitemid(i.getId());

opmLimt.setDisplayorder(-1L);

opmLimt.setName("View");

 

if(opmRole.getId()==null||"".equals(opmRole.getId())){

   opmLimt.setRoleid(role.getId());

   up= opmRolelimitMapper.insert(opmLimt);

}else{

opmLimt.setRoleid(opmRole.getId());

   up= opmRolelimitMapper.insert(opmLimt);

}

break;

}

}

if(up==0){

for(OpmMenuitemlimit lm : opmLimits){

if(lm.getId().equals(l)){

opmLimt.setMenuitemid(lm.getMenuitemid());

opmLimt.setDisplayorder(lm.getDisplayorder());

opmLimt.setName(lm.getName());

opmLimt.setMenuitemlimitid(lm.getId());

opmLimt.setDisplayorder(lm.getDisplayorder());

opmLimt.setName(lm.getName());

String org= opmRole.getOrganid();

                         if(opmRole.getId()==null||"".equals(opmRole.getId())){

                        opmLimt.setRoleid(role.getId());

  up= opmRolelimitMapper.insert(opmLimt);

}else{

opmLimt.setRoleid(opmRole.getId());

   opmRolelimitMapper.insert(opmLimt);

}

break;

}

 }

}

}

}catch(Exception e){

 

throw new Exception("Save character exception!");

}

return  1;

}

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326515879&siteId=291194637