How to process a multipart request consisting of a file and a JSON object in Spring restful service?

前端 未结 9 1226
一生所求
一生所求 2020-12-08 07:47

I have the following resource (implemented using Spring 4.05.RELEASE) which accepts a file and a JSON object:

(P.S. activityTemplate is a serializable entity class)<

9条回答
  •  余生分开走
    2020-12-08 08:30

    You have not given the param names to your @RequestParts ?

    public @ResponseBody ActivityTemplate createActivityTemplate(
        @RequestPart("activityTemplate") ActivityTemplate activityTemplate, @RequestPart("file") MultipartFile jarFile)
    {
       //process the file and JSON
    }
    

    Note: do not forget to include the jackson mapper .jar (maps your Json to ActivityTemplate) file in your classpath.

提交回复
热议问题