Util 情境 2

凌晨3:24






A. 使用 Spring's DaoSupport Or JBoss Hibernate DaoSupport (which executes the Hibernate HQL query) with Hibernate : Criterion , Restrictions

通常取得的是 : List(BOs)
若要在 presentation tier
要用 util(ex : Apache BeanUtils's copyProperties method) 轉成 List(VOs)


B.

    List<Order> orders = new ArrayList<Order>();
    Order order = Order.asc("orderField1");
    orders.add(order);

    List<the_bo1VO> list = the_dao1.findByCriteriaWithOrder(orders, Restrictions.eq("key1", key1));

    if (list.size() > 0) {
        for (theBo1 bo : list) {
            the_bo1VO vo = new the_bo1VO();
         
//1.
The_util1.convertMethod1(vo, bo);

            result.add(vo);
        }
    }

C. in getZZZ2() : for(theBo1 result: results) {}

//用 util(ex : Apache BeanUtils's describe method) 轉成 Map(VO)
    Map theMap1 = new HashMap();
    try {
    theMap1 = org.apache.commons.beanutils.BeanUtils.describe(result);
    } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


D.

Util 情境 2map-key_Set-and-value-List and List(map-key_Set-and-value-List)

/**map-key_Set-and-value-List*/
Map<Long, List<Long>> theMap1 = [ZZZ1]Service.getMap1(riMsg); //{itemId=[]}
List<Long> list1 = new ArrayList<Long>();
Set<Long> set1 = new HashSet<Long>();

for(Long itemId : theMap1.keySet()) {
List<Long> ids = theMap1.get(itemId);
if ( ids.isEmpty() ) {
/**List(map-key_Set-and-value-List)*/
List<Map<String, Object>> dataList = [ZZZ2]Delegate.getZZZ2(); //{itemId=[]}
for(Map<String, Object> map : dataList) {
Long element1 = (Long)map.get("element1");
if (!set1.contains(element1)) {
set1.add(element1);
list1.add(element1);
}
}
} else {
for(Long element1: ids) {
if (!set1.contains(element1)) {
set1.add(element1);
list1.add(element1);
}
}
}
}

  • Share:

You Might Also Like

0 意見