欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

表现层消息一致性,前后端数据协议

时间:2023-07-06

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)); }}

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。