1. Common interface request types:

Common interfaces include the following four types: interface containing query parameters, interface of form type, interface of JSON type, and interface containing upload file.

1.1 Contains query parameters

1.2 Form type

1.3 The value is json

1.4 Contains uploaded files

2. @ RequestParam, @ RequestBody

2.1 @ RequestParam

RequestParam is primarily used to map the data in the request parameter area to the parameters of the control layer method. RequestParam is used to process Content whose content-type is Application/X-www-form-urlencoded. Content-type is the default. RequestParam can also be used for other types of requests such as POST, DELETE, and so on. \

2.2 @ RequestBody

The @requestbody annotation accepts parameters from the RequestBody, which is the RequestBody. Generally, it is used to process data in non-content-type: Application/X-www-form-urlencoded format, such as Application/JSON, Application/XML, etc.

Typically the backend will have a parameter entity class with the @RequestBody annotation to receive data for application/ JSON request types. If the request is of application/ JSON type and the corresponding entity class is not annotated with @requestBody, the parameters will not be received. \

2.3 case



(1) The request body in the application/ JSON type body of a POST request can exist at the same time as the parameter spelled after the URL:




The back-end interface receives data as follows:

	@PostMapping("updateTableDataDL")
    public AjaxResult updateTableDataDL(@RequestBody List<TableDataParam> dataParamList, String rowGuid) {
        int result = 0;
        try {
            result = reportTableService.updateTableDataDL(dataParamList, rowGuid);
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        return toAjax(result);
    }
Copy the code



(2) The file upload request carries other parameters of the form




The back-end interface receives data as follows:

	@PostMapping("/add")
    public AjaxResult addcar(TzCar tzCar, HttpServletRequest request) {
        // Return the rowGuid of the vehicle
        int result = 0;
        try {
            result = tzCarService.insertTzCar(tzCar, request);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return AjaxResult.error(e.getMessage());
        }
        return toAjax(result);
    }
Copy the code

The TzCar is the parameter entity class encapsulated by the other parameters of the form. The two files, file1 and file2, are received in the HttpServletRequest. Specific parsing can see here multiple file upload + form data request before and after the processing