WEB module correlation

  • Spring-boot-starter: Core module, including auto-configuration support, logging, and YAML
  • Spring-boot-starter-test: test module, including JUnit, Hamcrest, and Mockito
  • spring-boot-starter-web

Commonly used annotations

  • @requestMapping = Handles annotations for address mapping

  • @pathVariable = is used to retrieve dynamic parameters in the request path (URL)

    1. The sample
        / * * *@RequestMapping(value = "user/login / {id} / {name} / {status}") in the {id} / {name} / {status} * with@PathVariableInt id,@PathVariableString name,@PathVariableBoolean status * One-to-one, matching by name. * /
    
        @RequestMapping(value = "user/login/{id}/{name}/{status}")
        @ResponseBody
        // All data types under the @pathVariable annotation are available
        public User login(@PathVariable int id, @PathVariable String name, @PathVariable boolean status) {
        // Returns a User object in response to an Ajax request
            return new User(id, name, status);
        }
    Copy the code
  • ResponseBody => Parse the client request data into JSONG data or XML format and return it to the HTTP ResponseBody (the data required by the client).

  • @ is configured in the Controller = “spring MVC view, annotations can be here to return to the JSP page, redirect, cooperate with @ ResponseBody can return to the page needed data, such as json.

  • @restController => @restController annotation is equivalent to @responseBody +@Controller combined. But if you only use the @RestController annotation Controller, the methods in Controller cannot return a JSP page. The @restcontroller annotation is more appropriate for restfulApi projects.

  • @reaustparam => You can use this annotation binding when the parameter name passed to the page is inconsistent with the method parameter name.

  • @requestBodey => writes ajax (datas) requests to the User object.

  • Composite annotations (updated version of RequestMapping)

    1. @GetMapping = @RequestMapping(method = RequestMethod.GET)
    2. @PostMapping = @RequestMapping(method = RequestMethod.POST)
    3. @PutMapping = @RequestMapping(method = RequestMethod.PUT)
    4. @DeleteMapping = @RequestMapping(method = RequestMethod.DELETE)
    Composite annotations are method-level and can only be used on methods, so our examples mostly use composite annotations.