mybatis 注解形式设置批量新增、批量更新数据

摘要:
1.批量更新:@Update({""+""+"UPDATE"+"mt_message_template"+"SETpushapp_type=#{item.pushAppType,jdbcType=VARCHAR},"+"message_title=#

1. 批量更新:

    @Update({"<script>" +
            "<foreach collection="smsConfigTemplateList" item="item" separator=";">" +
            " UPDATE" +
            " mt_message_template" +
            " SET pushapp_type = #{item.pushAppType, jdbcType=VARCHAR}, " +
            "  message_title = #{item.messageTitle, jdbcType=VARCHAR}, " +
            "  message_content = #{item.messageContent, jdbcType=VARCHAR}, " +
            "  template_id_weixin = #{item.emplateIdWeixin, jdbcType=VARCHAR}, " +
            "  template_weixin = #{item.templateWeixin, jdbcType=VARCHAR}, " +
            "  template_alipay = #{item.templateAlipay, jdbcType=VARCHAR}, " +
            "  template_id_zhifubao = #{item.templateIdZhifubao, jdbcType=VARCHAR}, " +
            "  modifiedon = #{item.modifiedon, jdbcType=TIMESTAMP}, " +
            "  modifiedby = #{item.modifiedby, jdbcType=VARCHAR} " +
            "  WHERE " +
            "   message_template_id = #{item.messageTemplateId, jdbcType=VARCHAR} " +
            "  AND deletion_state = '0' " +
            "</foreach>" +
            "</script>"})
    void update(@Param("smsConfigTemplateList") List<SmsConfigTemplate> smsConfigTemplateList);

2. 批量新增:

    @Insert({"<script>" +
            "INSERT INTO  mt_message_template (" +
            "message_template_id,
" +
            "message_template_head_id,
" +
            "message_title,
" +
            "message_content,
" +
            "pushapp_type,
" +
            "platform_hospital_id,
" +
            "template_id_weixin,
" +
            "template_weixin,
" +
            "template_alipay,
" +
            "template_id_zhifubao,
" +
            "createdby,
" +
            "createdon,
" +
            "modifiedby,
" +
            "modifiedon,
" +
            "deletion_state)" +
            "values  " +
            "<foreach collection="mtMessageTemplateList" item="item" separator=",">" +
            "(#{item.messageTemplateId}, #{item.messageTemplateHeadId}, " +
            "#{item.messageTitle}, #{item.messageContent}, " +
            "#{item.pushAppType}, #{item.platformHospitalId}, " +
            "#{item.emplateIdWeixin}, #{item.templateWeixin}, " +
            "#{item.templateAlipay}, #{item.templateIdZhifubao}, " +
            "#{item.createdby}, #{item.createdon}, " +
            "#{item.modifiedby}, #{item.modifiedon}, " +
            "#{item.deletionState})" +
            "</foreach>" +
            "</script>"})
    void insert(@Param("mtMessageTemplateList") List<MtMessageTemplate> mtMessageTemplateList);

免责声明:文章转载自《mybatis 注解形式设置批量新增、批量更新数据》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇FFmpeg编程(二)FFmpeg中级开发JAVA 执行控制流程下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

创建项目

---恢复内容开始--- 一、创建父工程 eshop-parent选择pom进行创建   添加pom.xml依赖    <!-- 集中定义依赖版本号 --> <properties> <junit.version>4.12</junit.version> <spring.version>4.2.4...

MyBatis(四)映射文件 之 参数获取详解#{} 与 ${}

一、#{} 与${} 的取值 相同点: #{}:可以获取map中的值或者pojo对象属性的值; ${}:可以获取map中的值或者pojo对象属性的值; 区别: #{}:是以预编译的形式,将参数设置到sql语句中;PreparedStatement;防止sql注入; ${}:取出的值直接拼装在sql语句中;会有安全问题; 大多情况下,我们去参数的值都应该去使...

MySQL面试题收集

1、MySQL的复制原理以及流程 基本原理流程,3个线程以及之间的关联; 1. 主:binlog线程——记录下所有改变了数据库数据的语句,放进master上的binlog中; 2. 从:io线程——在使用start slave 之后,负责从master上拉取 binlog 内容,放进 自己的relay log中; 3. 从:sql执行线程——执行relay...

Mybatis中 ResultMap的collection配置一对多使用详解

resultMap可以将查询到的多种数据,映射到一个符合要求的对象上。   1.实现操作的基本流程     调用Mapper接口的方法→→Mapper.xml文件中对应id的查询语句(接口的方法名=查询语句的id)→查询语句配置resultMap属性(属性值是其对应ResultMap标签的id)→在resultMap标签中,配置查到的表的字段与对象的属性的...

Mybatis笔记

这几天学习了Mybatis相关内容,在此整理一下这几天的笔记。 第一天 mybatis入门 mybatis的概述 mybatis的环境搭建 mybatis的入门案例 自定义mybatis框架 1 什么是框架 他是我们软件开发中的一套解决方案,不同的框架解决的是不同的问题。 使用框架的好处:框架封装了很多的细节,使开发者可以使用极简的方式实现功能。大大提...

Mybatis-第N篇配置log4j1、log4j2打印执行的sql语句

1、log4j1配置    目录结构:       conf.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/myba...