当我尝试访问以下方法时,我收到(客户端发送的请求语法错误)错误。
@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>
答案 0 :(得分:0)
尝试将您的文件绑定到:
private MultipartFile prosConsentForm;
而不是字节数组。
如果这不起作用,只需将记录器转为org.springframework的调试
对于每40X错误,spring不会写错误日志,但在调试中它会清楚地告诉你原因。