mybatis 批量插入到数据库中 纯注解~

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/KSMaster/article/details/81672806
   /** @description 插入多个日程
     * @author wangkaishuang
     * @date 2018/8/14
     * @param [events]
     * @return java.util.List<com.wps.calendar.core.model.Event>
     */
    @Insert({
            "<script>",
            "insert into event(id,summary,description,location,start_time,end_time,time_zone,event_type,action_type,notice_time,",
            "reminders,recurrence,notice_status,event_priority,event_status,share_status,creator_id,calendar_id,share_event_id,origin_event_id,",
            "finish_message,delete_reason,etag,expire_date,event_shared_date,split_id,create_time,update_time) ",
            "values",
            "<foreach item ='event' collection = 'list' separator = ','>",
            "(#{event.id},#{event.summary},#{event.description},#{event.location},#{event.startTime},#{event.endTime},#{event.timeZone},#{event.eventType},#{event.actionType},#{event.noticeTime},#{event.reminders},",
            "#{event.recurrence},#{event.noticeStatus},#{event.eventPriority},#{event.eventStatus},#{event.shareStatus},#{event.creatorId},#{event.calendarId},#{event.shareEventId},#{event.originEventId},#{event.finishMessage},#{event.deleteReason},",
            "#{event.etag},#{event.expireDate},#{event.eventSharedDate},#{event.splitId},#{event.createTime},#{event.updateTime})",
            "</foreach>",
            "</script>"
    })
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int saveAll(@Param("list") List<Event> list);
  1. item :list存储的实体类型
  2. collection:list

批量修改List

    /** @description 批量更新多个日程
     * @author wangkaishuang
     * @date 2018/8/14
     * @param [events]
     * @return java.util.List<com.wps.calendar.core.model.Event>
     */
    @Update({
            "<script>",
            "<foreach index = 'index' item ='item' collection = 'list' separator = ','>",
            "update event",
            "set summary = #{item.summary},description = #{item.description},location = #{item.location},start_time = #{item.startTime},end_time = #{item.endTime},time_zone = #{item.timeZone},",
            "event_type = #{item.eventType},action_type = #{item.actionType},notice_time = #{item.noticeTime},reminders = #{item.reminders},recurrence = #{item.recurrence},notice_status = #{item.noticeStatus},event_priority = #{item.eventPriority},",
            "event_status = #{item.eventStatus},share_status = #{item.shareStatus},creator_id = #{item.creatorId},calendar_id = #{item.calendarId},share_event_id = #{item.shareEventId},origin_event_id = #{item.originEventId},",
            "finish_message = #{item.finishMessage},delete_reason = #{item.deleteReason},etag = #{item.etag},expire_date = #{item.expireDate},event_shared_date = #{item.eventSharedDate},split_id = #{item.splitId},create_time = #{item.createTime},",
            " where id = #{item.id}",
            "</foreach>",
            "</script>"
    })
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    int updateAll(@Param("list") List<Event> list);
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页