|
@@ -2,8 +2,10 @@ package com.coffee.common.crud.controller;
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.mapper.Mapper;
|
|
import com.baomidou.mybatisplus.core.mapper.Mapper;
|
|
|
import com.coffee.common.crud.BaseService;
|
|
import com.coffee.common.crud.BaseService;
|
|
|
|
|
+import com.coffee.common.entity.GenericEntity;
|
|
|
import com.coffee.common.result.R;
|
|
import com.coffee.common.result.R;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
import java.io.Serializable;
|
|
@@ -26,14 +28,14 @@ public interface BaseSaveController<E,K extends Serializable> extends
|
|
|
|
|
|
|
|
@PostMapping("/_batch")
|
|
@PostMapping("/_batch")
|
|
|
@ApiOperation(value = "批量新增数据")
|
|
@ApiOperation(value = "批量新增数据")
|
|
|
- default R add(@RequestBody List<E> payload) {
|
|
|
|
|
|
|
+ default R add(@RequestBody @Validated(GenericEntity.Insert.class) List<E> payload) {
|
|
|
saveAuth();
|
|
saveAuth();
|
|
|
return getService().saveBatch(payload)?R.success():R.fail("数据新增失败");
|
|
return getService().saveBatch(payload)?R.success():R.fail("数据新增失败");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@PostMapping("/add")
|
|
@PostMapping("/add")
|
|
|
@ApiOperation(value = "新增单个数据,并返回新增后的数据.")
|
|
@ApiOperation(value = "新增单个数据,并返回新增后的数据.")
|
|
|
- default R add(@RequestBody E payload) {
|
|
|
|
|
|
|
+ default R add(@RequestBody @Validated(GenericEntity.Insert.class)E payload) {
|
|
|
saveAuth();
|
|
saveAuth();
|
|
|
return getService().save(payload)?R.success(payload):R.fail("数据新增失败");
|
|
return getService().save(payload)?R.success(payload):R.fail("数据新增失败");
|
|
|
}
|
|
}
|
|
@@ -41,7 +43,7 @@ public interface BaseSaveController<E,K extends Serializable> extends
|
|
|
|
|
|
|
|
@PostMapping("/edit")
|
|
@PostMapping("/edit")
|
|
|
@ApiOperation(value = "根据ID修改数据")
|
|
@ApiOperation(value = "根据ID修改数据")
|
|
|
- default R update(@RequestBody E payload) {
|
|
|
|
|
|
|
+ default R update(@RequestBody @Validated(GenericEntity.Update.class)E payload) {
|
|
|
editAuth();
|
|
editAuth();
|
|
|
return getService().updateById(payload)?R.success(payload):R.fail("更新失败");
|
|
return getService().updateById(payload)?R.success(payload):R.fail("更新失败");
|
|
|
}
|
|
}
|