目录
展示查询搜索
根据id展示数据
根据id删除数据
根据id更新数据
添加数据
展示查询搜索
// 根据姓名分页查询用户@GetMapping("/getUsersByName")public IPage<User> getUsersByName(@RequestParam(defaultValue = "1") Long current,@RequestParam(defaultValue = "2") Long size,@RequestParam(required = false) String name) {// 构建分页对象Page<User> page = new Page<>(current, size);// 调用服务方法进行分页查询return userService.getUsersByName(page, name);}
Postman路径:http://localhost:8080/test/user/getUsersByName2?current=1&size=3&name=z
根据id展示数据
@GetMapping("/{userId}")public R<User> getUserById(@PathVariable Long userId) {return userService.getUserById(userId);}
postman测试:http://localhost:8080/test/user/1
根据id删除数据
// 删除用户@DeleteMapping("/{userId}")public R<String> deleteUser(@PathVariable Long userId) {return userService.deleteUser(userId);}
PostMan测试: http://localhost:8080/test/user/1
根据id更新数据
// 更新用户信息@PutMapping("/updateUser")public R<String> updateUser(@RequestBody User user) {return userService.updateUser(user);}
postman测试:http://localhost:8080/test/user/updateUser
添加数据
// 新增用户@PostMapping("/addUser")public R<String> addUser(@RequestBody User user) {return userService.addUser(user);}
postman测试: http://localhost:8080/test/user/addUser