123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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<List<User>> queryAll() {
- return Result.success(userService.queryAll());
- }
-
- /**
- * 分页查询数据
- *
- * @return 所有数据
- */
- @GetMapping("/queryPage")
- public Result<List<User>> queryPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, User user) {
- PageQuery<User> pageQuery = new PageQuery<User>();
- pageQuery.setPageSize(pageSize);
- pageQuery.setPageNumber(pageNum);
- pageQuery.setParas(user);
- return userService.queryByPage(pageQuery);
- }
- /**
- * 通过主键查询单条数据
- *
- * @param id 主键
- * @return 单条数据
- */
- @GetMapping("/queryOne")
- public Result<User> queryOne(@RequestParam("id") Integer id) {
- return Result.success(userService.queryById(id));
- }
- /**
- * 通过主键查询单条数据
- *
- * @return 单条数据
- */
- @GetMapping("/getUserInfo")
- public Result<User> 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<Boolean> delete(@RequestParam("id") Integer id) {
- return Result.success(this.userService.deleteById(id));
- }
- }
|