用repository.deleteById()删除时候报错

报错org.springframework.dao.EmptyResultDataAccessException: No class…
解决办法:
在repository.deleteById()前加一句判断:

if(repository.existsById())

冲!

package cn.njucm.dosepre.repository; import cn.njucm.dosepre.entity.Patient; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.List; import java.util.Optional; @Repository public interface PatientRepository extends JpaRepository<Patient, Long> { Optional findByPatientId(String patientId); List findByPatientNameContaining(String patientName); boolean existsByPatientId(String patientId); @Query(“SELECT p FROM Patient p WHERE p.age BETWEEN :minAge AND :maxAge”) List findByAgeRange(@Param(“minAge”) Integer minAge, @Param(“maxAge”) Integer maxAge); } package cn.njucm.dosepre.entity; import lombok.Data; import javax.persistence.*; import java.math.BigDecimal; import java.util.Date; @Data @Entity @Table(name = “patient”) public class Patient { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(name = "patient_id", nullable = false, unique = true, length = 50) private String patientId; @Column(name = "patient_name", nullable = false, length = 100) private String patientName; @Enumerated(EnumType.STRING) private Gender gender; private Integer age; @Column(precision = 5, scale = 2) private BigDecimal weight; @Column(precision = 5, scale = 2) private BigDecimal height; @Column(precision = 5, scale = 2) private BigDecimal creatinine; @Column(name = "liver_function", length = 20) private String liverFunction; @Column(name = "kidney_function", length = 20) private String kidneyFunction; @Column(name = "create_time") @Temporal(TemporalType.TIMESTAMP) private Date createTime; @Column(name = "update_time") @Temporal(TemporalType.TIMESTAMP) private Date updateTime; public enum Gender { MALE, FEMALE } @PrePersist protected void onCreate() { createTime = new Date(); updateTime = new Date(); } @PreUpdate protected void onUpdate() { updateTime = new Date(); } }
最新发布
11-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值