2012-08-28 1 views
2

양식에 파일 업로드에 어려움이 있습니다 : spring roo로 업데이트하십시오.양식에 파일 업로드 : Spring Roo로 업데이트

작성 부분에 대해서는 호세 델가도 here이 제공하는 양식 : 멀티 태그를 사용했습니다. 사용자 지정 양식 : 다중 태그는 양식에 enctype = "multipart/form-data"를 추가하고 올바르게 작동합니다.

문제는 업데이트 양식에 파일 업로드 기능을 제공하려는 경우입니다. Spring Roo (아마도 spring mvc, 나도 몰라)는 기본적으로 enctype = "application/x-www-form-urlencoded"를 업데이트 양식 (form : update 태그)에 설정합니다. 업로드 양식에서 enctype 속성을 enctype = "multipart/form-data"로 설정하면 서버는 양식을 제출할 때 "udpate"대신 "작성"메소드를 실행합니다.

우리는 (간단히) 그 문제를 어떻게 해결할 수 있었는지 생각해보십시오. 나는 이미 그것에 꽤 많은 시간을 보냈습니다. 그리고 나는 영감을 얻지 못했습니다. 어쩌면 그것은 오늘의 끝이기도합니다. 당신의 도움에 대한

감사합니다,

친절 감사

답변

3

OK ... 그것은 RequestMapping에 약간의 문제가있을 것 같다.

어떤 이유로 든 multipart 속성이 update 태그의 형식에서 "true"로 설정되면 메소드 매개 변수가 "POST"로 설정됩니다.

임시 해결책으로 create 메소드의 시작 부분에서 _method 매개 변수를 확인합니다. "PUT"으로 설정된 경우 update 메소드의 값을 리턴합니다.

@RequestMapping(method = RequestMethod.POST, produces = "text/html") 
    public String create(@Valid ActionRequest actionRequest, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { 

     // Work around dispatcher bug: if the multipart attribute of the form is set to true, 
     // submission of the update form routes to create method 
     String toto = httpServletRequest.getParameter("_method"); 

     if(httpServletRequest.getParameter("_method").equals("PUT")){ 
      return this.update(actionRequest,bindingResult,uiModel,httpServletRequest); 
     } 
    ... 
}