判断是否已经存在该数据

/**
 * 修改角色  (可以判断是否已经存在角色代码)
 * @param role
 * @return
 */
@PostMapping("updateByCond")
public String updateByCond(Role role) {
    try {
        Role  roles = roleMapper.selectByPrimaryKey(role.getUuid());  //用id 查询该角色
        String sss=role.getRoleCode();
        String aaa=roles.getRoleCode();
        if ( sss.equals(aaa)){  //如果传回来的编码等于已经拥有的编码则继续修改操作
            role.setUpdateTime(DateUtils.getCurrentDateTime());
            int result = roleMapper.updateByPrimaryKeySelective(role);  //修改
            if (result > 0) {
                return JsonUtil.toJSON(new JKResponse(Constant.CODE_SUCCESS));修改成功
            } else {
                return JsonUtil.toJSON(new JKResponse(Constant.UPDATE_ERR_MSG));//操作失败
            }
        }else {    //如果传回来的编码不等于已经拥有的编码则判断编码是否存在,
            Role rse = roleMapper.selectByCond(role.getRoleCode());
            if (!EmptyUtil.isEmpty(rse)) {  
                return JsonUtil.toJSON(new JKResponse(Constant.CODE_DATA_IS_EXIST));  //判断是否已经拥有值
 如果存在返回611,
            } else {不存在则进行修改
                role.setUpdateTime(DateUtils.getCurrentDateTime());
                int result = roleMapper.updateByPrimaryKeySelective(role);//修改
                if (result > 0) {
                    return JsonUtil.toJSON(new JKResponse(Constant.CODE_SUCCESS)); 修改成功
                } else {
                    return JsonUtil.toJSON(new JKResponse(Constant.UPDATE_ERR_MSG));   //操作失败
                }
            }
        }
    }catch (Exception e){
        e.printStackTrace();
        log.error(ExceptionUtil.detail(e));
        return JsonUtil.toJSON(new JKResponse(Constant.CODE_SYSTEM_ERROR));   //系统异常
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值