Get请求时
return ResponseEntity.ok();
@GetMapping({"findAll"})
public ResponseEntity> findAll(@RequestParam(name = "admin", required = false) String admin, @RequestParam(name = "page", defaultValue = "https://www.it610.com/article/1") Integer page, @RequestParam(name = "rows", defaultValue = "https://www.it610.com/article/10") Integer rows) {
PageResult userPageResult = this.userService.findAll(admin, page, rows);
return ResponseEntity.ok(userPageResult);
}
【ResponseEntity的返回值用法】Post请求新增一条记录时,有返回值
return ResponseEntity.status(HttpStatus.CREATE).body();
()存放返回的内容
@PostMapping("save")
public ResponseEntity save(@RequestBody User user) throws Exception {
return ResponseEntity.status(HttpStatus.CREATED).body(this.userService.save(user));
}
Post请求新增一条记录时,无返回值
return new ResponseEntity(HttpStatus.CREATED);Delete删除请求,无返回
return new ResponseEntity(HttpStatus.NO_CONTENT);
@DeleteMapping({"delete"})
public ResponseEntity delete(@RequestParam(name = "ids") Integer[] ids) {
return ResponseEntity.ok(this.userService.delete(ids));
}
Put更新请求,无返回值
ResponseEntity.noContent().build();
@PutMapping({"update"})
public ResponseEntity update(@RequestBody User user) throws Exception {
return ResponseEntity.ok(this.userService.update(user));
}