当前位置: 首页 > 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://www.yutouwan.com/news/212540/

相关文章:

  • 住房和城乡建设部网站关于污水运行负荷率要求的文件360建筑网密码忘了
  • 最新某地方装修门户源码 php装饰公司程序 dede行业网站模板网页制作作业下载
  • 东莞网站建设五金建材房产信息查询系统入口
  • 合肥网站推广公司哪家好平面设计网站推荐
  • 沧州网站建设推广优分销app下载
  • 网站 逻辑结构营销网站建设流程图
  • 网站开发流程相关知识企业办公软件排名
  • 中国建设规划采购网站系统开发成本可以分为哪三种
  • 外贸品牌网站建设雅奇小蘑菇做网站好不好用
  • 网站建设公司挣钱吗手机网站制作教程软件
  • uni做网站首页wordpress后台乱码
  • 网站的服务器选择seo排名优化表格工具
  • 企业如何进行宣传和推广seo网站优化排名
  • 江苏大才建设集团网站iis 网站建设中
  • 专业轻电商网站建设公司wordpress简单投稿
  • 佛山网站建设网站建设收费上虞市建设风机厂网站
  • 如何做网站301重定向seo培训学校
  • 凡科网建站模板仪征做网站公司哪家好
  • 微商网站推广中国可信网站认证
  • 网站建设前途无锡网站搜索优化
  • 行业网站建设的书哪家公司做的网站好
  • 微网站开发案例重庆 网站 建设
  • asp黑网站源码苏州手机社区网站建设
  • 要加强县门户网站的建设管理百度竞价排名的利与弊
  • 高校工会网站建设工程建设方案
  • 赢了网站怎么做的北京网站建设+招聘信息
  • wordpress 上传网站吗如何查看网站的空间大小
  • 网站开发范本网站制作公司资质
  • 建网站 绑定域名 网址怎样做网站吸引人
  • 莆田外贸建站关键词优化举例