java - Spring Data Repositiories - add specific parameters to every query -
i have few repositories extend org.springframework.data.mongodb.repository.mongorepository
. have added methods searching entities different parameters, however, in search, want search entities have active
field set true
(have opted marking active=false
in place of deleting). example, 2 sample repositories this:
interface xxrepository extends mongorepository<xx, string> { optional<xx> findonebynameignorecaseandactivetrue(string name) page<xx> findbyactivetrue(pageable pageable) xx findonebyidandactivetrue(string id) } interface yyrepository extends mongorepository<yy, string> { optional<yy> findonebyemailandactivetrue(string email) }
is there way allow me not add byactivetrue
\ andactivetrue
each , every method , set somewhere in 1 place queries?
please try this. no need provide implementation. change 'active' , 'email' db column name.
interface yyrepository extends mongorepository<yy, string> { @query(value = "{ 'active' : { '$eq': true }, 'email' : ?0 }") optional<yy> findonebyemailandactivetrue(@param("email") string email) }
Comments
Post a Comment