package com.lele.Controller.utils;import lombok.Data;@Datapublic class R { private Boolean flag; private Object data; public R(){}; public R(Boolean flag){ this.flag = flag; } public R(Boolean flag,Object data){ this.flag=flag; this.data=data; }}
package com.lele.Controller;import com.baomidou.mybatisplus.core.metadata.IPage;import com.lele.Controller.utils.R;import com.lele.Service.IUserService;import com.lele.domain.User;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.*;import java.util.List;@RestController@RequestMapping("/collects")public class UserController2 { @Autowired private IUserService userService; @GetMapping public R getAll(){ return new R(true,userService.list()); } @PostMapping public R save(@RequestBody User user){// R r = new R();// boolean save = userService.save(user);// r.setFlag(save);// return r; return new R(userService.save(user)); } @PutMapping public R update(@RequestBody User user){ return new R(userService.updateById(user)); } @DeleteMapping({"id"}) public R delete(@PathVariable Integer id){ return new R(userService.removeById(id)); } @GetMapping("{id}") public R getById(@PathVariable Integer id){ return new R(true,userService.getById(id)); } @GetMapping("{currentPage}/{pageSize}") public R getPage(@PathVariable int currentPage, @PathVariable int pageSize){ return new R(true,userService.getPage(currentPage,pageSize)); }}