接口 CommonDao(公共Dao提供根据指定的PO类、列名称、列值和排序字段来获取po对象方法 findFirstByProperty)

java.lang.Object findFirstByProperty(java.lang.Class cls,
                                     java.lang.String propertyName,
                                     java.lang.String propertyValue,
                                     java.lang.String[] orders)

根据指定的PO类、列名称、列值和排序字段来获取po对象.

该方法只返回一条po对象,即使查询出多个,也返回第一条数据

参数:

cls - PO类

propertyName - 列名

propertyValue - 列值

orders - 排序字段,(new String[]{"sortcode"})

返回:

返回po对象

public Object findFirstByProperty(final Class cls,final  String propertyName,final     String propertyValue,final  String[] orders) {
        List ls = findAllByPropertyInArray(cls, propertyName,new Object[]{propertyValue}, orders);
        if(ls!=null && ls.size()>0){
            return ls.get(0);
        }else{
            return null;
        }
    }

public List findAllByPropertyInArray(final Class cls, final String propertyName,final    Object[] propertyValues,final String[] orders) {
        Map<String,Object[]> map = new HashMap<String,Object[]>();
        if(StringUtils.isNotBlank(propertyName)){
            map.put(propertyName, propertyValues);
        }
        return  findAllByPropertys(cls, map, orders, -1, -1);
    }

猜你喜欢

转载自blog.csdn.net/gongjian0321/article/details/89067285
今日推荐