samedi 1 avril 2017

Spring MVC 415 error when posting form

Getting 415 error when doing POST request. This is my form:

<c:url value="/createOrUpdate" var="actionUrl"/>
  <form  action="${actionUrl}" method="post" enctype="application/x-www-form-urlencoded">
    <table class="editor silver">
      <tr>
        <th colspan="2">Edit advert details</th>
        <input type="number" hidden value="${advert.id}" name="id"/>
      </tr>
      <tr>
        <td>Owner:</td>
        <td>
          <input type="text" disabled value="${advert.owner}" name="owner"/>
        </td>
      </tr>
      <tr>
        <td>Publication date:</td>
        <td>
          <input type="datetime" disabled value="${advert.publicationDate}" name="publicationDate"/>
        </td>
      </tr>
      <tr>
        <td>Select rubric</td>
        <td>
          <select name="rubric">
            <option value="sale" selected>Sale</option>
            <option value="buy">Buy</option>
            <option value="lease">Lease</option>
            <option value="services">Services</option>
            <option value="dating">Dating</option>
          </select>
        </td>
      </tr>
      <tr>
        <td>Enter header:</td>
        <td>
          <input type="text" value="${advert.header}" name="header"/>
        </td>
      </tr>
      <tr>
        <td>Enter text:</td>
        <td>
          <input type="text" value="${advert.text}" name="text"/>
        </td>
      </tr>

And this is controller where i'm doing request

@RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ModelAndView editAdvert(@RequestBody Advert advert) {//some actions

Advert is a simple POJO with getters and setters:

private long id;

private String owner;

private Date publicationDate;

private String rubric;

private String header;

private String text;

What i'm doing wrong? p.s. As i understand spring should map that 'name-fields' into fields of POJO. Right?




Aucun commentaire:

Enregistrer un commentaire