spring-data-jpa-guide icon indicating copy to clipboard operation
spring-data-jpa-guide copied to clipboard

JPA如何讲in查询返回的结果按in传入照顺序返回?

Open shihp opened this issue 2 years ago • 1 comments

没找到非native的xiefa

直接用mysql native语法可以做到 SELECT * from models where id in (26612,26611,26610) order by field(id,26612,26611,26610);

@Query(value = "select * from dress where id in (?1) and source = ?2 order by field(id,?3)", nativeQuery = true) List<Dress> queryDid(List<Long> dids, Integer code, List<Long> dids2);

shihp avatar Dec 09 '22 08:12 shihp

JPQL比较难,看你的顺序不是 order by Desc ?

zhangzhenhuajack avatar Dec 12 '22 07:12 zhangzhenhuajack