1 回答
TA贡献1828条经验 获得超3个赞
使用自定义本机查询:
@Query(value = "SELECT id, label
FROM TABLE10
WHERE label like %?1%", native = true)
List<User> findByLabel(String a);
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#_using_advanced_like_expressions
如果您需要可变数量的参数,则必须编写自己的查询:
@PersistenceContext
EntityManager entityManager;
@Override
public List<YourClass> findByLabelLike(List<String> labels) {
String q = "SELECT id, label FROM TABLE10";
for (String l : labels) {
// Add where and ORs
}
Query query = entityManager.createNativeQuery(q, YourClass.class);
int i = 0;
for (String label : labels) {
query.setParameter(++i, "%"+label+"%");
}
return query.getResultList();
}
添加回答
举报