前后端分离之后端controller
package com.lpz.zonghezsgc.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lpz.zonghezsgc.api.ResultApi;
import com.lpz.zonghezsgc.entity.Cb;
import com.lpz.zonghezsgc.entity.Custom;
import com.lpz.zonghezsgc.service.ICbService;
import com.lpz.zonghezsgc.service.ICustomService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.xml.transform.Result;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吕沛哲
 * @since 2020-06-07
 */
@RestController
@RequestMapping("/custom")
public class CustomController {
    @Autowired
    private ICustomService iCustomService;
    @Autowired
    private ICbService iCbService;
    @RequestMapping("/list")
    public ResultApi list(Page page, Custom custom){
        return ResultApi.success(iCustomService.selectCustom(page,custom));
    }
    //用户删除
    @RequestMapping("/delete")
    @Transactional
    public ResultApi delete(Integer ids[]){
        try {
            //遍历用户id
            for (Integer cid:ids) {
                QueryWrapper wrapper = new QueryWrapper();
                wrapper.eq("cid", cid);
                //删除中间表
                iCbService.remove(wrapper);
            }
            //批量删除客户表
            iCustomService.removeByIds(Arrays.asList(ids));
            return ResultApi.success(true);
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return ResultApi.error(false);
    }
    //用户添加
    @RequestMapping("insert")
    @Transactional
    public ResultApi insert(@RequestBody Custom custom){
        try {
            //先保存主表
            iCustomService.save(custom);
            //判断是否有银行账号信息
            if(custom.getBids()!=null && !custom.getBids().equals("")){
                //拆分数组
                String[] bids = custom.getBids().split(",");//[1,2,3]
                List<Cb> cbList = new ArrayList<>();
                for(String bid:bids){
                    Cb cb = new Cb();
                    cb.setBid(Integer.parseInt(bid));
                    cb.setCid(custom.getCid());
                    cbList.add(cb);
                }
                iCbService.saveBatch(cbList);
            }
            return ResultApi.success(true);
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return ResultApi.error(false);
    }
    //用户修改
    @RequestMapping("update")
    @Transactional
    public ResultApi update(@RequestBody Custom custom){
        try{
            //获取客户id
            Integer cid = custom.getCid();
            //设置条件
            QueryWrapper wrapper = new QueryWrapper<>();
            wrapper.eq("cid",cid);
            //根据客户的cid进行删除中间表
            iCbService.remove(wrapper);
            //修改主表
            iCustomService.updateById(custom);
            //判断是否有银行账号信息
            if(custom.getBids()!=null && !custom.getBids().equals("")){
                //拆分数组
                String[] bids = custom.getBids().split(",");
                List<Cb> cbList = new ArrayList<>();
                for(String bid:bids){
                    Cb cb = new Cb();
                    cb.setBid(Integer.parseInt(bid));
                    cb.setCid(custom.getCid());
                    cbList.add(cb);
                }
                iCbService.saveBatch(cbList);
            }
            return ResultApi.success(true);
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return ResultApi.error(false);
    }
}
==============================================================
=================================================================
package com.lpz.zonghezsgc.controller;
import com.lpz.zonghezsgc.service.IBankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吕沛哲
 * @since 2020-06-07
 */
@RestController
@RequestMapping("/bank")
public class BankController {
    @Autowired
    private IBankService iBankService;
    @RequestMapping("findAll")
    public Object findAll(){
        return iBankService.list();
    }
}
                    
                
                
            
        
浙公网安备 33010602011771号