Search code examples
springjspspring-mvcpojogetmethod

Why does @GetMapping method return request param while sending response?


I get request params as POJO and do nothing in method but in jsp shows parameter which I get from request.Why does method return my object? Additionally, when I use primitive type or String, It doesn't return object and works perfectly

Controller

@GetMapping("/ULD_details")
public String ULD_detailGet(ActionError ID){
return "ULD_detail";

JSP

 <tr>
    <td >ULD id</td>
    <td>${actionError.ID}</td>   
</tr>

Link

http://localhost:8080/UCM-controller/ULD_details?ID=1145

Solution

  • It doesn't return your object. It returns the String "ULD_detail", which is the name of the view to execute.

    This view is executed, and finds an actionError bean in the request attributes (i.e. in the model), because the Spring documentation about handler methods arguments says:

    Any other argument

    If a method argument is not matched to any of the above, by default it is resolved as an @RequestParam if it is a simple type, as determined by BeanUtils#isSimpleProperty, or as an @ModelAttribute otherwise.

    And the documentation of ModelAttribute says:

    The default model attribute name is inferred from the declared attribute type (i.e. the method parameter type or method return type), based on the non-qualified class name: e.g. "orderAddress" for class "mypackage.OrderAddress"