简体   繁体   中英

How to ignore accents in Spring JPA findBy repository?

Lets say we have this repository:

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

How to obtain the same results by ignoring when user mistypes accents ni search filter?

Examples: João | Joao | JOÃO João | Joao | JOÃO João | Joao | JOÃO , Marcio | Márcio Marcio | Márcio etc.

There is no way to do that within Spring's built-in capabilities. You can consider using Elastic Search to do that, there is an article on this subject You Have an Accent .

Another way is to not store accent letters in DB and perform mapping before executing SQL request or perform mapping on DB side using custom SQL function - but it's a too cumbersome and fragile solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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