根据父级ID生成一个数据库不重复的新ID,(补漏,开头删除,中间删除,的ID都可以按顺序补上)

本文介绍了一个用于生成系统模块代码的工具类方法。该方法通过查询数据库获取现有模块代码,并基于这些代码生成新的模块代码。文章重点讲解了如何处理连续编号的情况,确保新生成的代码在编号上与现有代码保持一致。

工具类:

	public String getNewModCode(String parentCode,String behindNum) {
		String newCode = "";
		int x = 0;
		List<String> codeList = sysModuleMapper.getAllModCode(parentCode);
		if(codeList.size()>0){
			x = Integer.valueOf(codeList.get(codeList.size()-1))-Integer.valueOf(codeList.get(0))+1;
			if(codeList.get(0).equals(behindNum)){
				if(codeList.size()<x){
					for(int i=0;i<codeList.size();i++){
						if(Integer.valueOf(codeList.get(i))+1==Integer.valueOf(codeList.get(i+1))){
							continue;
						}else{
							behindNum = Integer.valueOf(Integer.valueOf(codeList.get(i))+1).toString();
							break;
						}
					}
				}else{
					behindNum = Integer.valueOf(Integer.valueOf(codeList.get(codeList.size()-1))+1).toString();
				}
			}
		}
		if(parentCode.length()>1){
			newCode = parentCode + behindNum;
		}else{
			newCode = behindNum;
		}
		return newCode;
	}

SQL:

  	select s.mod_code from sys_module s where s.parent_code=#{parentCode} order by s.mod_code asc
使用于小数据量的菜单,机构数据添加,注意:999+1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值