Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search by multiple columns?

I am using spring-boot and hibernate. I have the following table:

firstName |  lastName | department(FK) | city

So far, I was successful in finding records by department (FK) with the following in my repository:

List<User> findByDepartmentId(@Param(value = "department") Long department);

Now, I would like to find not only by department, but also by city (which is a string value). How can I do that?

like image 894
uksz Avatar asked Oct 20 '25 11:10

uksz


1 Answers

You can use And in your method name (assuming you are using spring-data-jpa and city is the name of the field in your model),

List<User> findByDepartmentIdAndCity(Long id, String city);
like image 69
techtabu Avatar answered Oct 22 '25 02:10

techtabu



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!