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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM