2020-09-29 16:09:23.401 ERROR 1976 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/pedido/formulario.html]")] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'requisicaonovopedido' available as request attribute
PedidoController
@RequestMapping(method = RequestMethod.POST, value="novo")
public String novo(@Valid Requisicaonovopedido requisicao,BindingResult result) {
if(result.hasErrors()) {
return"pedido/formulario";
}
Pedido pedido = requisicao.toPedido();
// aqui ele vai salvar o pedido no banco de dados
Pedido_Repositorio.save(pedido);
return"pedido/novo";
}
HTML
<form th:object="${requisicaonovopedido}" class="card-body" action="/pedido/novo" method="POST">
<div class="form-group">
<label for="nomeProduto">Produto</label>
<input th:field="*{nomeProduto}" class="form-control" placeholder="nome do produto"/>
<small>Informa qual o nome do produto.</small>
</div>