xml代码如下:
<select id="updateQuestionHistoryAnswer">
update et_user_question_history
set error_book =
<foreach collection="updateAll" item="item" index="index" separator=" " open="case question_id" close="end">
when #{item.questionId} then #{item.errorBook}
</foreach>
, is_right =
<foreach collection="updateAll" item="item" index="index" separator=" " open="case question_id" close="end">
when #{item.questionId} then #{item.isRight}
</foreach>
where
user_id = #{userId } and question_id in
<foreach item="item" index="index" collection="updateAll" open="(" close=")" separator=",">
#{item.questionId}
</foreach>
</select>
参数配置如下:
mapper代码
void updateQuestionHistoryAnswer(@Param("updateAll")List<QuestionHistoryAnswer> updateAll, @Param("userId")Integer userId );
实体类代码
@Data
public class QuestionHistoryAnswer {
private int questionId;
private boolean isRight;
private int userId;
private String createTime;
private String updateTime;
private boolean errorBook;
}