请教关于Hibernate的问题
public User getUserByName(String username) {
Session session = getSession();
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.like("username", username));User user = null;
if (!criteria.list().isEmpty())
user = (User) criteria.list().get(0);
session.close();
return user;
}
我想问下一下如果那里的like换成eq有什么不一样,我查文档了,不过还是不太理解,非常感谢!
[解决办法]
当然不一样啊,一个是像,一个是等。
public static SimpleExpression like(String propertyName,
Object value)Apply a "like" constraint to the named property
Parameters:
propertyName -
value -
Returns:
Criterion
-------------------------------------------
eq
public static SimpleExpression eq(String propertyName,
Object value)Apply an "equal" constraint to the named property
Parameters:
propertyName -
value -
Returns:
Criterion
[解决办法]
我晕……