Boa tarde, estou fazendo um cadastro de cliente pegando as informações atraves de um form, mas ao mandar o formulario recebo erro 400
ao tentar enviar.
classe Controller:
package br.com.rprvidros.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import br.com.rprvidros.daos.UsuarioDao;
import br.com.rprvidros.models.Endereco;
import br.com.rprvidros.models.Usuario;
@Controller
@Transactional
public class Cadastro {
@Autowired
private UsuarioDao dao;
@RequestMapping(value = "/cadastro")
public ModelAndView cadastro(){
ModelAndView modelAndView = new ModelAndView("/cadastro");
return modelAndView;
}
@RequestMapping(value = "/cadastro/add",method = RequestMethod.POST)
public ModelAndView add(Usuario usuario, Endereco endereco){
Usuario usuarioCadastrado = dao.inseriUsuario(usuario,endereco);
ModelAndView modelAndView = new ModelAndView("/");
return modelAndView;
}
}
formulario
<form:form servletRelativeAction="/rprvidros/cadastro/add" method="post">
<div class="form-cadastro">
<div class="email-nome">
<span class="icon-user2"></span>
<label><input class="nome-orcamento" type="text" name="nome" placeholder="Nome" autofocus required></label>
</div>
<div class="email-email">
<span class="icon-key2"></span>
<label><input class="email-orcamento" type="password" name="senha" placeholder="Senha" required></label>
</div>
<div class="email-email">
<span class="icon-email"></span>
<label><input class="email-orcamento" type="email" name="email" placeholder="Email" required></label>
</div>
<div class="email-email">
<span class="icon-email"></span>
<label><input class="email-orcamento" type="email" name="emailAlternativo" placeholder="Email-Alternativo" required></label>
</div>
<div class="email-telefone">
<span class="icon-phone2"></span>
<label><input class="telefone-orcamento" type="number" name="telefone" placeholder="Telefone" required></label>
</div>
<div class="email-telefone">
<span class="icon-milestone"></span>
<label><input class="telefone-orcamento" type="text" name="uf" placeholder="Estado" required></label>
</div>
<div class="email-telefone">
<span class="icon-building"></span>
<label><input class="telefone-orcamento" type="text" name="cidade" placeholder="Cidade" required></label>
</div>
<div class="email-telefone">
<span class="icon-location2"></span>
<label><input class="telefone-orcamento" type="text" name="cep" placeholder="Cep" required></label>
</div>
<div class="email-telefone">
<span class="icon-street-view"></span>
<label><input class="telefone-orcamento" type="text" name="logradouro" placeholder="Logradouro" required></label>
</div>
<div class="email-telefone">
<span class="icon-bell"></span>
<label><input class="telefone-orcamento" type="number" name="numero" placeholder="Número" required></label>
</div>
<input type="hidden" name="roles" value="'ROLE-ADM'">
<div class="enviar-orcamento">
<span class="icon-email2"></span>
<input type="hidden" name="${_csrf.parameterName }" value="${_csrf.token }" />
<button class="botao-orcamento" type="submit">Enviar</button>
</div>
</div>
</form:form>
metodo para adicionar o Usuario:
public Usuario inseriUsuario(Usuario usuario, Endereco endereco) {
manager.persist(usuario);
Usuario usuarioCadastrado = manager.find(Usuario.class, usuario);
manager.persist(endereco);
return usuario;
}
obrigado