springboot:spring_form_input_from_httpservletrequest

Spring Form Input From HttpServletRequest

From those who do not like what Spring automatically bind the form input to an object, we can do it ourselves by using HttpServletRequest.

  1. In your controller, import javax.servlet.http.HttpServletRequest
  2. In your method add HttpServletRequest as a parameter, Spring will give the value to you.
  3. Now you can use request.getParameter(…) to get field value or request.getParameterValues(…) to get array value. Note all value are in type String. You need to do your own conversion if needed.
  • springboot/spring_form_input_from_httpservletrequest.txt
  • Last modified: 2020/05/26 12:30
  • by chongtin