GobsRuiz
GobsRuiz

Reputation: 522

Spring Boot - Edit data

I did the get, post and delete method. But now I'm suffering to do the put method.

My controller:

@RequestMapping("/teste/equipe/editar/{id}")
public String update(@RequestBody Team newTeam ,@PathVariable("id") Long id)
{
    Team team = teamService.findById(id);
    
    team.setName(newTeam.getName());
    team.setName(newTeam.getRole());
    teamService.save(team);

    return "redirect:/teste/equipe";
}

HTML:

<form action="/teste/equipe/editar/{id}" method="PUT">
    <input type="text" th:field="${team.name}" placeholder="Nome">
    
    <br>

    <input type="text" th:field="${team.role}" placeholder="Função">

    <button>
        Enviar
    </button>
</form>

Error: enter image description here

Upvotes: 2

Views: 38

Answers (1)

Rob Evans
Rob Evans

Reputation: 2874

Not certain this helps but the error on the whitelabel error page states:

Number Format Exception for input {id}

Seems like you're expecting {id} in your form:

<form action="/teste/equipe/editar/****{id}****" method="PUT">

to be interpolated with an actual ID. Should it instead be:

<form action="/teste/equipe/editar/${id}" method="PUT">

Upvotes: 1

Related Questions