How does Spring MVC convert @RequestParam values?

前端 未结 1 1960
北海茫月
北海茫月 2021-02-19 22:24

I\'m new to the Spring Framework, and as a symptom, I want to keep my adoption of its Web MVC portions as simple as possible, so I\'m using the annotation functions to work with

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-19 22:39

    I've noticed that when I use Spring's terminology: @RequestParameter("numberValue") int numVal the conversion is handled automatically.

    Here you are looking for Type Conversion

    As per spring documentation given on this link

    String-based values extracted from the request including request parameters, path variables, request headers, and cookie values may need to be converted to the target type of the method parameter or field (e.g., binding a request parameter to a field in an @ModelAttribute parameter) they’re bound to. If the target type is not String, Spring automatically converts to the appropriate type. All simple types such as int, long, Date, etc. are supported.

    0 讨论(0)
提交回复
热议问题