Externalize mongo json query using spring boot -


i have started using spring data mongodb spring-boot.

i have mongo based json queries added in interface using @query annotation when using spring data repository.

i want know if possible externalize or separate out json query outside codebase can optimized separately ,

also not having mixed code.

thanks suggestions.

this code have added in interface , annotated @query annotation.

@query("{ 'firstname' : ?0 ,'lastname': ?1}") list findbycriteria(string firstname,string lastname);

the above simple example. have complex conditions involving $and , $or operators .

what want achieve externalize above native mongo json query config file , refer in above annotation.

spring data supports similar when using jpa hibernate. not sure if can same using spring data mongodb spring boot.

do (i explaining api)

suppose have entity user

at top there user domain

public class user extends coredomain { private static final long serialversionuid = -4292195532570879677l; @length(min = 2) private string name; @length(min = 2) @uniqueusername(message = "user name registered,please choose different") private string username; @length(min = 6) private string password; } 

user controller

user service (interface)

user serviceimpl(service implementation)

mongo repository(since, have mongodb)

now in usercontroller take queries , param(parameters) , pagerequest

public class usercontroller extends corecontroller {  @autowired private userservice userservice;  /*  * controller getting userdetails on passing userid in  * @param annotation  */ @get @path("{id}") public user getuser(@pathparam("id") string userid) {     user user = new user();     user = userservice.finduserid(userid);      if (user == null)         throw new notfoundexception();     log.info("the userid searched having details :" + user);     return user; }} 

for serviceinterface have :

public interface userservice { // boolean authenticateuser(user user);  user finduserid(string userid);  } 

for serviceimpl :

public class userserviceimpl implements userservice { @setter @autowired private userrepository userrepository;  /*  * method find user on basis of userids passed in  * parameter.  */ @override public user finduserid(string userid) {     user useridresult = userrepository.findone(userid);     log.info("the userdetail is" + useridresult);     return useridresult; } 

in mongorepository user have: default query findbyid(string userid);

hopefully you.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -