0

I am using Spring JPA with mongo.I have a requirement to use contains query on one of the fields.If end users(UI/Service) hits the GET Request and looks for information in EMAIL Field,I need to search based on text.Pretty much it is like. https://docs.spring.io/spring-data/jpa/docs/current/reference/html/

This link explains that We can Use Contains to get the Data.

List<ScheduledNotification> findByMobileNumberContaining(String mobileNumber);
    List<ScheduledNotification> findByEmailIdIgnoreCaseContaining(String emailId);

But when I am using this API,I am not able to get the data.So ,has any one done something like using Contains.

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
MrWayne
  • 309
  • 1
  • 9
  • 20
  • … where x.MobileNumber like ?1 (parameter bound wrapped in %) Are you using "%" with your mobile no? – Afridi May 11 '17 at 06:38
  • Afridi I am not using any % with input.My controller just grabs it from Request and sends it to Service method,which in turn gets data from methods mentioned above – MrWayne May 11 '17 at 06:57
  • @NeilStockton I did not get your point – MrWayne May 11 '17 at 06:59
  • public interface ScheduledNotificationRepository extends BaseRepository,ScheduledNotificationRepositoryCustom { ListfindByNotificationMediumSMSAllIgnoreCase(String notificationMediumSMS); ListfindByNotificationMediumEmailAllIgnoreCase(String notificationMediumEmail); List findByMobileNumberContaining(String mobileNumber); List findByEmailIdIgnoreCaseContaining(String emailId); } – MrWayne May 11 '17 at 06:59
  • You are using Spring-MongoDB, not Spring-Data-JPA. Anybody using a technology ought to know what is being used – Neil Stockton May 11 '17 at 07:06
  • According to spring document, your input parameter should be wrapped in between "%". Its been mentioned in spring documentation: "… where x.firstname like ?1 (parameter bound wrapped in %)" – Afridi May 11 '17 at 12:06
  • @Afridi Yes i went through that.But Spring Mongo provides the implementation for Contains data.All I have to do it formulate the method and done.Again as said,error message I was getting did not have anything to do with spring mongo thing. – MrWayne May 11 '17 at 12:30
  • @NeilStockton Ok after reading docs,I got the point you are trying to make – MrWayne May 11 '17 at 12:31

1 Answers1

0

well ,I was not sending content type in header attribute in GET request.So yes it works,alright.There was no issue with method signature.

MrWayne
  • 309
  • 1
  • 9
  • 20