当前位置: 首页 > news >正文

深圳住房建设厅网站首页中国域名交易平台

深圳住房建设厅网站首页,中国域名交易平台,杭州外贸网站建设公司排名,做网站ui去哪儿接私活在工程应用中#xff0c;通常会遇到多表更新操作#xff0c;在集成mybatis中需要在执行插入语句后返回主键id进行后续的表更新操作#xff0c;下面对其实现的方式记录分享出来#xff0c;以应对不同的应用场景。 1、在xml文件中应用useGeneratedKeys和keyProperty 在xml文… 在工程应用中通常会遇到多表更新操作在集成mybatis中需要在执行插入语句后返回主键id进行后续的表更新操作下面对其实现的方式记录分享出来以应对不同的应用场景。 1、在xml文件中应用useGeneratedKeys和keyProperty 在xml文件中insert标签属性中添加useGeneratedKeys和keyProperty类似如下 insert idinsert parameterTypecom.***.Attachment useGeneratedKeystrue keyPropertyattachment.id keyColumnidinsert into b_attachmenttrim prefix( suffix) suffixOverrides,if testattachment.id ! -1id,/ifif testattachment.fileName ! null and attachment.fileName !file_name,/ifif testattachment.remarks ! null and attachment.remarks !remarks,/if/trimtrim prefixvalues ( suffix) suffixOverrides,if testattachment.id ! -1#{attachment.id,jdbcTypeBIGINT},/ifif testattachment.fileName ! null and attachment.fileName !#{attachment.fileName,jdbcTypeVARCHAR},/ifif testattachment.remarks ! null and attachment.remarks !#{attachment.remarks,jdbcTypeVARCHAR},/if/trim/insert通过这种方式插入的值经常会返回1原因是因为他这里的意思是返回当前影响的行数不能准确返回你新插入的id值有时候返回的结果是准确的。 2、在xml文件中应用selectKey 在xml文件中insert标签属性中添加selectKey标签属性各个属性值含义resultType:查询结果的类型keyProperty把查询的值赋给谁order在插入前还是后执行id在insert语句插入之后才会生成id所以要在插入之后执行所以此处orderafter。类似如下 insert idinsert parameterTypecom.***.AttachmentselectKey resultTypejava.lang.Integer orderAFTER keyPropertyattachment.idselect LAST_INSERT_ID()/selectKeyinsert into b_attachmenttrim prefix( suffix) suffixOverrides,if testattachment.id ! -1id,/ifif testattachment.fileName ! null and attachment.fileName !file_name,/ifif testattachment.remarks ! null and attachment.remarks !remarks,/if/trimtrim prefixvalues ( suffix) suffixOverrides,if testattachment.id ! -1#{attachment.id,jdbcTypeBIGINT},/ifif testattachment.fileName ! null and attachment.fileName !#{attachment.fileName,jdbcTypeVARCHAR},/ifif testattachment.remarks ! null and attachment.remarks !#{attachment.remarks,jdbcTypeVARCHAR},/if/trim/insert注意keyProperty属性的值一定为对应对象的主键id否则获取不到返回的主键id。 3、注解方式 在mapper层用注解的方式用SelectKey注解里面属性含义resultType:查询结果的类型keyProperty把查询的值赋给谁 statement:查找最后一个插入的id keyColumn查询的是哪一列 before是否在插入之前执行 id在insert语句插入之后才会生成id所以要在插入之后执行所以此处beforefalse。 Insert(insert into b_attachment values(#{id},#{fileName},#{remarks}) SelectKey(statement select last_insert_id() from dual, before false, resultType Interger.class, keyColumn id, keyProperty attachment.id) int add(Param(attachment) Attachment attachment);其中“select last_insert_id()”这条语句它是配合插入语句一块只用的在insert语句执行成功后可以返回新增数据的id。 4、使用方式 在service层类似如下 ...orderMapper.insert(order);//先执行插入order的语句Integer id order.getId();//通过order.getId()获取你新插入数据的id值...
http://wiki.neutronadmin.com/news/212540/

相关文章:

  • 濮阳网站建设熊掌网络做物流的网站有哪些
  • 网站制作 推荐新鸿儒phpwind与wordpress
  • 建国际网站需要多少钱电商网站制作成手机app
  • 关于建立公司网站的申请深圳网站建设服务联系方式
  • 长安网站设计嘉兴cms模板建站
  • seo 网站关键词优化免费上传图片的网址
  • 广东个人网站备案建站行业发展趋势
  • 单网页网站制作旅游网站的制作
  • 适合新手模仿的网站2017做那个网站能致富
  • 东莞市主营网站建设平台响应式企业网站设计
  • 微信 网站wordpress5.2.2中文
  • 网站建设优化兼职在家如何自己创建一个网址
  • 网站宣传推广方案网站功能表
  • 苏州网站开发公司兴田德润简介网站搭建策略与方法有哪些方面
  • 做网站可以不写代码做网贷网站多少钱
  • 怎么样关闭网站中国建筑网官网首页
  • 中国建设银行信用卡中心网站wordpress2014
  • 买机票便宜网站建设企业网站建设的意义
  • 织梦做的网站打开慢html网页模板代码下载
  • 好看的学校网站首页wordpress 轻论坛
  • 台州 做网站嘉兴市城乡规划建设局网站
  • title 芜湖网站制作wordpress文章分类插件
  • 别样网图片素材网站用html5做网站百度经验
  • 外贸型网站建设方法网络系统定级备案
  • 湖南兼职网站建设h5平台官网
  • 成都高档网站建设wordpress当前分类下所有子分类
  • 如何做网站视频外贸信息发布平台
  • 收费网站设计平面排版网站
  • 无锡网站设计多少钱大气蓝色律师网站phpcms模板
  • 精美的php个人网站源码个体网站建设