0

Minha pagina está assim;

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:th="http://www.thymeleaf.org">

<body>
    <h1>Olá! Thymeleaf configurado!</h1>
</body>

    <form method="POST">
        <label for="numero">numero</label>
        <input type="text" id="numero" name="nomero"/>


        <input type="submit" value="Salvar"/>
    </form>

</html>

E meu controller está assim;

package com.controle.boleto.controller;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.controle.boleto.model.Boleto;

@Controller
public class BoletoController {


    @RequestMapping("/boleto/novo")
    public String novo(){
        return "boleto/CadastroBoleto";
    }


    @RequestMapping(value="/boleto/novo", method = RequestMethod.POST)
    public String cadastrar(@Valid Boleto boleto, BindingResult result ){

        if(result.hasErrors()){
            System.out.println("tem erro sim");
        }

        System.out.println(">>>>> numero " + boleto.getNumero());
        return "redirect:/boleto/novo";
    }


}

meu model está assim;

@NotBlank
private String numero;
private BigDecimal valor;
private String comentario;

public String getNumero() {
    return numero;
}

public void setNumero(String numero) {
    this.numero = numero;
}

public BigDecimal getValor() {
    return valor;
}

public void setValor(BigDecimal valor) {
    this.valor = valor;
}

public String getComentario() {
    return comentario;
}

public void setComentario(String comentario) {
    this.comentario = comentario;
}

O getNumero está retornando null, será que alguém está enxergando algo que não estou conseguindo ver?

2 Respostas 2

3

Seu input está errado.

Troque: <input type="text" id="numero" name="nomero"/>

Por: <input type="text" id="numero" name="numero"/>

1
  • 1
    muito obrigado, errei feio.
    – user10264
    21/11/2016 às 17:53
0

Spring Boot - Form Submission

No controller está faltando a criação do objeto Boleto. Algo parecido como no exemplo:

@GetMapping("/greeting")
public String greetingForm(Model model) {
    model.addAttribute("greeting", new Greeting());
    return "greeting";
}

Onde se tem a criação do objeto "Greeting".

Você deve fazer log-in para responder a esta pergunta.