使用MyBatisPlus查询数据库,并进行更新

431 阅读1分钟
  1. 获取Entity并进行更新

     EhrIndexInfoChangeRecord ehrIndexInfoChangeRecord = baseMapper.selectOne(
             new LambdaQueryWrapper<EhrIndexInfoChangeRecord>().
                     eq(EhrIndexInfoChangeRecord::getArchivesId, archieveId).
                     eq(EhrIndexInfoChangeRecord::getIndexCode, indexCode).
                     orderByDesc(EhrIndexInfoChangeRecord::getIndexTime).last("limit 1"));
     ehrIndexInfoChangeRecord.setIndexVal(value);
    
     baseMapper.updateById(ehrIndexInfoChangeRecord);
     
    
  2. 如果是这样则会更新所有符合条件的查询,感觉很危险

     EhrIndexInfoChangeRecord ehrIndexInfoChangeRecord = new EhrIndexInfoChangeRecord();
     ehrIndexInfoChangeRecord.setIndexVal(value);
    
     baseMapper.update(ehrIndexInfoChangeRecord, new LambdaQueryWrapper<EhrIndexInfoChangeRecord>().eq(
             EhrIndexInfoChangeRecord::getArchivesId, archieveId).eq(EhrIndexInfoChangeRecord::getIndexCode, indexCode));