JPA模糊查询的坑

List<Menu> findByPidsLikeAndStatus(Long pids,BYte status); 
pid = [3]
status = 1
底层SQL
select * from sys_menu where pids like '%[3]%' and status=1;


解决
select * from sys_menu where pids like '%[3]%' escape '[' and status=1 ;
JPA
@Query(value = "select * from sys_menu where pids like concat('%[',:pid,']%')  escape '[' and status=:status" , nativeQuery = true)
List<Menu> findByPidsLikeAndStatus(@Param("pid") String pids, @Param("status") Byte status);
原文地址:https://www.cnblogs.com/mrluve/p/14389143.html