こんにちは、MyBatisを使ってsqlを実行しDBからデータを取得したいのですが
Mapper.xml
1<mapper namespace="shopMapper"> 2 <update id="stockDecrement"> 3 update STOCK set stock = stock - #{num} where product_id = #{id}; 4 </update> 5 <select id="getProduct" resultType="ProductEntity"> 6 select name, stock from PRODUCT_MASTER as p join STOCK as s on p.#{productId} = s.#{productId} where p.shop_id = #{shopId} ; 7 </select> 8</mapper>
上のようにmapperを定義し、sqlsessionを取得するためfactoryを作成しました。
ここでDAOクラスの中で
public List<ProductEntity> getProduct(int productId, int shopId){ SqlSession session = null; try{ session=MyBatisSessionFactory.getSession( ).getSessionFactory().openSession(false); return session.selectList("shopMapper.getProduct", productId, shopId); }finally{ session.close(); } }
としてデータを取得しようとするとselectListの部分でeclipseに怒られてしまいます。
内容としては
型 SqlSession のメソッド selectList(String, Object, RowBounds) は
引数 (String, int, int) に適用できませんとでます
この場合どのようにすればMapperに定義したSQLに変数を渡すことができるでしょうか?
よろしくおねがいします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/31 07:00
2017/12/31 09:08
2017/12/31 09:15