gpt4 book ai didi

java - spring CrudRepository 是否支持列表的 deleteBy?

转载 作者:IT老高 更新时间:2023-10-28 13:49:05 30 4
gpt4 key购买 nike

Spring Data CrudRepository 是否提供通过非主键的属性删除条目列表?

public interface MyRepository extends CrudRepository<MyEntity, Long> {
@Modifying
@Transactional
public void deleteByName(List<String> names);
}

最佳答案

是的,这是可能的,documentation解释 In关键字与以下示例。示例进一步表明,列表参数不必是实体主键的类型:

In -> findByAgeIn(Collection<Age> ages)

In and NotIn also take any subclass of Collection as parameter as well as arrays or varargs.

然后这又可以应用于您的删除查询:

In addition to query methods, query derivation for both count and delete queries, is available.

类似:

void deleteByNamesIn(List<String> names);

关于java - spring CrudRepository 是否支持列表的 deleteBy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28063409/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com