springboot datajpa 简明说明

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即可

原文地址:https://www.cnblogs.com/noigel/p/12072110.html