java - Rest api via spring -
i have data mysql
in table using condition select
query fields isdeleted=0, location=1. how implement in repository , access manager.
public interface foodcourtrepository extends jparepository<foodcourtentity, long> { list<foodcaseentity> findbyisdeleted(boolean isdeleted); }
in access manager
public list<foodcasedo> getallfoodcourt() { list<foodcaseentity> foodcaselist = foodcourtrepository.findbyisdeleted(false); }
jpa provides @query write custom query. can define interface called foodcourtrepositorycustom , write custom query below:
public interface foodcourtrepositorycustom { @query("select fe foodcaseentity fe fe.isdeleted=?1 , fe.location=?2 ") list<foodcaseentity> findbyisdeletedandlocation(boolean isdeleted, integer location); }
then extends interface in repository inteface below:
public interface foodcourtrepository extends jparepository<foodcourtentity, long>, foodcourtrepositorycustom{ list<foodcaseentity> findbyisdeleted(boolean isdeleted); }
now method available in access manager.
public list<foodcasedo> getallfoodcourt() { list<foodcaseentity> foodcaselist = foodcourtrepository.findbyisdeleted(false); list<foodcaseentity> foodcaselist = foodcourtrepository.findbyisdeletedandlocation(false, 1); }
Comments
Post a Comment