Hibernate标准限制.eq是病例不敏感的



我正在使用标准检查JSON的用户名和密码是否正确。我确定输入用户名和密码在正确的情况下,但即使字母案例不同,它也总是会返回我的对象。

public Admin getLoggedAdminInformation(String username, String password){
   Criteria criteria = criteria()
            .add(Restrictions.eq("userName", username))
            .add(Restrictions.eq("password", password));
   return (Admin) criteria.uniqueResult();
}

Restrictions.eq只需返回带有 ignoreCaseSimpleExpression对象是错误的。因此,它将创建具有与您提供的完全相同值的SQL。

public static SimpleExpression eq(String propertyName, Object value) {
        return new SimpleExpression(propertyName, value, "=");
    }

因此,这种情况不敏感的比较是数据库的行为。这取决于数据库服务器,表或列配置。

ex:在MS SQL Server中,这是基于数据库的整理,可以在表级别或列级中载入。样本整理名称是Latin1_general_ci_as,此处CI = CASE不敏感,AS = ACCENT敏感。

最新更新