级联删除,联级删除,根据关联字段,在A表中删除B表中的关联内容

目的:两个关联表,A表为主表,B表为次表,删除A表中一行内容时,连同B表中的关联内容一同删除。
思路:在B表中要写一个新的删除语句,在Mapper.xml中用SQL语句写出根据两表相同字段删除内容。然后在A表的controller层删除语句中添加调用之前的方法。(例如:相同字段为contractId)
我使用的框架是:springboot+thymeleaf

B表dao层:

public int deleteItemByContractIds(String[] contractIds);

B表service层:

public int deleteItemByContractIds(String ids);

B表service.impl层:

@Override
	public int deleteItemByContractIds(String ids) {
		return contractItemMapper.deleteItemByContractIds(Convert.toStrArray(ids));
	}

B表Mapper.xml:

<delete id="deleteItemByContractIds" parameterType="String">
        delete from fd_contract_item where contract_id in 
        <foreach item="contractId" collection="array" open="(" separator="," close=")">
        	#{contractId}
        </foreach>
    </delete>

A表controller层:

public AjaxResult remove(String ids)
    {	
    	contractItemService.deleteItemByContractIds(ids);//就是这句话,调用B表中的内容
        return toAjax(contractService.deleteContractByIds(ids));
    }
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值