package com.tong.common.web.web;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.List;
public abstract class IController, T> {
@Autowired
protected S service;
@GetMapping("/{id}")
@ApiOperation("根据主键获取业务信息")
public T get(@PathVariable String id) throws Exception {
return service.getById(id);
}
@PostMapping("/save")
@ApiOperation("保存或更新业务信息")
public T save(T t) throws Exception {
service.saveOrUpdate(t);
return t;
}
@DeleteMapping("/{id}")
@ApiOperation("根据主键删除业务信息")
public int delete(@PathVariable String id) throws Exception {
service.removeById(id);
return 1;
}
@DeleteMapping
@ApiOperation("根据主键批量删除业务信息")
public int delete(@RequestParam List id) throws Exception {
if (CollectionUtils.isEmpty(id)) return 0;
service.removeByIds(id);
return id.size();
}
}