मैं अपने ContactDao परिभाषित किया है इस प्रकार है:क्या @Query पैरामीटर में वाइल्डकार्ड जोड़ना संभव है?
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);
}
ऊपर पूरी तरह से काम कर रहा है, और उत्पन्न एसक्यूएल मैं अपने आप को क्या लिखना चाहते हैं। समस्या यह है कि मैं आसपास के जंगली-कार्ड :name
पैरामीटर में जोड़ना चाहता हूं। क्या ऐसा करने का कोई अच्छा तरीका है? मैंने स्प्रिंग डेटा जेपीए संदर्भ दस्तावेज़ पर एक नज़र डाली है और मुझे वाइल्डर्ड्स और @query
के बारे में कुछ भी नहीं मिला है।
निम्नलिखित हैक काम करता है, लेकिन थोड़ा बदसूरत है:
and lower(c.fullName) like '%' || lower(:name) || '%'
है किसी को भी एक बेहतर समाधान है?
धन्यवाद, ईंधन।
किसी भी _Spring डेटा_ लेखकों के मामले में थोड़ा सा विषय-पक्ष साइड-नोट .. :) शायद इस तरह की सुविधा (वाइल्डकार्ड से जुड़ी) को '@ परम' में जोड़ा जा सकता है; उदाहरण के लिए '@ पैरा (मूल्य =" नाम ", वाइल्डकार्डस्टैजी = वाइल्डकार्डस्ट्रेटी.बीओटीएच)'। बेशक, मैंने यह बहुत कम विचार दिया है, इसलिए इसके खिलाफ शायद मजबूत तर्क हैं! – Muel
क्या वाकई यह एक हैक है? –