码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-12-29 12:37:35      阅读:949      评论:0      收藏:0      [点我收藏+]

标签:

//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();
    }

 

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

标签:

原文地址:http://www.cnblogs.com/hui-blog/p/5085137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!