日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mybatisplus 一次性执行多条SQL语句插入(Oracle篇)

發(fā)布時(shí)間:2024/9/27 数据库 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mybatisplus 一次性执行多条SQL语句插入(Oracle篇) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

          • 一、數(shù)據(jù)庫部分
            • 1. 創(chuàng)建數(shù)據(jù)庫
            • 2. 初始化表結(jié)構(gòu)
          • 二、代碼部分
            • 2.1. controller
            • 2.2. mapper接口
            • 2.3. 映射文件
            • 2.4. 參數(shù)封裝
          • 三、測(cè)試驗(yàn)證
            • 3.1. 發(fā)起請(qǐng)求
            • 3.2. 查看數(shù)據(jù)庫
            • 3.3. 配置文件部分

一、數(shù)據(jù)庫部分
1. 創(chuàng)建數(shù)據(jù)庫

創(chuàng)建more-insert

2. 初始化表結(jié)構(gòu)
-- 一次性插入多張表測(cè)試 --oracle 表結(jié)構(gòu) create table HERO (SNO VARCHAR2(20) not null,USER_NAME VARCHAR2(20),AGE NUMBER(3) );alter table HEROadd primary key (SNO);create table HERO2 (SNO VARCHAR2(20) not null,USER_NAME VARCHAR2(20),AGE NUMBER(3) ); alter table HERO2add primary key (SNO);
二、代碼部分

聲明:這里為了演示省略service層

2.1. controller
package com.gblfy.modular.order.controller;import com.gblfy.modular.order.mapper.MysqlMoreInsertMapper; import com.gblfy.modular.order.model.request.OracleMoreInsertParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;@RestController public class MoreController {@Autowiredprivate OraclelMoreInsertMapper oraclelMoreInsertMapper;@GetMapping("/oracleMoreInsert")public String oracleMoreInsert() {OracleMoreInsertParam oracleMoreInsertParam = new OracleMoreInsertParam();oracleMoreInsertParam.setSno("1");oracleMoreInsertParam.setUserName("Name1");oracleMoreInsertParam.setAge(1);oracleMoreInsertParam.setSno2("2");oracleMoreInsertParam.setUserName2("Name2");oracleMoreInsertParam.setAge2(2);oraclelMoreInsertMapper.oraclelmoreInsert(oracleMoreInsertParam);return "SUCCESS";} }
2.2. mapper接口
package com.gblfy.modular.order.mapper;import com.baomidou.dynamic.datasource.annotation.DS; import com.gblfy.modular.order.model.request.OracleMoreInsertParam; import org.apache.ibatis.annotations.Param;/*** <p>* 通用Mapper 接口* </p>** @author gblfy* @since 2021-08-13*/ @DS("oracle_1") public interface OraclelMoreInsertMapper {void oraclelmoreInsert(@Param("paramCondition") OracleMoreInsertParam paramCondition);}

mapper類上添加@DS注解是因?yàn)槲沂褂昧硕鄶?shù)據(jù)源,不涉及可以刪除此注解

2.3. 映射文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.gblfy.modular.order.mapper.OraclelMoreInsertMapper"><insert id="oraclelmoreInsert" parameterType="com.gblfy.modular.order.model.request.OracleMoreInsertParam">begininsert into hero(SNO, USER_NAME, AGE) values (#{paramCondition.sno}, #{paramCondition.userName}, #{paramCondition.age});insert into hero2(SNO, USER_NAME, AGE) values (#{paramCondition.sno2}, #{paramCondition.userName2}, #{paramCondition.age2});end;</insert></mapper>
2.4. 參數(shù)封裝
package com.gblfy.modular.order.model.request;import lombok.Data;import java.io.Serializable;/*** oracle演示對(duì)象** @author gblfy* @since 2021-08-13*/ @Data public class OracleMoreInsertParam implements Serializable {private static final long serialVersionUID = 1L;private String sno;private String userName;private Integer age;private String sno2;private String userName2;private Integer age2; }
三、測(cè)試驗(yàn)證
3.1. 發(fā)起請(qǐng)求

http://localhost/oracleMoreInsert

3.2. 查看數(shù)據(jù)庫


3.3. 配置文件部分
########################################## 多數(shù)據(jù)源配置 ############################################ spring:datasource:dynamic:primary: master #設(shè)置默認(rèn)的數(shù)據(jù)源或者數(shù)據(jù)源組,默認(rèn)值即為masterstrict: false #嚴(yán)格匹配數(shù)據(jù)源,默認(rèn)false. true未匹配到指定數(shù)據(jù)源時(shí)拋異常,false使用默認(rèn)數(shù)據(jù)源datasource:master:url: jdbc:mysql://localhost:3306/more-insert?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true&allowMultiQueries=trueusername: rootpassword: 123456driver-class-name: com.mysql.cj.jdbc.Driver # 3.2.0開始支持SPI可省略此配置filters: wall,mergeStatoracle_1:driver-class-name: oracle.jdbc.OracleDriverurl: jdbc:oracle:thin:@192.168.xxx.xxx:1521:orclusername: orclpassword: orclfilters: wall,mergeStat

總結(jié)

以上是生活随笔為你收集整理的mybatisplus 一次性执行多条SQL语句插入(Oracle篇)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。