Ce contenu n'est pas disponible dans la langue sélectionnée.

20.11. @MultipartForm and POJOs


If you are familiar with your multipart/form-data packets, you can map them to and from a POJO class with the @org.jboss.resteasy.annotations.providers.multipart.MultipartForm annotation and the @FormParam JAX-RS annotation. To do so, define a POJO with a default constructor (at least), and annotate its fields, properties, or both, with @FormParams. These @FormParams must also be annotated with @org.jboss.resteasy.annotations.providers.multipart.PartType to be output. For example:
   public class CustomerProblemForm {
      @FormData("customer")
      @PartType("application/xml")
      private Customer customer;

      @FormData("problem")
      @PartType("text/plain")
      private String problem;

      public Customer getCustomer() { return customer; }
      public void setCustomer(Customer cust) { this.customer = cust; }
      public String getProblem() { return problem; }
      public void setProblem(String problem) { this.problem = problem; }
   }
Copy to Clipboard Toggle word wrap
Once you have defined your POJO class, you can use it to represent multipart/form-data. The following code sends a CustomerProblemForm using the RESTEasy client framework:
   @Path("portal")
   public interface CustomerPortal {

      @Path("issues/{id}")
      @Consumes("multipart/form-data")
      @PUT
      public void putProblem(@MultipartForm CustomerProblemForm,
                             @PathParam("id") int id);
   }

   {
       CustomerPortal portal = ProxyFactory.create(CustomerPortal.class, "http://example.com");
       CustomerProblemForm form = new CustomerProblemForm();
       form.setCustomer(...);
       form.setProblem(...);

       portal.putProblem(form, 333);
   }
Copy to Clipboard Toggle word wrap
Note that the @MultipartForm annotation tells RESTEasy that the object has @FormParam, and that it should be marshalled from that parameter. You can use the same object to receive multipart data. Here is an example of the server-side counterpart to the customer portal.
   @Path("portal")
   public class CustomerPortalServer {

      @Path("issues/{id})
      @Consumes("multipart/form-data")
      @PUT
      public void putIssue(@MultipartForm CustomerProblemForm,
                           @PathParam("id") int id) {
         ... write to database...
      }
   }
Copy to Clipboard Toggle word wrap
Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat