我一直在网上搜索这个问题,我发现所有关于如何创建一个不区分大小写的查询。我知道默认情况下查询是区分大小写的,但是我的存储库仍然会返回结果,即使大写字母和小写字母与数据库中的字母不同。
AccountRepository.java
@Repository
public interface AccountRepository extends JpaRepository<Account, Integer>
{
Account findByPassword(String password);
Account findByUsernameAndPassword(String username, String password);
}AccountService.java
public void login(Account entity)
{
System.out.println(repository.findByUsernameAndPassword(
entity.getUsername(), entity.getPassword());
System.out.println(repository.findByPassword(
entity.getPassword());
}上面的服务都会打印出正确的结果,尽管在错误的情况下输入了密码(比如mypassword和MyPassword)。有什么想法吗?
发布于 2017-09-07 13:45:53
在…的例子中
findByPassword它把它分割成关键词,然后用实例说明:
find by password其中密码是一个属性
在…的例子中
findByUsernameAndPassword这成了
find by username and password其中用户名和密码是属性。
请参阅https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods
您的数据库可能有不区分大小写的开关集。MySql允许这样做,但甲骨文不允许。
https://stackoverflow.com/questions/46097763
复制相似问题