简体   繁体   English

是否可以用int代替List

[英]IS it POSSIBLE TO int instead of List

I want number of records of a particular table, but my query is returning list i want integer as result my code is here 我想要特定表的记录数,但是我的查询正在返回列表,我想要整数作为结果,我的代码在这里

public int<BorrowerEvaluationDTO> findEvaluations(final String sector, final String investorId) {
    return (List<BorrowerEvaluationDTO>) getHibernateTemplate().executeFind(
            new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException,
                        SQLException {
                    Criteria criteria = session.createCriteria(BorrowerEvaluationDTO.class);
                    criteria.add(Expression.eq("hasEvaluation", true));
                    //      criteria.setProjection(Projections.distinct(Projections.property("stateOrProvinceId")));
                    //      criteria.setProjection(Projections.distinct(Projections.property("partnerOrganisation")));
                    if (sector != null && !sector.trim().equals("")) {
                        criteria.add(Expression.eq("sector", sector));
                    }
                    criteria.setProjection(Projections.rowCount());
                    if (investorId != null && !investorId.trim().equals("")) {


                    }




                    return criteria.list().size();
                }

                ;
            });
}

You have declared the wrong return type. 您声明了错误的返回类型。
Just try to change your function to return an int and the return value to criteria.list().size(); 只需尝试更改您的函数以将int和返回值返回至criteria.list().size();

EDIT 编辑

You can write your own function. 您可以编写自己的函数。 Just make criteria global. 只是将criteria全局。 For Example: 例如:

public int getListSize()
{
    return criteria.list().size();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM