【Java毕设项目推荐】基于SpringBoot的springboot国风彩妆网站

时间:2025-04-07 08:52:19
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.pojo.BeautyProduct; // 假设你的彩妆产品实体类名为BeautyProduct import your.package.name.service.BeautyProductService; // 假设你的服务名为BeautyProductService @RestController @RequestMapping("/api/beauty-products") public class BeautyProductController { private final BeautyProductService beautyProductService; public BeautyProductController(BeautyProductService beautyProductService) { this.beautyProductService = beautyProductService; } // 获取所有彩妆产品 @GetMapping public Page<BeautyProduct> getAllBeautyProducts( @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size, @RequestParam(required = false) String keyword) { Page<BeautyProduct> beautyProductsPage = new Page<>(page, size); QueryWrapper<BeautyProduct> queryWrapper = new QueryWrapper<>(); if (keyword != null && !keyword.isEmpty()) { queryWrapper.and(wrapper -> wrapper.like("name", keyword) .or() .like("description", keyword) ); } return beautyProductService.page(beautyProductsPage, queryWrapper); } // 根据ID获取单个彩妆产品 @GetMapping("/{id}") public BeautyProduct getBeautyProductById(@PathVariable Long id) { return beautyProductService.getById(id); } // 创建新的彩妆产品 @PostMapping public BeautyProduct createBeautyProduct(@RequestBody BeautyProduct beautyProduct) { beautyProductService.save(beautyProduct); return beautyProduct; } // 更新彩妆产品信息 @PutMapping("/{id}") public BeautyProduct updateBeautyProduct(@PathVariable Long id, @RequestBody BeautyProduct beautyProduct) { beautyProduct.setId(id); beautyProductService.updateById(beautyProduct); return beautyProduct; } // 删除彩妆产品 @DeleteMapping("/{id}") public void deleteBeautyProduct(@PathVariable Long id) { beautyProductService.removeById(id); } }