1.目标语句
select * from test where id in(1,2,3);
2.Book.java中定义ArrayList类型
private List<Integer> bookIdList;
public void setBookIdList(List<Integer> bookIdList) {
this.bookIdList = bookIdList;
}
3.在controller中调用
List<Integer>list = new ArrayList<Integer>();
Book Book = new Book();
book.setBookIdList(list);
4.Mapper.xml中定义,注意parameterType的值,以及foreach的用法
<select id="getBookDetail"parameterType="com.ssm.shopping.pojo.Book" resultType="com.ssm.shopping.pojo.Book">
select * from test where id
<foreach collection="list" item="id" open="in("close=")" separator=",">#{id}</foreach>
</select>
这样拼接出来的sql语句就是目标语句