【Java毕设选题推荐】基于SpringBoot的springboot基于BS构架的失物招领系统设计与实现

时间:2025-04-07 08:05:10
import org.springframework.web.bind.annotation.*; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import your.package.name.model.LostItem; // 假设你的失物模型类名为LostItem import your.package.name.service.LostItemService; // 假设你的服务名为LostItemService import org.springframework.beans.factory.annotation.Autowired; @RestController @RequestMapping("/lostItems") public class LostItemController { @Autowired private LostItemService lostItemService; // 获取所有失物列表 @GetMapping public Page<LostItem> getAllLostItems( @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) { Page<LostItem> lostItemsPage = new Page<>(page, size); QueryWrapper<LostItem> queryWrapper = new QueryWrapper<>(); // 这里可以添加查询条件 return lostItemService.page(lostItemsPage, queryWrapper); } // 根据ID获取单个失物信息 @GetMapping("/{id}") public LostItem getLostItemById(@PathVariable Long id) { return lostItemService.getById(id); } // 创建新的失物信息 @PostMapping public void createLostItem(@RequestBody LostItem lostItem) { lostItemService.save(lostItem); } // 更新失物信息 @PutMapping("/{id}") public void updateLostItem(@PathVariable Long id, @RequestBody LostItem lostItem) { lostItem.setId(id); lostItemService.updateById(lostItem); } // 删除失物信息 @DeleteMapping("/{id}") public void deleteLostItem(@PathVariable Long id) { lostItemService.removeById(id); } }