客户列表
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语句