title: Spring ajax 400 (Bad Request)
body: <p>I try develop simple ajax application. But when I Send data, I see in chrome console.</p>
  
  <pre><code>Clicked! create.js:12
  Object {name: "df", description: "fd", price: "2", accessible: "on"} create.js:13
  ERROR: POST http://localhost:8080/cqrsSpring/create 400 (Bad Request) 
  </code></pre>
  
  <p><strong>Page:</strong></p>
  
  <pre><code>    &lt;%@ page contentType="text/html;charset=UTF-8" language="java" %&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="${pageContext.request.contextPath}/js/create.js"&gt;&lt;/script&gt;
      &lt;title&gt;Create Product&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;label&gt;Name&lt;/label&gt;
      &lt;input id="name"&gt;
  
      &lt;label&gt;Price&lt;/label&gt;
      &lt;input id="price" type="number"&gt;
  
      &lt;label&gt;Description&lt;/label&gt;
      &lt;input id="description"&gt;
  
      &lt;label&gt;Accesible&lt;/label&gt;
      &lt;input id="accessible" type="checkbox"&gt;
  
      &lt;button id="send"&gt;Send&lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Script</strong></p>
  
  <pre><code>    $(document).ready(function () {
  
      $("#send").click(function () {
  
          var form = {
              name: $("#name").val(),
              description: $("#description").val(),
              price: $("#price").val(),
              accessible: $("#accessible").val()
          }
  
          console.info("Clicked!");
          console.info(form);
          $.ajax({
              url: "create",
              type: "POST",
              dataType: "json",
              contentType: "application/json",
              data: JSON.stringify(form),
              success: function (d) {
                  console.info("Success!");
              }
          })
  
      })
  })
  </code></pre>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>   @RequestMapping(value = "/create", method = RequestMethod.POST, consumes = "application/json")
      public ModelAndView recCreate(@RequestBody CreateProduct product, BindingResult result) {
  
          if (result.hasErrors())
              return new ModelAndView("createProduct");
  
          logger.info("Command recived " + product.toString());
          bus.post(product);
  
  
          return new ModelAndView("hello", "message", "Product " + product.getName() + " received!");
      }
  </code></pre>
  
  <p><strong>Command Object</strong></p>
  
  <pre><code>public final class CreateProduct {
  
  @NotNull
  @NotBlank
  private String name;
  
  @NotBlank
  @NotNull
  private String description;
  
  @Min(0)
  private int price;
  
  private boolean accessible;
  
  public CreateProduct(int price, String name, boolean accessible, String description) {
      this.price = price;
      this.name = name;
      this.accessible = accessible;
      this.description = description;
  }
  
  @Override
  public String toString() {
      return "CreateProduct{" +
              "price=" + price +
              ", name='" + name + '\'' +
              ", accessible=" + accessible +
              ", description='" + description + '\'' +
              '}';
  }
  
  public int getPrice() {
      return price;
  }
  
  public String getName() {
      return name;
  }
  
  public boolean isAccessible() {
      return accessible;
  }
  
  public String getDescription() {
      return description;
  }
  
  //set
  public void setPrice(int price) {
      this.price = price;
  }
  
  public void setName(String name) {
      this.name = name;
  }
  
  public void setAccessible(boolean accessible) {
      this.accessible = accessible;
  }
  
  public void setDescription(String description) {
      this.description = description;
  }
  </code></pre>
  
  <p>}</p>