title: Spring MVC - Why not able to use @RequestBody and @RequestParam together
body: <p>Using HTTP dev client with Post request and Content-Type application/x-www-form-urlencoded</p>
  <h3>1) Only @RequestBody</h3>
  <p>URL: localhost:8080/SpringMVC/welcome<br />
  Body: name=abc</p>
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String printWelcome(@RequestBody String body, Model model) {
      model.addAttribute(&quot;message&quot;, body);
      return &quot;hello&quot;;
  }
  // Gives body as 'name=abc' as expected
  </code></pre>
  <h3>2) Only @RequestParam</h3>
  <p>URL: localhost:8080/SpringMVC/welcome<br />
  In Body - name=abc</p>
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String printWelcome(@RequestParam String name, Model model) {
      model.addAttribute(&quot;name&quot;, name);
      return &quot;hello&quot;;
  }
  // Gives name as 'abc' as expected
  </code></pre>
  <h3>3) Both together</h3>
  <p>URL: localhost:8080/SpringMVC/welcome<br />
  Body: name=abc</p>
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String printWelcome(
      @RequestBody String body, 
      @RequestParam String name, Model model) 
  {
      model.addAttribute(&quot;name&quot;, name);
      model.addAttribute(&quot;message&quot;, body);
      return &quot;hello&quot;;
  }
  // HTTP Error Code 400 - The request sent by the client was syntactically incorrect.
  </code></pre>
  <h3>4) Above with params position changed</h3>
  <p>URL: localhost:8080/SpringMVC/welcome<br />
  Body: name=abc</p>
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String printWelcome(
      @RequestParam String name, 
      @RequestBody String body, Model model) 
  {
      model.addAttribute(&quot;name&quot;, name);
      model.addAttribute(&quot;message&quot;, body);
      return &quot;hello&quot;;
  }
  // No Error. Name  is 'abc'. body is empty
  </code></pre>
  <h3>5) Together but get type url parameters</h3>
  <p>URL: localhost:8080/SpringMVC/welcome?name=xyz<br />
  Body: name=abc</p>
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String printWelcome(
      @RequestBody String body, 
      @RequestParam String name, Model model) 
  {
      model.addAttribute(&quot;name&quot;, name);
      model.addAttribute(&quot;message&quot;, body);
      return &quot;hello&quot;;
  }
  // name is 'xyz' and body is 'name=abc'
  </code></pre>
  <h3>6) Same as 5) but with parameters position changed</h3>
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  public String printWelcome(
      @RequestParam String name, 
      @RequestBody String body, Model model) 
  {
      model.addAttribute(&quot;name&quot;, name);
      model.addAttribute(&quot;message&quot;, body);
      return &quot;hello&quot;;
  }
  // name = 'xyz,abc' body is empty
  </code></pre>
  <p>Can someone explain this behaviour?</p>