ContactDaoを次のように定義しました。
public interface ContactDao extends JpaRepository<Contact, Long> {
/**
* Finds all contacts that the given user has entered where the contact's full name matches {@code name}.
* @param userId The current user's LDAP id.
* @param name The name to search for.
* @return A list of contacts matching the specified criteria.
*/
@Query(" select c from Form as f" +
" inner join f.contacts as c" +
" where f.requestorUserId = :userId" +
" and lower(c.fullName) like lower(:name)" +
" order by lower(c.fullName)")
List<Contact> findUserContactsByUserIdAndName(@Param("userId") String userId, @Param("name") String name);
}
上記は完全に機能しており、生成されたSQLは私が自分で書いたものです。:name
問題は、パラメータに周囲のワイルドカードを追加したいということです。これを行うための良い方法はありますか?Spring Data JPAリファレンスドキュメントを確認しましたが、wildardsとについては何も見つかりません@query
。
次のハックは機能しますが、少し醜いです。
and lower(c.fullName) like '%' || lower(:name) || '%'
誰かがより良い解決策を持っていますか?
ありがとう、ムエル。