如何忽略 Spring JPA findBy 存储库中的重音符号?

How to ignore accents in Spring JPA findBy repository?

假设我们有这个存储库:

public interface DeviceTypeRepository extends CrudRepository<DeviceType, Integer>, JpaSpecificationExecutor<DeviceType> {    
    public Iterable<DeviceType> findByNameContaining(String name);    
}

当用户在搜索过滤器中输入错误的重音时,如何通过忽略来获得相同的结果?

示例:João | Joao | JOÃOMarcio | Márcio

Spring 的内置功能无法做到这一点。你可以考虑使用Elastic Search to do that, there is an article on this subject You Have an Accent.

另一种方法是不在数据库中存储重音字母并在执行 SQL 请求之前执行映射,或者使用自定义 SQL 函数在数据库端执行映射 - 但这是一个过于繁琐和脆弱的解决方案。