Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rest api via spring

I have to get all data from MySQL in a table using condition select query where fields is isdeleted=0, location=1. How could I implement this in repository and 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);
}
like image 830
bkumar Avatar asked Jul 17 '26 15:07

bkumar


1 Answers

You need to add another condition as well, for location, e.g.:

public List<FoodcaseEntity> findByIsdeletedAndLocation(boolean deleted, int location);

And call it with false and 1 as arguments, e.g.:

List<FoodcaseEntity> foodCaseList = foodcourtRepository.findByIsdeletedAndLocation(false, 1);

This should give you the required result.

Updte

If you want to fetch the data for multiple locations then you need to write a method that supports IN, e.g.:

public List<FoodcaseEntity> findByIsdeletedAndLocationIn(boolean deleted, List<Integer> location);

And then call it like this:

List<FoodcaseEntity> foodCaseList = foodcourtRepository.findByIsdeletedAndLocation(false, Arrays.asList(2,3,4,5));
like image 62
Darshan Mehta Avatar answered Jul 20 '26 04:07

Darshan Mehta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!