尝试提交我的表单以创建新的拍卖时,此错误出现在浏览器中:

Whitelabel错误页面:

此应用程序没有/error的显式映射,因此您正在看到
作为后备。

2017年3月30日星期四21:00:15 BST
发生意外错误(类型=错误的请求,状态= 400)
对object ='auctionItem'的验证失败。错误计数:2

我似乎无法在日志中找到任何特定的错误,因此无法找到错误页面上显示的两个验证错误。在这一点上我很迷茫。希望有人可以帮助我,这阻止了我目前的进步。

JSP文件:

<body id="product" class="product">
    <header>
            <%@include file="../jsp/Header.jsp" %>
    </header>
    <div>
        <div class="container">
            <div class ="row">
                <div class="center_column">
                    <h2 style=" ">Create New Listing</h2>
                    <mvc:form class="form-inline" action="sell" method="post" modelAttribute="newAuction" id="addNewAuc">
                        <div class="form-inline" cssClass="TitleBlock">
                            <label class="control-label">Title</label>
                            <div>
                                <mvc:input path="aTitle" type="text" required="true" cssClass="Title" class="form-control" placeholder="Please enter title of item" maxlength="55" minlength="40"/>
                            </div>
                        </div>

                        <div class="form-group ">
                            <label class="control-label">Item Condition</label>
                            <div style="padding-top: 4px;">
                                <mvc:select path="aCondition">
                                    <mvc:option value="New">New</mvc:option>
                                    <mvc:option value="Used">Used</mvc:option>
                                </mvc:select>
                            </div>
                        </div>
                        <div class="form-group ">
                            <label class="control-label" style = "padding-left: 15px;">Can the item be returned?</label>
                            <div style="padding-top: 4px; padding-left: 15px;">
                                <mvc:select path="aReturns">
                                    <mvc:option value="You can return">Yes</mvc:option>
                                    <mvc:option value="Seller does not offer returns">No</mvc:option>
                                </mvc:select>
                            </div>
                        </div>
                        <div class="form-inline">
                            <label class="control-label">Description</label>
                            <div>
                                <mvc:textarea path="aDescription" required="true" cssClass="Desc" class="form-control" rows="3" name="Description" placeholder="Item description"/>
                            </div>
                        </div>

                        <div class="form-inline">
                            <label class="control-label">Category</label>
                            <div style="padding-top: 4px;">
                                <mvc:select path="categories">
                                    <mvc:option value="category1">Electronics</mvc:option>
                                    <mvc:option value="category2">Fashion</mvc:option>
                                    <mvc:option value="category3">Home & Gardens</mvc:option>
                                    <mvc:option value="category4">Toys & Games</mvc:option>
                                    <mvc:option value="category5">Sports & Leisure</mvc:option>
                                </mvc:select>
                            </div>
                        </div>
                        <div class="form-inline">
                            <label class="control-label ">Minimum Price</label>
                            <div style="padding-top: 4px;">
                                <mvc:input path="aBottomPrice" type="number" step="any" required="true" class="form-control" placeholder="?"/>
                            </div>
                        </div>
                        <div class="form-inline">
                            <label class="control-label ">Starting Price</label>
                            <div style="padding-top: 4px;">
                                <mvc:input path="aTopPrice" type="number" step="any" required="true" class="form-control" placeholder="?"/>
                            </div>
                        </div>
                        <div class="form-inline">
                            <label class="control-label">End of listing</label>
                            <div style="padding-top: 4px;">
                                <mvc:input path="aEnd" type="text" id="datetimepicker" required="true" class="form-control" placeholder="YYYY-MM-DD"/>
                            </div>
                        </div>

                    </mvc:form>
                    <div class="form-inline">
                        <div style="padding-top: 10px;">
                            <button type="submit" name="submit" class="btn btn-success" form="addNewAuc">Next</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

AuctionItem类
@Entity
@Table(name = "auction_items")
public class AuctionItem {


 @Id
 @GeneratedValue(strategy = GenerationType.IDENTITY)
 private int idauction;

 @Column(name = "auctionTitle")
 private String aTitle;

 @Column(name = "auctionDescription")
 private String aDescription;

 @Column(name = "auctionStatus")
 private String aStatus;

 @Column(name = "auctionStart")
 private Date aStart;

 @Column(name = "auctionEnd")
 private Date aEnd;

 private String endTimeAsString;

 @Column(name = "auctionCondition")
 private String aCondition;

 @Column(name = "auctionTopPrice")
 private double aTopPrice;

 @Column(name = "auctionBottomPrice")
 private double aBottomPrice;

 private long auctionDuration;

 private String aReturns;

 @ManyToOne
 @JoinColumn(name = "owner")
 private User owner;

 @ManyToOne
 @JoinColumn(name = "cId")
 private Category categories;




 public long getAuctionDuration() {
  return auctionDuration;
 }

 public void setAuctionDuration(long auctionDuration) {
  this.auctionDuration = auctionDuration;
 }

 public int getaID() {
  return idauction;
 }

 public void setaID(int idauction) {
  this.idauction = idauction;
 }

 public String getaTitle() {
  return aTitle;
 }

 public void setaTitle(String aTitle) {
  this.aTitle = aTitle;
 }

 public String getaDescription() {
  return aDescription;
 }

 public void setaDescription(String aDescription) {
  this.aDescription = aDescription;
 }

 public String getaStatus() {
  return aStatus;
 }

 public void setaStatus(String aStatus) {
  this.aStatus = aStatus;
 }

 public Date getaStart() {
  return aStart;
 }

 public void setaStart(Date aStart) {
  this.aStart = aStart;
 }

 public Date getaEnd() {
  return aEnd;
 }

 public void setaEnd(Date aEnd) {
  this.aEnd = aEnd;
 }

 public String getaCondition() {
  return aCondition;
 }

 public void setaCondition(String aCondition) {
  this.aCondition = aCondition;
 }

 public double getaTopPrice() {
  return aTopPrice;
 }

 public void setaTopPrice(double aTopPrice) {
  this.aTopPrice = aTopPrice;
 }

 public double getaBottomPrice() {
  return aBottomPrice;
 }

 public void setaBottomPrice(double aBottomPrice) {
  this.aBottomPrice = aBottomPrice;
 }

 public User getOwner() {
  return owner;
 }

 public void setOwner(User owner) {
  this.owner = owner;
 }

 public String getaReturns() {
  return aReturns;
 }

 public void setaReturns(String aReturns) {
  this.aReturns = aReturns;
 }

 public Category getCategories() {
  return categories;
 }

 public void setCategories(Category categories) {
  this.categories = categories;
 }

 public String getEndTimeAsString() {
  return endTimeAsString;
 }

 public void setEndTimeAsString(String EndTimeAsString) {
  this.endTimeAsString = EndTimeAsString;
 }

}

最佳答案

也许您错过了Controller中的“BindingResult”。
例:

import org.springframework.validation.BindingResult;

@RequestMapping(value = "/registration", method = RequestMethod.POST)
public String registration(
    @ModelAttribute("userlogin") @Valid LoginProfile userlogin,
    BindingResult userloginResult)

10-06 14:02