findById返回Optional的使用

查询

    public Object lookupDevice(Integer id) {
        return deviceJpa.findById(id).orElse(null);
    }

更新

    public Object updateDevice(Integer id) {
        Optional<Device> optionalDevice = deviceJpa.findById(id);
        if (optionalDevice.isPresent()) {
            Device device=optionalDevice.get();
            device.setSerial("HEHHEHEEH");
            return deviceJpa.save(device);
        }
        return null;
    }

 

保存上传的文件到数据库

Entity类成员定义

    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(columnDefinition = "longblob")
    private byte[] someData;

然后在MultipartFile fileField

fileField getBytes即可

相关文章:

  • 2021-07-07
  • 2022-01-09
  • 2021-09-05
  • 2022-01-05
  • 2021-11-20
  • 2021-04-22
  • 2021-10-29
  • 2021-07-20
猜你喜欢
  • 2021-10-30
  • 2022-01-14
  • 2022-01-23
  • 2021-08-20
  • 2021-12-18
  • 2021-12-18
  • 2021-07-01
相关资源
相似解决方案