JPetStore 분석 2 - iBatis

Product ID가 빠졌다.

catalog/Product.jsp
13번째 라인에서 item#productId 임.

1. item 을 product 로 변경한다.
<div id="Catalog">

  <h2><bean:write name="product" property="name"/></h2>

  <table>
    <tr><th>Item ID</th>  <th>Product ID</th>  <th>Description</th>  <th>List
      Price</th>  <th> </th></tr>
    <logic:iterate id="item" name="itemList">
      <tr>
        <td>
          <html:link paramId="itemId" paramName="item" paramProperty="itemId" page="/shop/viewItem.shtml">
            <bean:write name="item" property="itemId"/></html:link></td>
        <td><bean:write name="item" property="productId"/></td>
        <td>
          <bean:write name="item" property="attribute1"/>
          <bean:write name="item" property="attribute2"/>
          <bean:write name="item" property="attribute3"/>
          <bean:write name="item" property="attribute4"/>
          <bean:write name="item" property="attribute5"/>
          <bean:write name="product" property="name"/>
        </td>
        <td><bean:write name="item" property="listPrice" format="$#,##0.00"/></td>
        <td><html:link styleClass="Button" paramId="workingItemId" paramName="item" paramProperty="itemId" page="/shop/addItemToCart.shtml">
          Add to Cart</html:link></td>
      </tr>
    </logic:iterate>
    <tr><td>
      <logic:notEqual name="itemList" property="firstPage" value="true">
        <a class="Button" href="switchItemListPage.shtml?pageDirection=previous"><< Prev</a>
      </logic:notEqual>
      <logic:notEqual name="itemList" property="lastPage" value="true">
        <a class="Button" href="switchItemListPage.shtml?pageDirection=next">Next >></a>
      </logic:notEqual>
    </td></tr>
  </table>

</div>

Item.xml
product#productId 에는 들어가는데 item#productId 에는 들어가지 않는다.

2. 쿼리에 productId 를 추가한다.
<select id="getItemListByProduct" resultClass="item" parameterClass="string" cacheModel="itemCache">
	SELECT
		ITEMID,
		LISTPRICE,
		UNITCOST,
		SUPPLIER AS supplierId,
		I.PRODUCTID AS "product.productId",
		/* I.PRODUCTID, */
		NAME AS "product.name",
		DESCN AS "product.description",
		CATEGORY AS "product.categoryId",
		STATUS,
		ATTR1 AS attribute1,
		ATTR2 AS attribute2,
		ATTR3 AS attribute3,
		ATTR4 AS attribute4,
		ATTR5 AS attribute5
	FROM ITEM I, PRODUCT P
	WHERE P.PRODUCTID = I.PRODUCTID
	AND I.PRODUCTID = #value#
</select>

iBatis에서 주석은 -- 대신 /* */ 를 사용할 것.