Update AdminController.java

main
pveayojnc 4 months ago
parent 6ef529c891
commit 80e35cf1bd

@ -13,50 +13,86 @@ import org.springframework.web.bind.annotation.*;
import java.util.List;
@Api("管理员管理器")
@RestController
@RequestMapping("/sms/adminController")
/**
*
* RESTful
* /sms/adminController
*/
@Api(tags = "管理员管理器", value = "提供管理员信息的CRUD操作") // Swagger接口分组说明
@RestController // 声明为Spring MVC控制器自动将返回值转为JSON
@RequestMapping("/sms/adminController") // 基础请求路径
public class AdminController {
@Autowired
AdminService adminService;
@Autowired // 自动注入管理员服务层
private AdminService adminService;
// http://localhost:8080/sms/adminController/getAllAdmin/1/3?adminName=
@ApiOperation("根据分页条件查询管理员信息")
/**
*
* http://localhost:8080/sms/adminController/getAllAdmin/1/3?adminName=张
*
* @param pageNo
* @param pageSize
* @param adminName
* @return
*/
@ApiOperation(value = "分页查询管理员信息", notes = "根据姓名模糊查询+分页")
@GetMapping("/getAllAdmin/{pageNo}/{pageSize}")
public Result getAllAdmin(
@ApiParam("分页查询的页码数") @PathVariable("pageNo") Integer pageNo,
@ApiParam("分页查询的页大小") @PathVariable("pageSize") Integer pageSize,
@ApiParam("要查询的管理员姓名") String adminName
){
Page<Admin> adminPage = new Page<>(pageNo, pageSize);
Page<Admin> adminPage1 = adminService.getAllAdminData(adminPage,adminName);
return Result.ok(adminPage1);
@ApiParam(value = "页码", example = "1", required = true)
@PathVariable("pageNo") Integer pageNo,
@ApiParam(value = "每页数量", example = "10", required = true)
@PathVariable("pageSize") Integer pageSize,
@ApiParam(value = "管理员姓名", example = "admin")
@RequestParam(required = false) String adminName) {
// 创建分页对象
Page<Admin> page = new Page<>(pageNo, pageSize);
// 调用服务层获取分页数据
Page<Admin> resultPage = adminService.getAllAdminData(page, adminName);
// 返回统一响应格式
return Result.ok(resultPage);
}
// http://localhost:8080/sms/adminController/saveOrUpdateAdmin
@ApiOperation("新增或者修改管理员信息")
/**
*
* http://localhost:8080/sms/adminController/saveOrUpdateAdmin
*
* @param admin JSON
* @return
*/
@ApiOperation(value = "保存管理员信息", notes = "新增时自动加密密码")
@PostMapping("/saveOrUpdateAdmin")
public Result saveOrUpdateAdmin(
@ApiParam("提交的管理员信息") @RequestBody Admin admin
){
Integer id = admin.getId();
if (null == id || 0 == id){
String password = admin.getPassword();
String encrypt = MD5.encrypt(password);
admin.setPassword(encrypt);
@ApiParam(value = "管理员信息", required = true)
@RequestBody Admin admin) {
// 新增操作时加密密码
if (admin.getId() == null || admin.getId() == 0) {
String encryptedPwd = MD5.encrypt(admin.getPassword());
admin.setPassword(encryptedPwd);
}
// 保存或更新数据
adminService.saveOrUpdate(admin);
return Result.ok();
}
// http://localhost:8080/sms/adminController/deleteAdmin
@ApiOperation("删除单个或多个管理员信息")
/**
*
* http://localhost:8080/sms/adminController/deleteAdmin
*
* @param ids IDJSON
* @return
*/
@ApiOperation(value = "批量删除管理员", notes = "支持单个或多个ID同时删除")
@DeleteMapping("/deleteAdmin")
public Result deleteAdmin(
@ApiParam("要删除的管理员的id列表") @RequestBody List<Integer> ids
){
@ApiParam(value = "管理员ID列表", example = "[1,2,3]", required = true)
@RequestBody List<Integer> ids) {
// 批量删除操作
adminService.removeByIds(ids);
return Result.ok();
}
}
}
Loading…
Cancel
Save