树形结构数据的提交

树形结构数据提交问题

(1)标记,关联工作在jsp中进行

基于树形结构提交数据的复杂关联问题一个控件的name,value无法包含所有关联信息,自身信息,故用隐藏域,

由于隐藏域是统统提交,所以用隐藏域value作为key,能获取被选中值的就是被选中了,

所以组织隐藏域和选择框数据的时候按照key-value-key-value(中间的key-value相同)

所有看有没有被选中的关键就在隐藏域提交所有的,通过request获取隐藏域作为值的value,能获取到的说明是选中的

组装时

1,只要按钮能get(K)到的就把当前遍历的menuId作为menuId,当前按钮value中带的部分信息作为value

2,没有按钮但是通过get(K)=1的说明是单个被选中页面

(2)直接就提交选中值,至于关联关系放到后台(查数据库)(这样对于树形结构的渲染(数据值的组织也简单))

1,提交的值父节点不是100000(排除文件夹)

2,提交的节点在menu表中找到(页面被选中)

3,提交的节点在menuLIst按钮表中被找到(按钮被选中)

 即:A:遍历的是按钮被选中,把这个按钮的页面id同时查出(数据录增加菜单可以不用多查)(只管按钮)

 B:遍历的是页面被选中(只管页面)

   

   为了减少遍历数据库,可以在之中标记是哪级(页面,按钮,value=“100000;1”)或者在按钮级别标记其父(value=("100000;110000"))检测有;就是按钮级别,

   没有;就是页面

先以所有的最外层作为key(遍历数据库现有的最外层),获取所有被选中的值,再像上面处理

request.getParameter(“外层Key”)

我这里只有页面和按钮有name

///////用$("<table></table>")这种方式根方便动态构建树。

树形结构选择中jsp提交数据,用的一个特性:同名的input(等一切域值,各种控件的)提交到后台会是一个用“,”隔开的字符串,

这种同名的域需要承接逗号分隔的值1,用模型驱动中的属性(可以是string,string[]),2,属性驱动(可以是String,String[]),3,如果用String[] a=request.getParameterValues("subsystem");

要有这种否则,用getparamet()只会是一个

 比如下面示例:我这里只有页面和按钮有name(同一个大类的页面,按钮的name一样)

 字符串初始化String[] a=new String[]{};

其他:

按装的第三方软件访问直接用ip+该软件的端口

通用mapper的插入操作自动是返回id的

opmRoleMapper.insert(role);

OpmRolelimit roleLimt1 = new OpmRolelimit();

roleLimt1.setRoleid(role.getId());

//@control层调用@service中的方法时不能传入request参数,否则调用不到(ServletReques也不行)

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

类似角色权限这样第三方的维护应是先根据角色Id删除,然后根据角色id增加

示例:

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>所属市场:</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("你输入的会员编号不存在!");

        }

       

        },

        error:function(data){

        alert("数据加载异常!");

       

        }

    }); 

}

//全选 选中多选框

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("操作失败!");

}

}

@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;\">&nbsp;&nbsp;&nbsp;"+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;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type=\"checkbox\" value="+p.get("ID")+"  name='"+groupId+"'/>"+p.get("NAME")+"</label>"+"\n");

   JsonArray.add(Json);

}

}else{

//TODO

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= opmRolelimitService.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;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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= opmRolelimitService.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("传入参数为空!");

}

TbCusMark tbCusMark = new TbCusMark();

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

   TbCusMark mark= tbCusMarkMapper.selectOne(tbCusMark);

   if(mark==null){

   throw new Exception("交易市场找不到!");

   }

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("查看");

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("保存角色异常!");

}

return  1;

}

猜你喜欢

转载自yuhuiblog6338999322098842.iteye.com/blog/2311978