package com.example.demo11.Controller;标签:10,return,users,usersService,Result,import,public From: https://www.cnblogs.com/luoqingci/p/18556211
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo11.Service.UsersService;
import com.example.demo11.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/users")
public class UsersController {
@Autowired
private UsersService usersService;
@GetMapping()
public Result<List<Users>> getAll() {
//查询所有
return Result.success(usersService.list());
}
@GetMapping("/page")
public Result<IPage<Users>> getPage(PageVo page) {
//分页查询
IPage<Users> userPage = usersService.getPage(page);
return Result.success(userPage);
}
@PostMapping()
public Result<Users> addUser(@RequestBody Users users) {
//新增
usersService.save(users);
return Result.success(users);
}
@PutMapping("/{id}")
public Result<Users> updateUser(@RequestBody Users users) {
//修改
usersService.updateById(users);
return Result.success(users);
}
@DeleteMapping("/{id}")
public Result<Users> deleteUser( @PathVariable("id") Integer id) {
//删除
usersService.removeById(id);
return Result.success();
}
}