002 common notes of springboot

Time:2020-9-12

Controller receives parameters

  1. @PathVariableGet path parameters
    • @GetMapping("/{depid}/{userid}")
      • func(@PathVariable("depid") int dep_id){}
      • func(@PathVariable("userid") int user_id){}
  2. @RequestParamGet query parameters
    • http://www.baidu.com?name= Zhang San & age = 18
      • func(@RequestParam("name") String name){}
      • func(@RequestParam("age") int age){}
      • func(@RequestParam("head_img") MultipartFile file){}Picture upload
  3. @RequestBody
    • "{Name: 'Zhang San', age:20 }
      1. func(@RequestBody Map<String, String> person){}
      2. System.out.println(person.get("name"));
  4. @RequestHeaderGet request header
  5. @CookieValueGet cookie
  6. HttpServletRequest
    • func(HttpServletRequest request){ String name = request.getParameter("name"); }

exception handling

  • @ControllerAdvice
  • @RestControllerAdviceIf you want to return JSON data, you can use this instead of adding it@ResponseBody
  • @ExceptionHandler(value=Exception.class)Catch global exceptions and handle all unknowable exceptions

java

My brother is going to be a CTO in the future. How can these technologies not?

Recommended Today

How to share queues with hypertools 2.5

Share queue with swote To realize asynchronous IO between processes, the general idea is to use redis queue. Based on the development of swote, the queue can also be realized through high-performance shared memory table. Copy the code from the HTTP tutorial on swoole’s official website, and configure four worker processes to simulate multiple producers […]