package com.benyun.controller; import com.benyun.boot.core.vo.Result; import lombok.RequiredArgsConstructor; import com.benyun.entity.User; import com.benyun.service.UserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.beetl.sql.core.engine.PageQuery; import java.util.List; /** * 用户管理 * * @author makejava * create on 2023-03-17 09:06:58 */ @RestController @RequestMapping("user") @RequiredArgsConstructor(onConstructor_ = {@Autowired}) public class UserController { /** * 服务对象 */ private final UserService userService; /** * 查询所有数据 * * @return 所有数据 */ @GetMapping("/queryAll") public Result> queryAll() { return Result.success(userService.queryAll()); } /** * 分页查询数据 * * @return 所有数据 */ @GetMapping("/queryPage") public Result> queryPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, User user) { PageQuery pageQuery = new PageQuery(); pageQuery.setPageSize(pageSize); pageQuery.setPageNumber(pageNum); pageQuery.setParas(user); return userService.queryByPage(pageQuery); } /** * 通过主键查询单条数据 * * @param id 主键 * @return 单条数据 */ @GetMapping("/queryOne") public Result queryOne(@RequestParam("id") Integer id) { return Result.success(userService.queryById(id)); } /** * 通过主键查询单条数据 * * @return 单条数据 */ @GetMapping("/getUserInfo") public Result getUserInfo() { return Result.success(); } /** * 新增数据 * * @param user 实体对象 * @return 新增结果 */ @PostMapping("/create") public Result create(@RequestBody User user) { userService.insert(user); return Result.success(user); } /** * 修改数据 * * @param user 实体对象 * @return 修改结果 */ @PostMapping("/update") public Result update(@RequestBody User user) { return userService.updateById(user) ? Result.success() : Result.failure(); } /** * 删除数据 * * @param id 主键 * @return 删除结果 */ @PostMapping("/delete") public Result delete(@RequestParam("id") Integer id) { return Result.success(this.userService.deleteById(id)); } }