You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SRuml/SuperRice/springboot/src/main/java/com/example/controller/CollectController.java

112 lines
3.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.example.controller;
import com.example.common.Result;
import com.example.entity.Collect;
import com.example.service.CollectService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* CollectController类负责处理与收藏功能相关的前端请求。
* 它使用CollectService来执行具体的业务逻辑操作。
*/
@RestController
@RequestMapping("/collect")
public class CollectController {
@Resource
private CollectService collectService;
/**
* 新增收藏项。
*
* @param collect 待添加的收藏项信息包含用户ID和被收藏项的ID等信息。
* @return 返回操作结果,成功则返回成功信息。
*/
@PostMapping("/add")
public Result add(@RequestBody Collect collect) {
collectService.add(collect);
return Result.success();
}
/**
* 根据ID删除收藏项。
*
* @param id 要删除的收藏项的ID。
* @return 返回操作结果,成功则返回成功信息。
*/
@DeleteMapping("/delete/{id}")
public Result deleteById(@PathVariable Integer id) {
collectService.deleteById(id);
return Result.success();
}
/**
* 批量删除收藏项。
*
* @param ids 要删除的收藏项的ID列表。
* @return 返回操作结果,成功则返回成功信息。
*/
@DeleteMapping("/delete/batch")
public Result deleteBatch(@RequestBody List<Integer> ids) {
collectService.deleteBatch(ids);
return Result.success();
}
/**
* 修改收藏项信息。
*
* @param collect 包含要修改的收藏项的新信息。
* @return 返回操作结果,成功则返回成功信息。
*/
@PutMapping("/update")
public Result updateById(@RequestBody Collect collect) {
collectService.updateById(collect);
return Result.success();
}
/**
* 根据ID查询收藏项信息。
*
* @param id 要查询的收藏项的ID。
* @return 返回查询结果,包括收藏项的详细信息。
*/
@GetMapping("/selectById/{id}")
public Result selectById(@PathVariable Integer id) {
Collect collect = collectService.selectById(id);
return Result.success(collect);
}
/**
* 查询所有收藏项。
*
* @param collect 可选参数用于指定查询条件如用户ID。
* @return 返回所有符合条件的收藏项列表。
*/
@GetMapping("/selectAll")
public Result selectAll(Collect collect ) {
List<Collect> list = collectService.selectAll(collect);
return Result.success(list);
}
/**
* 分页查询收藏项。
*
* @param collect 可选参数用于指定查询条件如用户ID。
* @param pageNum 当前页码默认为1。
* @param pageSize 每页大小默认为10。
* @return 返回分页查询结果,包括总页数、总记录数及当前页的收藏项列表。
*/
@GetMapping("/selectPage")
public Result selectPage(Collect collect,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
PageInfo<Collect> page = collectService.selectPage(collect, pageNum, pageSize);
return Result.success(page);
}
}