gpt4 book ai didi

spring - 在 hibernate 中选择多列的标准查询?

转载 作者:行者123 更新时间:2023-12-04 18:22:24 25 4
gpt4 key购买 nike

如何使用条件查询从表中选择多列。

Select testid,marks from user where id='uid' and name='uname'; 

我只能获得 testid 但除了 testid 我还需要标记 任何人都可以修改以下查询以获取 testid 和标记。
Session ses = sessionFactory.getCurentSession();
Criteria c = ses.createCriteria(user.class);
c.add(Restrictions.eq("id", uid));
c.add(Restrictions.eq("name", uname));
c.setProjection(Pojections.distinct(Projections.property("testid")));

最佳答案

你可以尝试给一个 ProjectionList给您的 Projections.distinct :

Session ses = sessionFactory.getCurentSession();
Criteria c = ses.createCriteria(user.class);
c.add(Restrictions.eq("id", uid));
c.add(Restrictions.eq("name", uname));

ProjectionList pl = Projections.projectionList();
pl.add(Projections.property("testid"));
pl.add(Projections.property("marks"));

c.setProjection(Projections.distinct(pl));

关于spring - 在 hibernate 中选择多列的标准查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22066300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com