1 List<Instrument> insts = instService.search(search);
 2 
 3     if (insts.size() == 1) {
 4           Instrument inst = insts.get(0);
 5 
 6     if (inst != null) {
 7 
 8       inst.setBarCode("imported");
 9 
10       instService.save(inst)
11 
12   }
13 }

第10行加不加都会保存上。所有以下的方式应该避免

 1 List<Instrument> insts = instService.search(search);
 2 
 3     if (insts.size() == 1) {
 4           Instrument inst = insts.get(0);
 5 
 6     if (inst != null) {
 7 
 8       inst.setBarCode("imported");
 9 
10         if(cond) {
11           instService.save(inst)
12         }
13 
14   }
15 }

应该改为这样

 1 List<Instrument> insts = instService.search(search);
 2 
 3     if (insts.size() == 1) {
 4           Instrument inst = insts.get(0);
 5 
 6         
 7           if (inst != null) {
 8         if(cond) {
 9               inst.setBarCode("imported");
10 
11               instService.save(inst)
12         }
13     }
14 }

 

相关文章:

  • 2022-12-23
  • 2021-08-15
  • 2022-01-01
  • 2021-11-02
  • 2021-12-28
  • 2021-06-25
  • 2021-12-29
  • 2021-11-20
猜你喜欢
  • 2021-11-23
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-02-03
相关资源
相似解决方案