下面是我如何从数据库中获取我的用户 bean。
session.createCriteria(User.class).list();
从数据库返回所有用户记录。有趣的是,我不想从数据库中获取密码字段。只想在检索时排除该字段。
我的选择
1) 在其他领域使用投影。这需要更多代码才能添加到投影列表中。所以放弃了那个想法。
2) 使用 Sql 我需要手动编写查询,这会破坏 Hibernate 的主题。
是否有可能排除 Bean 的列值?
最佳答案
你可以试试:
Example example = Example.create(cat)
.excludeZeroes() //exclude zero valued properties
.excludeProperty("color") //exclude the property named "color"
.ignoreCase() //perform case insensitive string comparisons
.enableLike(); //use like for string comparisons
List results = session.createCriteria(Cat.class)
.add(example)
.list();
引用:-
关于java - 在 Hibernate 条件结果中排除 bean 的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25970226/