简体   繁体   English

如何从 spring boot -REST API /JPA 中删除?

[英]How to delete from spring boot -REST API /JPA?

I want to delete an item from table.我想从表中删除一个项目。

Present valuee like below:现值如下:

CatId         CatName
1             Name1
1             Name2
1             Name3
1             ABC1 
1             ABC2
2             Name4
3             Name5

Both columns are in same table.两列都在同一个表中。 How to delete NAME1,NAME2, NAME3 from CatName column where CatId is 1 using spring boot jpa?如何使用spring boot jpa从CatId为1的CatName列中删除NAME1、NAME2、NAME3?

You need to create Cat Repository and put this method as follows..您需要创建 Cat Repository 并将此方法如下..

@Repository
public interface CatRepository extends JpaRepository<Cat, Integer > {

   List<Cat> findAllByCatIdAndCatNameLike(Integer catId, String catName);

}

In your service class create method and put in to following code lines.在您的服务类中创建方法并放入以下代码行。

List<Cat> catList = catRepository.findAllByCatIdAndCatNameLike(1, Name);
catRepository.deleteAll(catList);

 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM