ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
#### 新增一条数据 Mapper接口 ``` //插入数据 - 可修改返回值类型 void insertWell(Map<String,Object> param)throws Exception; ``` Mapper.xml ``` <!--插入数据--> <insert id="insertWell" parameterType="java.util.HashMap"> INSERT INTO RTOC_ARTIFICIAL_MONTH <trim prefix="(" suffix=")" suffixOverrides=","> <if test="ARTIFICIAL_MONTH_ID!=null and ARTIFICIAL_MONTH_ID!=''">ARTIFICIAL_MONTH_ID,</if> <!--oracle日期转换--> <if test="STARTDRILL_TIME!=null and STARTDRILL_TIME!=''"> STARTDRILL_TIME, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="ARTIFICIAL_MONTH_ID!=null and ARTIFICIAL_MONTH_ID!=''">#{ARTIFICIAL_MONTH_ID},</if> <!--oracle日期转换--> <if test="STARTDRILL_TIME!=null and STARTDRILL_TIME!=''"> to_date(#{STARTDRILL_TIME} , 'yyyy-mm-dd hh24:mi:ss'), </if> </trim> </insert> ``` #### foreach字段添加 ``` <insert id="insert" parameterType="hashmap"> insert into ${_tableName} ( <foreach collection="data" index="colName" item="colValue" separator=",">${colName}</foreach> ) values ( <foreach collection="data" index="colName" item="colValue" separator=",">#{colValue}</foreach> ) </insert> ``` #### Mybatis批量插入到oracle ``` void insertOracle(List<Map<String,Object>> wellInfos); ``` ``` <insert id="insertOracle" parameterType="java.util.Map" useGeneratedKeys="false"> INSERT ALL <foreach item="item" index="index" collection="list"> INTO RTOC_WELLBOREID_RTDDATA ( ID, WELL_ID, WELLBORE_ID, WELL_DEPTH, TIME, TIMESTAMP, DATA ) VALUES ( #{item.id}, #{item.wellId}, #{item.wellboreId}, #{item.wellDepth}, #{item.time}, #{item.timeStamp}, #{item.data} ) </foreach> SELECT 1 FROM DUAL </insert> ```