2013-06-21 94 views
0

我正在嘗試與此請求處理程序進行交談(對於糟糕的語言抱歉,我是全新的春天,我認爲這就是它的名稱)。我環顧四周,看到將日誌記錄級別設置爲DEBUG的建議,我跟我們的負責人談了這件事,他問我不花時間。我正在用盡想法,我已經搜索了很多堆棧溢出,並且似乎無法找到我的方式。Spring MVC - 請求語法不正確

這裏是我的控制器:

@RequestMapping(value={"/project/save", "/project/add", "/project/edit"}, method=RequestMethod.POST) 
public ModelAndView saveProject(@ModelAttribute ProjectForm form) { 
    ModelAndView mav = this.createBaseModelAndView("project/start"); 
    ModelAndView redirect = new ModelAndView("redirect:/admin/projects"); 
    return this.projectUtils.saveProject(form, mav, redirect); 
} 

在請求發送這些增值經銷商:

projectId:   51c4619c036492494eca2740 
vendorId:   5113babc0364a6e3eb6aa368 
name:    Cedar Goodies 
description:  ldfkj 
url:    http://caseywise.com 
openDate:   06/22/2013 12:00 AM 
closeDate:   06/26/2013 12:00 AM 
organizerId:  517da4b92e3a896d9c613b2e 
allowIndividualShipping: false 
allowIndividualPayments: false 
allowOrderEditing:   false 
items[0]:   51c461a9036492494eca2741 

而且這些請求頭

Accept:  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Encoding: gzip,deflate,sdch 
Accept-Language: en-US,en;q=0.8 
Cache-Control: no-cache 
Connection:  keep-alive 
Content-Length: 366 
Content-Type: application/x-www-form-urlencoded 
Cookie:  JSESSIONID=6eebd82250b5429bfd8bb5f82e42 
Host:  localhost:8080 
Origin:  http://localhost:8080 
Pragma:  no-cache 
Referer:  http://localhost:8080/admin/project/start 
User-Agent:  Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 

的ProjectForm對象(從該saveProject方法控制器)想要這些屬性

private String projectId; 
private String name; 
private String description; 
private Date openDate; 
private Date closeDate; 
private String organizerId; 
private List<String> items; // hidden inputs for form submission, since we can't send an object through a form 
private String url; 
private boolean allowOrderEditing; 
private boolean allowIndividualPayments; 
private boolean allowIndividualShipping; 
private String vendorId; 

我回來了400 - The request sent by the client was syntactically incorrect()。你看到任何明顯的錯誤?你想看更多的代碼嗎?有任何想法嗎?


編輯

包括每個帕維爾的評論的ProjectForm對象:


package com.ordercollector.viewmodels.project; 

import com.ordercollector.controllers.utils.ControllerUtils; 
import com.ordercollector.entities.ProjectItem; 
import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import java.util.List; 
import org.apache.http.impl.cookie.DateParseException; 
import org.apache.http.impl.cookie.DateUtils; 
import org.jboss.logging.Logger; 

/** 
* 
* @author jables 
*/ 
public class ProjectForm { 
    private String projectId; 
    private String name; 
    private String description; 
    private Date openDate; 
    private Date closeDate; 
    private String organizerId; 
    private List<String> items; // hidden inputs for form submission, since we can't send an object through a form 
    private String url; 
    private boolean allowOrderEditing; 
    private boolean allowIndividualPayments; 
    private boolean allowIndividualShipping; 
    private String vendorId; 

    /** 
    * @return the name 
    */ 
    public String getName() { 
     return name; 
    } 

    /** 
    * @param name the name to set 
    */ 
    public void setName(String name) { 
     this.name = name; 
    } 

    /** 
    * @return the description 
    */ 
    public String getDescription() { 
     return description; 
    } 

    /** 
    * @param description the description to set 
    */ 
    public void setDescription(String description) { 
     this.description = description; 
    } 

    /** 
    * @return the openDate 
    */ 
    public Date getOpenDate() { 
     return openDate; 
    } 

    public String getOpenDateFormatted() { 
     return ProjectForm.formatDateAsString(openDate); 
    } 

    /** 
    * @param openDate the openDate to set 
    */ 
    public void setOpenDate(Date openDate) { 
     this.openDate = openDate; 
    } 

    /** 
    * @return the closeDate 
    */ 
    public Date getCloseDate() { 
     return closeDate; 
    } 

    /** 
    * Returns the project's close date in a formatted string. If the close 
    * date has not been set, an empty string is returned. 
    * @return String 
    */ 
    public String getCloseDateFormatted() { 
     return ProjectForm.formatDateAsString(closeDate); 
    } 

    /** 
    * @param closeDate the closeDate to set 
    */ 
    public void setCloseDate(Date closeDate) { 
     this.closeDate = closeDate; 
    } 

    /** 
    * @return the organizerId 
    */ 
    public String getOrganizerId() { 
     return organizerId; 
    } 

    /** 
    * @param organizerId the organizerId to set 
    */ 
    public void setOrganizerId(String organizerId) { 
     this.organizerId = organizerId; 
    } 

    /** 
    * @return the item 
    */ 
    public List<String> getItems() { 
     return items; 
    } 

    /** 
    * @param item the item to set 
    */ 
    public void setItems(List<String> items) { 
     this.items = items; 
    } 

    /** 
    * @return the url 
    */ 
    public String getUrl() { 
     return url; 
    } 

    /** 
    * @param url the url to set 
    */ 
    public void setUrl(String url) { 
     this.url = url; 
    } 

    /** 
    * @return the projectId 
    */ 
    public String getProjectId() { 
     return projectId; 
    } 

    /** 
    * @param projectId the projectId to set 
    */ 
    public void setProjectId(String projectId) { 
     this.projectId = projectId; 
    } 

    /** 
    * @return the allowOrderEditing 
    */ 
    public boolean getAllowOrderEditing() { 
     return allowOrderEditing; 
    } 

    /** 
    * @param allowOrderEditing the allowOrderEditing to set 
    */ 
    public void setAllowOrderEditing(boolean allowOrderEditing) { 
     this.allowOrderEditing = allowOrderEditing; 
    } 

    /** 
    * @return the allowIndividualPayments 
    */ 
    public boolean getAllowIndividualPayments() { 
     return allowIndividualPayments; 
    } 

    /** 
    * @param allowIndividualPayments the allowIndividualPayments to set 
    */ 
    public void setAllowIndividualPayments(boolean allowIndividualPayments) { 
     this.allowIndividualPayments = allowIndividualPayments; 
    } 

    /** 
    * @return the allowIndividualShipping 
    */ 
    public boolean getAllowIndividualShipping() { 
     return allowIndividualShipping; 
    } 

    /** 
    * @param allowIndividualShipping the allowIndividualShipping to set 
    */ 
    public void setAllowIndividualShipping(boolean allowIndividualShipping) { 
     this.allowIndividualShipping = allowIndividualShipping; 
    } 

    /** 
    * Returns the given date in the format used by the form. If date object 
    * is null, an empty string is returned. 
    * @param date 
    * @return String 
    */ 
    public static String formatDateAsString(Date date) { 
     if (null == date) 
     { 
      return new String(""); 
     } 
     else 
     { 
      DateFormat df = new SimpleDateFormat("MM/dd/yyyy h:mm a"); 
      return df.format(date); 
     } 
    } 

    /** 
    * @return the vendorId 
    */ 
    public String getVendorId() { 
     return vendorId; 
    } 

    /** 
    * @param vendorId the vendorId to set 
    */ 
    public void setVendorId(String vendorId) { 
     this.vendorId = vendorId; 
    } 
} 
+0

你可以試着改變saveProject'的'簽名有隻是一個單一的'@ RequestParam'說法只是爲了看看是否會導致請求被映射到那裏。 – david

+0

你的客戶是什麼? HTML/JSP頁面還是獨立休息客戶端? –

+0

嘗試刪除商品[0]:51c461a9036492494eca2741,只是爲了檢查。通常,列表會導致彈簧mvc – renanlf

回答

3

Spring缺省(3版)使用DateTimeFormatAnnotationFormatterFactoryDate場結合。

模型中的對象你Date字段或getter方法必須用正確的@DateTimeFormat的註解:

@DateTimeFormat(pattern="MM/dd/yyyy hh:mm a") 
public Date getCloseDate() { 
    return closeDate; 
} 
+0

感謝您的注意。我不知道如何使用日期字段綁定的註釋,非常整潔!要看看現在是否能正常工作。 – fusion27

相關問題