I'm trying to make a method in Repository that will be able to give me list of users, but it didn't return a value.
This is my method:
public interface ProductRepository extends JpaRepository<Product, Integer> {
@Query(value = "select * from mmall_product m where m.status =1 and m.name like CONCAT('%',?1,'%') and m.category_id in (?2)", nativeQuery = true)
List<Product> findByNameAndCategoryIds(String productName, String categoryIdLists);
}
This is my categoryIdLists
:
String categoryIdLists = StringUtils.join(categoryIdList, ",");
In my navicatfor mysql, I can get the data.
This is my SQL select:
select * from mmall_product m where m.status =1 and m.name like CONCAT('%','a','%') and m.category_id in ("100001","100002","100003")
This is my return:
26 100002 Apple iPhone 7 Plus (A1661) 128G iPhone 7,.jpeg detailtext 1422 7 1 2019-03-14 19:45:38 2019-03-14 19:45:58
40 100003 afa aa test.jpg test.jpg,11.jpg,2.jpg,3.jpg detailtext 757 100 1 2019-03-14 19:45:38 2019-03-14 19:45:58
42 100003 apple testtest.jpg test.jpg,11.jpg,2.jpg,3.jpg detailtext 463 100 1 2019-03-14 19:45:38 2019-03-14 19:45:58
But in my spring boot, I can't get the return value.
Can anybody help me with this?
For your requirement why you are not going with booleanbuilder instead of @query. For understanding purpose you can go through http://www.querydsl.com/static/querydsl/2.1.0/reference/html/ch03.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.