zoukankan      html  css  js  c++  java
  • SSH新学,关于面向对象的看法

    流程:model-->dao-->service-->impService-->action

    如果只是操作单个的一个表,比如user表,则都写到user的流程中

    如果要操作俩个表,+manage,就要用到 关联 了,这个时候操作起来还是对一个表,因为user表里面包含另一个表mange。

    既然是面向对象,那么userModel-->userDAO-->userService-->userImpService-->userAction 等等一切的返回值都是user 或者是List<user>

    但是遇到这样一个问题:

    情况一:

        public List<Xmxx> findXmxxsByGksh(){
            String hql="from Xmxx where DM_ZT_GKSH = 2 ";
            return this.xmxxDAO.findList(hql);
        }

    这个应该没有问题,this.xmxxDAO.findList(hql);返回的是List<Xmxx>

    情况二:

        public List<Xmxx> findXmxxsByZt_sq(String USERNAME){
            String hql="from Xmxx x inner join x.yhxxs y where DM_ZT_TX in (0,1) and y.USERNAME=:USERNAME ";
            List<Xmxx> xmxxList=new ArrayList<Xmxx>();
            Map map=new HashMap();
            map.put("USERNAME", USERNAME);
            List list=this.yhxxDAO.findListOfMap(hql, map);
            if(list!=null){
                Iterator it=list.iterator();
                while(it.hasNext()){
                    Object[] obj=(Object[])it.next();
                    xmxxList.add((Xmxx)obj[0]);
                }
            }
            return xmxxList;
        }

    注意看这里List list=this.yhxxDAO.findListOfMap(hql, map),这样写不会报错。

    如果把yhxxDAO去掉,只写this.findListOfMap(hql,map)也不会报错。

    但是List<Xmxx> list=this.yhxxDAO.findListOfMap(hql, map),就会出错,提示cannot convert from List<Yhxx> to List<Xmxx>。

  • 相关阅读:
    C# 中对COOKIES的操作
    guruguru
    异或序列
    最优贸易
    farm
    Fruit Ninja
    商务旅行
    Generation I
    Heritage of skywalkert
    Bichrome Tree
  • 原文地址:https://www.cnblogs.com/-beauTiFul/p/6105395.html
Copyright © 2011-2022 走看看