Java Spring MVC 415过帐表单时出错

Java Spring MVC 415过帐表单时出错,java,spring,model-view-controller,web,Java,Spring,Model View Controller,Web,执行POST请求时出现415错误。 这是我的表格: <c:url value="/createOrUpdate" var="actionUrl"/> <form action="${actionUrl}" method="post" enctype="application/x-www-form-urlencoded"> <table class="editor silver"> <tr> <th c

执行POST请求时出现415错误。 这是我的表格:

<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>
广告是一个简单的POJO,包含getter和setter:

private long id;

private String owner;

private Date publicationDate;

private String rubric;

private String header;

private String text;
我做错了什么? p、 据我所知,spring应该将“名称字段”映射到POJO的字段中。对吗?
添加了好的,我发现有些值没有以表单形式发送。我在浏览器中检查了控制台,现在一切正常,但仍然出现415错误。

问题在于日期转换。 将
@RequestBody更改为@MadelAttribute
,并将
@DateTimeFormat(iso=DateTimeFormat.iso.DATE)
私人日期公布日期

对于模型,问题在于日期转换。 将
@RequestBody更改为@MadelAttribute
,并将
@DateTimeFormat(iso=DateTimeFormat.iso.DATE)
私人日期公布日期

对于模型

可以使用
@modeldattribute
而不是
@RequestBody
。RequestBody使用json、xml。删除application/x-www-form-urlencoded,因为它已经是默认类型

如果您想使用
@Requestbody
,那么您可以使用JQuery之类的JavaScript库将表单数据发布为json,发布内容类型为application/json的json数据。并使用jacksonlib轻松地将json转换为java对象

400-请求错误


问题可能是发送日期。关注如何发送日期spring mvc。您可以使用
@DateTimeFormat
@InıtBinder
您可以使用
@modeldattribute
而不是
@RequestBody
。RequestBody使用json、xml。删除application/x-www-form-urlencoded,因为它已经是默认类型

如果您想使用
@Requestbody
,那么您可以使用JQuery之类的JavaScript库将表单数据发布为json,发布内容类型为application/json的json数据。并使用jacksonlib轻松地将json转换为java对象

400-请求错误


问题可能是发送日期。关注如何发送日期spring mvc。您可以在ıtBinder中使用
@DateTimeFormat

您可以使用ModelAttribute而不是RequestBody。RequestBody使用json、xml。删除application/x-www-form-urlencoded,因为它已经是默认类型。如果您想使用@requestbody,那么可以使用JQuery之类的JavaScript库将表单数据发布为json,发布内容类型为application/json的json数据。使用jackson lib可以轻松地将json转换为java对象。但是现在我得到了错误400-错误请求问题可能是发送日期。关注如何发送日期spring mvc。您可以使用DateTimeFormat或Inıtbinder是的,它很有效。非常感谢。您可以使用ModelAttribute而不是RequestBody。RequestBody使用json、xml。删除application/x-www-form-urlencoded,因为它已经是默认类型。如果您想使用@requestbody,那么可以使用JQuery之类的JavaScript库将表单数据发布为json,发布内容类型为application/json的json数据。使用jackson lib可以轻松地将json转换为java对象。但是现在我得到了错误400-错误请求问题可能是发送日期。关注如何发送日期spring mvc。您可以使用DateTimeFormat或Inıtbinder是的,它很有效。非常感谢。
private long id;

private String owner;

private Date publicationDate;

private String rubric;

private String header;

private String text;