728x90
<select id="getGoods" parameterType="java.util.list" resultMap="map">
  SELECT *
  FROM GOODS
  WHERE 
  GOODS_ID IN(
   <foreach collection="list" item="item" separator=",">
   	#{item.goodsId}
   </foreach>
  )
  AND GOODS_NAME = #{goodsName}
</select>

위와 같이 마이바티스로 쿼리를 짤 때 parameterType이 list이기 때문에 foreach문의 값들은 받아왔지만, goodsName에 값은 받지 못했다.

 

아래 처럼 변경하면 된다.

<select id="getGoods" parameterType="parameterVo" resultMap="map">
  SELECT *
  FROM GOODS
  WHERE 
  GOODS_ID IN(
   <foreach collection="list" item="item" separator=",">
   	#{item.goodsId}
   </foreach>
  )
  AND GOODS_NAME = #{goodsName}
</select>

[parameterVo]

public class parameterVo {
    private List<Map<String, String>> list = new ArrayList<>();
    private String goodsName;
    
    public List<Map<String, String>> getList() {
    	return list;
    }
    
    public void setList(List<Map<String, String>> list) {
    	this.list = list;
    }
    
    public String getGoodsName() {
    	return goodsName;
    }
    
    public void setGoodsName(String goodsName) {
    	this.goodsName = goodsName;
    }
}
728x90
TOP