Mybatis Oracle数据库批量更新数据

最近在项目中用到了批量数据的问题,记录一下
第一层、控制层代码:

@RestController
@RequestMapping("/dsDetailEntity")
public class demmoController {
    @Autowired
   	DmDsDetailService dmDsDetailService; // 注入业务层
   	
    @ApiOperation(value="编辑数据集合明细") // 使用了swagger注解
    @ApiImplicitParams({
       @ApiImplicitParam(name = "dmDsId", value = "集合主键ID", dataType = "String", required = true),
       @ApiImplicitParam(name = "dataEleIds", value = "数据元主键ID", dataType = "String", allowMultiple = true) 
    })
    @PutMapping(value="/update/dmDsDetail")
    public ResultMessage updateDmDsDetail(@RequestParam(value = "dataEleIds") List<String> dataEleIds,String dmDsId){
      	return dmDsDetailService.updateDmDsDetail(dataEleIds, dmDsId);
    }
}

第二层:业务层代码

package com.mxx.demo.base;
import com.baomidou.mybatisplus.extension.service.IService;
  /**
   * 所有服务层接口的父接口
   * @param <T> 操作所绑定的Entity
   */
public interface SuperService<T> extends IService<T> { // 继承了mybatis-plus的service接口
    // 可以封装一下公用的接口方法
    	
    /**
      * 异步插入一条记录
      * @param entity 实体对象
      */
      boolean asyncSave(T entity);
}

        
package com.mxx.demo.service;
// service层接口 (此处可以继承也可以不继承SuperService)
public interface DmDsDetailService extends SuperService<DmDsDetailEntity> { 
      // 编辑数据集合明细
      ResultMessage updateDmDsDetail(List<String> dataEleIds,String dmDsId);
}
---- --------------------------------------------- 

package com.mxx.demo.serviceImpl;
@Transactional
@Service
public class DmDsDetailServiceImpl  implements DmDsDetailService {
    @Autowired
	DmDsDetailMapper dmDsDetailMapper ;  
	
    // 编辑数据集明细
	@Override
	public ResultMessage updateDmDsDetail(List<String> dataEleIds, String dmDsId) {
           dmDsDetailMapper .updateDataEleOrderFlag(dataEleIds , dmDsId);
     }
}

第三层:mapper层

package com.mxx.demo.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
 * 所有 mapper 父类,注意这个类不要让 mp 扫描到!!
 */
public interface SuperMapper<T> extends BaseMapper<T> {
    // 这里可以放一些公共的方法
}


package com.mxx.demo.mapper;
//  Mapper层映射接口,继承了mybatis-plus的BaseMapper类(这样就可以使用mybatis-plus中封装好的方法了)
public interface DmDsDetailMapper extends SuperMapper<DmDsDetailEntity> {
      // 编辑数据集明细
      int updateDataEleOrderFlag(@Param("updateList") List<DmDsDetailEntity> updateList );
}
    
----------------- mapper映射文件(字段名和实体类名用resultMap进行转换映射)
  <!-- 编辑数据集明细 (所有参数都是实体类DmDsDetailEntity中的)-->
<update id="updateDataEleOrderFlag" parameterType="java.util.List">
      <foreach collection="updateList" item="item" index="index"  open="begin" close="end;">
		 update HJ_MDM_DM_DS_DETAIL
		 <set>
		     data_ele_order_flag = #{item.dataEleOrderFlag}
		 </set>
		 where data_ele_id = #{item.dataEleId} 
		        and dm_ds_id= #{item.dmDsId} 
		        and invalid_flag = #{item.invalidFlag};
       </foreach>
</update>
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值