0

I want post a formdata where somme value/files can be null/empty. I tried to modify every parameters but when i resolve the 415 i get a 405 error.

Here is my controller function

@RequestMapping(value = "/cart/post", method = RequestMethod.POST)
    public @ResponseBody String addToCart(@RequestBody 
ConfigurationForm configurationForm, BindingResult bindingResult) 
throws CMSItemNotFoundException{

Here is my AJAX request

$('#popin_overlay_configuration').on('submit', '#configure-product- 
form', function (e) {
    e.preventDefault();
    var productCode = configuredCode;

    var formData = new FormData();

    // Code where i fill my formdata

    $.ajax({
        url: "cart/post",
        type: 'POST',
         data: formData,
         cache: false,
         processData: false,
         contentType: false,
        success: function(data) {
            $('#popin_overlay_configuration').hide();
        }
    });
 })

Here is my ConfigurationForm

public class ConfigurationForm
{
private String date;
private String lieuDePrestation;
private String pointDeContact;
private String commentaire;
private String transport;
private List<MultipartFile> PJFacultative;
private String referenceS;
private String referenceL;
private MultipartFile PJObligatoire;

//all the getters and setters are set
}
Millet Antoine
  • 313
  • 4
  • 19

1 Answers1

1

remove @ResponseBody inside your method,since @ResponseBody means your passing paramter must meet the specify format,and in your ajax,the parameter data may not meet the format

change

   public @ResponseBody String addToCart(@RequestBody ConfigurationForm 
       configurationForm, BindingResult bindingResult)

to

   public @ResponseBody String addToCart(ConfigurationForm configurationForm,
          BindingResult bindingResult)
lucumt
  • 6,642
  • 2
  • 16
  • 32
  • Thank you it works, but i really need to read some documentation about that – Millet Antoine Jun 06 '18 at 09:34
  • @milletantoine you can google `Spring ResponseBody` and you will find lots of document,such as this http://websystique.com/springmvc/spring-mvc-requestbody-responsebody-example/ – lucumt Jun 06 '18 at 09:38