Spring数据JPA existByField区分大小写,如何使其忽略大小写

问题描述 投票:1回答:1

ClientsRepository类

public interface ClientsRepository extends JpaRepository<ClientsEntity, Long> {

    boolean existsByClientId(String clientId);

}

ClientsEntity类

@Getter
@Setter
@NoArgsConstructor
@Entity
@Table(name = "clients")
public class ClientsEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private String clientId;

}

客户表| id | client_id | |---------------------|------------------| | 1 | ABC | |---------------------|------------------|

在调用existingByClientId(“ abc”)时返回true,如何强制检查大小写?

预期结果:existsByClientId("abc") --> falseexistsByClientId("ABC") --> true

Java版本8Spring Boot版本2.1.2.RELEASEmysql-connector-java版本5.1.46

java spring spring-boot jpa spring-data-jpa
1个回答
0
投票

Query Creation,您可以使用IgnoreCase

existsByClientIdIgnoreCase("abc")
© www.soinside.com 2019 - 2024. All rights reserved.