【发布时间】:2016-03-11 13:29:04
【问题描述】:
当我尝试访问以下方法时,出现(客户端发送的请求在语法上不正确)错误。
@RequestMapping ( value = "/prospect/prospectupdated", method = RequestMethod.POST )
public String prospectUpdated ( @ModelAttribute("prospect") CustomProspectList customProspectList, @RequestParam("consentForm") MultipartFile file ) throws IOException {
int id = customProspectList.getProsId();
String consentFormStatus = prospectService.consentFormStatus(id);
byte[] consentFormFile = file.getBytes();
String consentFormName = file.getOriginalFilename();
long consentFormSize = file.getSize();
String consentFormType = file.getContentType();
if ( consentFormStatus.equals("Y") && consentFormSize != 0 ){
prospectService.updateConsentForm(id, consentFormName, consentFormSize, consentFormFile, consentFormType);
}
return "success";
}
文件上传的JSP部分:
<form:input path="prosConsentForm" id="consentForm" type="file" style="display:initial" name="consentForm"/>
DAO实现方式:
@Override
public void updateConsentForm(int id, String consentFormName, long consentFormSize, byte[] consentFormFile, String consentFormType) {
Session session = sessionFactory.getCurrentSession();
String sql = "UPDATE ccm_prospect SET PROS_Consent_Form_Name = :ConsentFormName, PROS_Consent_Form_Size = :ConsentFormSize, PROS_Consent_Form_File = :ConsentFormFile, PROS_Consent_Form_Type = :ConsentFormType WHERE PROS_Id = :ProspectId";
SQLQuery query = session.createSQLQuery(sql);
query.setParameter("ConsentFormName", consentFormName);
query.setParameter("ConsentFormSize", consentFormSize);
query.setParameter("ConsentFormFile", consentFormFile);
query.setParameter("ConsentFormType", consentFormType);
query.setParameter("ProspectId", id);
query.executeUpdate();
}
在这里帮帮我:
这是 customProspectList 模型类。
public class CustomProspectList {
private int prosId;
private String prosDOB;
private String prosTrackingStatus;
private String prosFirstName;
private String prosLastName;
private String prosMiddleName;
private String prosGender;
private String prosEmail;
private String prosMobilePhone;
private String prosHomePhone;
private String prosWorkPhone;
private String prosCommuMethod;
private String prosAddrLine1;
private String prosAddrLine2;
private String prosCity;
private String prosState;
private String prosZipCode;
private byte[] prosConsentForm;
private byte[] prosHippaForm;
private String prosConsentFormName;
private String prosHippaFormName;
private String prosConsentFormDate;
private String prosHippaFormDate;
private BigInteger prosConsentFormSize;
private BigInteger prosHippaFormSize;
private String provNPI;
private String faciName;
private String faciAddrState;
private String persFirstName;
private String persLastName;
private String persMiddleName;
private String prosConsentFormType;
//getters & setters
这是表格:
<form:form commandName="prospect" action="${pageContext.request.contextPath}/prospect/prospectupdated" method="post" enctype="multipart/form-data" accept-charset="utf-8">
........
</form:form>
【问题讨论】:
-
请添加完整的堆栈跟踪。
-
抱歉,我在控制台中没有得到任何堆栈跟踪,我得到的是 HTTP 状态 400 - 仅......带有此描述“客户端发送的请求在语法上不正确。”。
-
请发布完整的 http 表单以及
CustomProspectList类,问题可能与它们有关。顺便说一句:您的表单必须设置多部分参数,并且您需要在 Spring 中注册 MultipartResolver / Filter。 spring.io/guides/gs/uploading-files -
是的,我已经在 spring 配置文件中注册了 MultipartResolver。
-
任何人都知道解决方案...
标签: java spring hibernate spring-mvc