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