首页 > 解决方案 > JPA中包含和喜欢有什么区别?

问题描述

如果我想使用模糊选择,当我使用喜欢时似乎错误,我必须使用包含。那么 JPA 中的 contains 和 like 有什么不同呢?

标签: spring-bootjpaspring-data-jpaspring-datajpa-2.0

解决方案


两者都非常相似,根据有关容器参数的 Spring 文档,它们被绑定在 % 中,而在 Like not 中。因此,如果您想要相同的结果,请尝试使用 Like 将 % 添加到查询的参数中

https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.details


推荐阅读