hibernate查询部分字段转换成实体bean

时间:2024-04-17 15:35:30
//hibernate查询部分字段转换成实体bean

    /**
     * 查询线路信息
     */
    @Override
    public List<Line> getSimpleLineListByTj(Map<String,Object> paramMap){

        Criteria cr=this.getSession().createCriteria(Line.class,"Line");
//        cr.setFetchMode("chuTuanInfo", FetchMode.JOIN);
//        Criteria teamche=cr.createAlias("chuTuanInfo","chuTuanInfo", JoinType.LEFT_OUTER_JOIN);
//        Criteria teamPlanCR=cr.createAlias("teamplan","teamplan", JoinType.LEFT_OUTER_JOIN);
        ProjectionList pList=Projections.projectionList();
//        pList.add(Projections.property("id"));
//        pList.add(Projections.property("linename"));
        pList.add(Projections.alias(Projections.property("id"), "id"));//使用别名才能aliasToBean到Line
        pList.add(Projections.alias(Projections.property("linename"), "linename"));
//        pList.add(Projections.property("teamplan.renshu"));
        cr.setProjection(pList);

//        FaTuanState.getMap();
//        List<String> propertyNameList = new ArrayList();
//        propertyNameList.add("id");
//        propertyNameList.add("linename");
//        List list =  getListWithPartProperty(cr, propertyNameList);

//        Map<String,Object> paramMap = new HashMap<String,Object>();
//        paramMap.put(key, value);

        cr.add(Restrictions.ne("state", FaTuanState.TINGFA));//《》停发和暂停的
        cr.add(Restrictions.ne("state", FaTuanState.ZANTING));

        if(paramMap.get("areaid")!=null && !StringUtils.isBlank(paramMap.get("areaid").toString())){
            cr.add(Restrictions.eq("jingqu.id", Integer.parseInt(paramMap.get("areaid").toString())));
        }

        cr.addOrder(Order.asc("linename"));
        cr.setResultTransformer(Transformers.aliasToBean(Line.class));

        return cr.list();
    }