Spring MVC, So senden Sie ein Formular per AJAX und gelangen mit ModelAttribute @Valid in den ControllerJava

Java-Forum
Anonymous
 Spring MVC, So senden Sie ein Formular per AJAX und gelangen mit ModelAttribute @Valid in den Controller

Post by Anonymous »

Ich habe das folgende Formular:

Code: Select all




Nome






Salario






Requisitos






Carga Mínima



Desconto Impostos










Klasse:

Code: Select all

@Model
public class CargoCadastroModel {

@NotEmpty(message = "Informe o nome!") @Pattern(regexp = "^\\p{L}+(?: \\p{L}+)*$", message = "Nome inválido")
private String nome;

@NotEmpty(message = "Informe o salário!") @Pattern(regexp = "[0-9]d+,d{0,2}$", message = "Valor inválido")
private String salario;

@NotEmpty(message = "Informe os Requisitos!")
private String requisitos;

@NotEmpty(message = "Informe a carga mínima!") @Pattern(regexp = "[0-9]+$", message = "Valor inválido, somente números")
private String cargamin;

@NotEmpty(message = "Informe o imposto!") @Pattern(regexp = "[0-9]d+,d{0,2}$", message = "Valor inválido somente números")
private String descImpostos;

public CargoCadastroModel() {
}
Ajax-Skript:

Code: Select all

$(document).on('click', '#cadCargo', function (e) {
e.preventDefault();  // prevent standard form submission
var fdata = new FormData($('#formCargo')[0]);
debugger;
$.ajax({
type: 'post',
url: '/Rhindo/Gerente/AddCargo',
data: fdata,
async: false,
cache: false,
processData: false,
dataType: "html",
contentType: 'application/json',
success: function (content) {
debugger;
$("#cadModal").html(content);
},
});
return false;
});
und Controller:

Code: Select all

@RequestMapping(value = "/Gerente/AddCargo", method = RequestMethod.POST)
public String getFormCargo(@RequestBody @ModelAttribute("formCargo") @Valid CargoCadastroModel cargoModel, BindingResult bindingResult, Model model) {
if (bindingResult.hasErrors()) {
model.addAttribute(cargoModel);
return "/gerente/cadastroCargo";
}
else{

}
return "/gerente/cadastroCargo";
}
Aber im Controller ist mein Modell immer null;
Ich habe es gerade mit JSON.strignfy und Serialisierung versucht, aber nichts hat funktioniert
Bitte helfen Sie

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post