package com.example.controller; import com.example.common.Result; import com.example.entity.Notice; import com.example.service.NoticeService; import com.github.pagehelper.PageInfo; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.List; /** * 公告信息表前端操作接口 **/ @RestController @RequestMapping("/notice") public class NoticeController { @Resource private NoticeService noticeService; /** * 新增公告信息 * @param notice 公告对象 * @return 操作结果 */ @PostMapping("/add") public Result add(@RequestBody Notice notice) { noticeService.add(notice); return Result.success(); } /** * 根据ID删除公告信息 * @param id 公告ID * @return 操作结果 */ @DeleteMapping("/delete/{id}") public Result deleteById(@PathVariable Integer id) { noticeService.deleteById(id); return Result.success(); } /** * 批量删除公告信息 * @param ids 公告ID列表 * @return 操作结果 */ @DeleteMapping("/delete/batch") public Result deleteBatch(@RequestBody List ids) { noticeService.deleteBatch(ids); return Result.success(); } /** * 修改公告信息 * @param notice 公告对象 * @return 操作结果 */ @PutMapping("/update") public Result updateById(@RequestBody Notice notice) { noticeService.updateById(notice); return Result.success(); } /** * 根据ID查询公告信息 * @param id 公告ID * @return 公告对象 */ @GetMapping("/selectById/{id}") public Result selectById(@PathVariable Integer id) { Notice notice = noticeService.selectById(id); return Result.success(notice); } /** * 查询所有公告信息 * @param notice 公告对象,用于条件查询 * @return 公告列表 */ @GetMapping("/selectAll") public Result selectAll(Notice notice ) { List list = noticeService.selectAll(notice); return Result.success(list); } /** * 分页查询公告信息 * @param notice 公告对象,用于条件查询 * @param pageNum 页码 * @param pageSize 每页大小 * @return 分页的公告信息 */ @GetMapping("/selectPage") public Result selectPage(Notice notice, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) { PageInfo page = noticeService.selectPage(notice, pageNum, pageSize); return Result.success(page); } }