共计 1493 个字符,预计需要花费 4 分钟才能阅读完成。
package com.guigu.liujie.controller;
import com.guigu.liujie.pojo.User;
import com.guigu.liujie.service.UserService;
import com.guigu.liujie.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @ClassName UserController
* @Description TODO
* @Author liujie
* @Date 2021/6/15 16:19
* @Version 1.0
**/
@RestController
@RequestMapping("user")
public class UserController {
@Autowired
public UserService userService;
/**
* 用户新增
* @param user
* @return
*/
@PostMapping()
public Object userAdd(@RequestBody User user){boolean isAdd = userService.userAdd(user);
if(!isAdd){return new Result(isAdd,"新增失败");
}
return new Result([PerfectMoney 下载](https://www.gendan5.com/wallet/PerfectMoney.html)isAdd,"新增胜利");
}
/**
* 依据 id 删除
* @param id
* @return
*/
@DeleteMapping(value = "{id}")
public Object userDel(@PathVariable Integer id){boolean flag = userService.userDel(id);
if(!flag){return new Result(flag,"删除失败");
}
return new Result(flag,"删除胜利");
}
/**
* 依据以后用户 id 进行批改
* @param user
* @return
*/
@PutMapping()
public Object userUpd(@RequestBody User user){boolean flag = userService.userUpd(user);
if(!flag){return new Result(flag,"批改失败");
}
return new Result(flag,"批改胜利");
}
/**
* 查问所有用户信息
* @return
*/
@GetMapping()
public Object findAll(){List<User> userList = userService.findAll();
return new Result("查问所有胜利",userList);
}
/**
* 依据 id 查看详情
* @param id
* @return
*/
@GetMapping(value = "{id}")
public Object findById(@PathVariable Integer id){User user = userService.findById(id);
if(user!=null){return new Result("查看详情胜利",user);
}
return new Result("查看详情失败",user);
}
}
正文完