我想发布一个表单数据,其中一些值/文件可以为空/空。我尝试修改每个参数,但是当我解决 415 时出现 405 错误。
这是我的控制器功能
@RequestMapping(value = "/cart/post", method = RequestMethod.POST)
public @ResponseBody String addToCart(@RequestBody
ConfigurationForm configurationForm, BindingResult bindingResult)
throws CMSItemNotFoundException{
这是我的 AJAX 请求
$('#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();
}
});
})
这是我的配置表单
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
}