2013-06-21 48 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

相关问题