| (String arg0, Object arg1) 外,还有重载方法:
people=(People)sqlMap.queryForObject("getPeople",people);
替换成
sqlMap.queryForObject("getPeople", people, people);
第一个”people”是传入参数,第二个”people”是返回的结果。要表达的意思一样,只不过换了种表现形式。
下面我会讲到如何以集合类持有多个 People 对象实例。
在车辆管理应用中,需要把人员一一列出,选中某个再显示详细内容。类似于这样的需求,iBATIS SQL Maps 引入 sqlMap.queryForList(String arg0, Object arg1) 来满足。
还记得我们的映射文件怎么写的?对了,传入主键值再查询!
但是,新需求不要任何条件,直接列出人员啊!难道还要再添加新的 Mapped Statement 来满足?动态 Mapped Statement 能满足在不改变映射文件的前提下提供有参数和无差数查询:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD SQL Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd">
<sqlMap> <resultMap id="get-autoInfo-result" class="bo.AutoInfo"> <result property="id" column="auto_id"/> <result property="licensePlate" column="license_plate"/> </resultMap>
<resultMap id="get-people-result" class="bo.People"> <result property="id" column="owner_id"/> <result property="name" column="name"/> <result property="address" column="address"/> <result property="autoInfoList" column="owner_id" select="getAutoInfo"/> </resultMap>
<select id="getPeople" resultMap="get-people-result" parameterClass="bo.People"> <![CDATA[ select * from people ]]> <dynamic prepend="where"> <isNotNull property="id"> <![CDATA[ owner_id=#id# ]]> </isNotNull> </dynamic> </select>
<select id="getAutoInfo" resultMap="get-autoInfo-result" parameterClass="int" resultClass="bo.AutoInfo"> <![CDATA[ select * from auto_info where owner_no=#id# ]]> </select> </sqlMap>
上一页 [1] [2] [3] [4] [5] 下一页 |