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);

 

posted @ 2021-02-08 15:47  MrLuve  阅读(744)  评论(0编辑  收藏  举报