【发布时间】:2017-04-23 05:00:30
【问题描述】:
嗨,我伸出手是希望我忽略了一些微不足道的事情。我认为此处的 url 编码帖子没有任何问题。尽管我试图抓住它,但我无法获得 400 Bad Request 异常消息的详细信息。它可能是我在处理程序中没有映射到的类。
无论如何,这适用于普通的 application/json 帖子,但在通过 url 编码发布时存在问题。我什至没有到达我的控制器,因此当涉及 url 编码时,我相当确定这是对我的示例实体的绑定问题。当我使用 @RequestBody 并使用 application/json 发布时,它绑定得很好,但在通过 urlencoding 发布时 @ModelAttribute 出现问题。对于 urlencoding 帖子,我的身体有什么问题?
批量编辑文本
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
用于 x-www-formurlencoded POST 的控制器方法
@RequestMapping(method = RequestMethod.POST)
@ResponseStatus(HttpStatus.CREATED)
@ResponseBody
public Lead save(@Valid @ModelAttribute("entity") final SampleEntity entity)
{
return createInternal(entity);
}
SampleEntity(同样,这适用于应用程序/json POST)
@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
非常感谢任何帮助。谢谢。
【问题讨论】:
标签: spring rest exception postman http-status-code-400