Returning NULL in Spring Boot

0

My page looks like this;

<!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>

And my controller is like this;

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";
    }


}

My model looks like this;

@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;
}

The getNumero is returning null, is someone seeing something that I can not see?

    
asked by anonymous 21.11.2016 / 17:44

2 answers

3

Your input is wrong.

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

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

    
21.11.2016 / 18:37
1

Spring Boot - Form Submission

The controller is missing the creation of the Ticket object. Something like the example:

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

Where to create the "Greeting" object.

    
21.11.2016 / 18:17