Reputation: 9765
@RequestMapping(value = "downloadFIReport.do", method = RequestMethod.POST)
public @ResponseBody String downloadFIBill(ModelMap model,@ModelAttribute("SpringWeb") FIReportSearchInput fiReportSearchInput)
{
//
}
Above is my controller code. I want to send FIReportSearchInput fiReportSearchInput
as input without binding it to page using a <form:form/>
tag and using jQuery's Ajax method
$.ajax()
How can this be done ?
Update here is the definition of FIReportSearchInput
public class FIReportSearchInput {
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date startDate;
@DateTimeFormat(pattern = "dd/MM/yyyy")
private Date endDate;
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getEndDate() {
return endDate;
}
public void setEndDate(Date endDate) {
this.endDate = endDate;
}
}
Upvotes: 2
Views: 3657
Reputation: 36
Here is a example,you can try it: I suppose FIReportSearchInput have id and name attributes.
$.ajax({
url:"downloadFIReport.do",
type:"post",
dataType:"json",
data:{id:$("#id").val(),name:$("#name").val()},
success:function(){}
});
when the spring mvc server catch this request,if your answer body is 'FIReportSearchInput fiReportSearchInput' and Object FIReportSearchInput have id and name attributes,it will call setter method automatically to build a new FIReportSearchInput Object named fiReportSearchInput.
Upvotes: 2