论坛首页 入门技术论坛

queryForMap的问题

浏览 8935 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-11-26  
queryForMap的问题
queryForMap(statementName, parameterObject, keyProperty);
参数的含义
   发表时间:2008-11-26   最后修改:2008-11-26
  /**
   * Executes a mapped SQL SELECT statement that returns data to populate
   * a number of result objects that will be keyed into a Map.
   * <p/>
   * The parameter object is generally used to supply the input
   * data for the WHERE clause parameter(s) of the SELECT statement.
   *
   * @param id              The name of the statement to execute.
   * @param parameterObject The parameter object (e.g. JavaBean, Map, XML etc.).
   * @param keyProp         The property to be used as the key in the Map.
   * @return A Map keyed by keyProp with values being the result object instance.
   */


默认实现:
public Map queryForMap(SessionScope session, String id, Object paramObject, String keyProp, String valueProp) throws SQLException {
    Map map = new HashMap();

    List list = queryForList(session, id, paramObject);

    for (int i = 0, n = list.size(); i < n; i++) {
      Object object = list.get(i);
      Object key = PROBE.getObject(object, keyProp);
      Object value = null;
      if (valueProp == null) {
        value = object;
      } else {
        value = PROBE.getObject(object, valueProp);
      }
      map.put(key, value);
    }

    return map;
  }
1 请登录后投票
   发表时间:2008-11-26  
<select id="selectList" resultMap="selectHead"
parameterClass="java.lang.String">
select bill_id,bill_origin,bill_time,total,linkman_name,b.agentid,b.member_id ,paymentModeCodeName,a.agentName
from etp_bills b,etp_linkmanbase l,paymentmode p ,agent a where b.linkman_id = l.linkman_id
and b.payment_typeid = p.paymentModeId and b.agentid = a.agentId and bill_id = #bill_id#
</select>
<resultMap id="selectHead" class="com.bean.agent.AgentBean">
<result property="agentId" column="agentId" />
<result property="agentName" column="agentName" />
</resultMap>
<resultMap id="selectHead" class="com.bean.agent.AgentBean">
<result property="linkman_id" column="linkman_id" />
<result property="linkman_name" column="linkman_name" />
</resultMap>
<resultMap id="selectHead" class="com.bean.agent.AgentBean">
<result property="paymentModeCodeName" column="paymentModeCodeName" />
<result property="paymentModeId" column="paymentModeId" />
</resultMap>
比如我的配置文件是这样的
那 map = dao.queryForMap("selectList", billid, "selectHead");这样对吗
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics