Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring REST 400错误请求,带有x-www-urlformencoded POST,将正文发送到@ModelAttribute域对象_Spring_Rest_Exception_Postman_Http Status Code 400 - Fatal编程技术网

Spring REST 400错误请求,带有x-www-urlformencoded POST,将正文发送到@ModelAttribute域对象

Spring REST 400错误请求,带有x-www-urlformencoded POST,将正文发送到@ModelAttribute域对象,spring,rest,exception,postman,http-status-code-400,Spring,Rest,Exception,Postman,Http Status Code 400,嗨,我伸出手希望我忽略了一些琐碎的事情。我看这里的url编码帖子没有任何问题。我无法获得400错误请求异常消息的详细信息,尽管我试图捕获它。它可能是我在处理程序中没有映射到的类 无论如何,这适用于普通的应用程序/json post,但在通过url编码发布时存在问题。我甚至没有到达我的控制器,因此我相当确定,当涉及url编码时,这是一个绑定到我的示例实体的问题。当我使用application/json使用@RequestBody和post时,它绑定良好,但当通过urlencoding发布时,它与@

嗨,我伸出手希望我忽略了一些琐碎的事情。我看这里的url编码帖子没有任何问题。我无法获得400错误请求异常消息的详细信息,尽管我试图捕获它。它可能是我在处理程序中没有映射到的类

无论如何,这适用于普通的应用程序/json post,但在通过url编码发布时存在问题。我甚至没有到达我的控制器,因此我相当确定,当涉及url编码时,这是一个绑定到我的示例实体的问题。当我使用application/json使用@RequestBody和post时,它绑定良好,但当通过urlencoding发布时,它与@modeldattribute有问题。我的身体有什么问题吗

批量编辑文本

用于x-www-formurlencoded POST的控制器方法

SampleEntity(同样,这适用于应用程序/json POST)

非常感谢您的帮助。谢谢

试试看


必须将BindingResult添加到我的参数中才能发现问题。这样做之后,我很明显ModelAttribute无法从我的文章中绑定日期字符串并将其转换为java.util.Date。需要将InitBinding自定义转换器添加到我的控制器类。

感谢您的回复。这不起作用。当我用MultiValueMap替换RequestBody的ModelAttribute时,它与x-www-urlencoded body post一起工作。不知道为什么这篇文章不能与ModelAttribute一起使用。我的许多其他帖子在ModelAttribute方面没有其他问题。这是关于这篇文章中ModelAttribute无法处理的特定数据的吗?最后找出这个问题。公共潜在客户保存(@Valid@modeldattribute final Lead entity,BindingResult BindingResult)@InitBinder public void InitBinder(WebDataBinder WebDataBinder){SimpleDateFormat sdf=new SimpleDateFormat(“yyyy-MM-dd”);WebDataBinder.registerCustomEditor(Date.class,new CustomDateEditor(sdf,true));}
firstName:JohnTest
lastName:Stafford
birthDate:1990-08-07
driversLicenseNumber:080005900
address:1700NW36thTerraceYukonOklahoma
zip:73099
email:john.charles.stafford@gmail.com
homePhone:4055506800
workPhone:4055506800
amount:300
employer:meMyselfAndI
activeMilitary:0
incomeType:EMPLOYMENT
monthlyIncome:12000
date1:2016-12-02
date2:2016-12-16
frequency:TWICEMONTHLY
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public Lead save(@Valid @ModelAttribute("entity") final SampleEntity entity)   
{
    return createInternal(entity);
}
@Entity
@Table(name="sample_table")
public class SampleEntity implements IBaseEntity{

/**
 * 
 */
private static final long serialVersionUID = -1110216193971231355L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;

@Column(name = "first_name")
@NotNull
private String firstName;

@Column(name = "last_name")
@NotNull
private String lastName;

@Column(name = "birth_date")
@NotNull
private String birthDate;

@Column(name = "drivers_license_number")
@NotNull
private String driversLicenseNumber;

@Column
@NotNull
private String address;

@Column
@NotNull
private String zip;

@Column
@NotNull
private String email;

@Column(name = "home_phone")
@NotNull
private String homePhone;

@Column(name = "work_phone")
@NotNull
private String workPhone;

@Column(name = "requested_amount")
@NotNull
private String requestedAmount;

@Column
@NotNull
private String employer;

@Column(name = "active_military")
@NotNull
private String activeMilitary;

@Column(name = "income_type")
@NotNull
private String incomeType;

@Column(name = "monthly_income")
@NotNull
private String monthlyIncome;

@Column
@Temporal(TemporalType.DATE)
@NotNull
private Date date1;

@Column
@Temporal(TemporalType.DATE)
@NotNull
private Date date2;

@Column(name = "frequency")
@NotNull
private String frequency;

//getters and setters
@RequestMapping( method = RequestMethod.POST, consumes = {"application/x-www-form-urlencoded", "application/json"})