spring boot对表的增删查改

tech2022-12-19  97

对表的增删查改操作!

##RestController.java文件 @RequestMapping(“user”) public class UserController { @Autowired private UserService userService;

@Autowired private RedisService redisService; /** * 查询 * * @param id * @return */ @GetMapping("/queryById") public String queryById(int id) { //从redis获取key为Id User String userStr = redisService.get(id + ""); //判断是否存在 if (userStr != null) { //查询 设置到redis redisService.set(id + "", userService.queryById(id).toString()); } return userStr; } /** * 增 改 * @param user * @return */ @PostMapping("/saveOrUpdate") public User saveOrUpdateUser(User user) { return userService.save(user); } /** * 删除用户 * @param id * @return */ @DeleteMapping("/delete") public Boolean deleteUser(int id) { userService.deletUserById(id); return true; }

打开postman应用 输入对应的路径输出

最新回复(0)