BookAndBookTypeMapper.xml
<insert id="insertBookAndBookTypeBatch" useGeneratedKeys="true" parameterType="java.util.List">
INSERT INTO wor_book_booktype (wor_book_booktype.BookId,wor_book_booktype.BookTypeId)
VALUES
<foreach collection="list" item="BookAndBookTypeEntity" index="index" separator=",">
(#{BookAndBookTypeEntity.bookId},#{BookAndBookTypeEntity.bookTypeId})
</foreach>
</insert>
BookAndBookTypeServiceImpl
public String saveOrUpdateBookType(List<BookAndBookTypeEntity> bookAndBookTypeEntityList) {
String result = "";
try
{
if (this.bookAndBookTypeMapper.findBookTypeByBookId(bookAndBookTypeEntityList.get(0).getBookId()).size() == 0)
{
this.bookAndBookTypeMapper.insertBookAndBookTypeBatch(bookAndBookTypeEntityList);
} else
{
this.bookAndBookTypeMapper.deleteBookAndBookType(bookAndBookTypeEntityList.get(0).getBookId());
this.bookAndBookTypeMapper.insertBookAndBookTypeBatch(bookAndBookTypeEntityList);
}
} catch (Exception e)
{
e.printStackTrace();
return null;
}
return result;
}