vue element多对多

客户列表

idea代码

/**

  • 前端控制器

  • @author liyi

  • @since 2020-05-01
    */
    @RestController
    @RequestMapping("/client")
    public class ClientController {

    @Autowired
    private IClientService iClientService;
    @Autowired
    private ICBService icbService;

    @RequestMapping("/list")
    public ResultApi list(Page page , ClientVo vo){
    return ResultApi.success(iClientService.selectPageVo(page,vo));
    }

    @RequestMapping(“inserts”)
    public ResultApi inserts(@RequestBody ClientVo clientVo){
    try{
    //先保存主表
    iClientService.save(clientVo);
    System.out.println(clientVo);
    System.out.println(clientVo.getBids());
    if(clientVo.getBids()!=null && !clientVo.getBids().equals("")){
    //拆分数组
    String[] bids = clientVo.getBids().split(",");
    ArrayList cbList = new ArrayList<>();
    for (String bid:bids) {
    CB cb = new CB();
    cb.setCid(clientVo.getId());
    cb.setBid(Integer.parseInt(bid));
    cbList.add(cb);
    }
    icbService.saveBatch(cbList);
    }
    return ResultApi.success(true);
    }catch (Exception e){
    e.printStackTrace();
    }
    return ResultApi.error(false);
    }

    @RequestMapping(“updates”)
    public ResultApi updates(@RequestBody ClientVo clientVo){
    try{
    //获取用户的id值
    Integer cid = clientVo.getId();
    //设置添加
    QueryWrapper queryWrapper = new QueryWrapper();
    queryWrapper.eq(“cid”, cid);
    //根据用户的uid进行删除中间表
    icbService.remove(queryWrapper);
    //先跟新主表
    iClientService.updateById(clientVo);
    System.out.println(clientVo);
    System.out.println(clientVo.getBids());
    if(clientVo.getBids()!=null && !clientVo.getBids().equals("")){
    //拆分数组
    String[] bids = clientVo.getBids().split(",");
    ArrayList cbList = new ArrayList<>();
    for (String bid:bids) {
    CB cb = new CB();
    cb.setCid(clientVo.getId());
    cb.setBid(Integer.parseInt(bid));
    cbList.add(cb);
    }
    icbService.saveBatch(cbList);
    }
    return ResultApi.success(true);
    }catch (Exception e){
    e.printStackTrace();
    }
    return ResultApi.error(false);
    }

    @RequestMapping("/delete")
    public ResultApi delete(Integer ids[]){
    try {
    QueryWrapper wrapper = new QueryWrapper();
    for (Integer cid:ids) {
    wrapper.eq(“cid”,cid);
    icbService.remove(wrapper);
    }
    iClientService.removeByIds(Arrays.asList(ids));
    System.out.println(ids);
    return ResultApi.success(true);
    }catch (Exception e){
    e.printStackTrace();
    }
    return ResultApi.error(false);
    }
    }

实体类扩展 Vo类
@Data
public class ClientVo extends Client {
//银行名称
private String bids;
private String bname;
}

Mapper sql语句



SELECT c.*,GROUP_CONCAT(b.`name`) as bname,GROUP_CONCAT(b.id) as bids FROM f_client c LEFT JOIN c_b z ON (c.id=z.cid) LEFT JOIN f_bank b ON (z.bid=b.id) and b.name like concat ('%',#{vo.bname},'%') or c.name like concat ('%',#{vo.bname},'%') GROUP BY c.id
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值