I'm trying to make this springboot code, turn a code into WebApi
@RequestMapping("/deletarEvento")
public String deletarEvento(long codigo)
{
Evento evento = er.findByCodigo(codigo);
er.delete(evento);
return "redirect:/eventos";
}
More when I try to do
@RequestMapping(value="/deletarEvento", method=RequestMethod.DELETE)
public String deletarEvento(long codigo)
{
Evento evento = er.findByCodigo(codigo);
er.delete(evento);
return "redirect:/eventos";
}
He gives this error:
There was an unexpected error (type = Bad Request, status = 400).
Failed to convert value of type 'java.lang.String' to required type 'long';
nested exception is java.lang.NumberFormatException: For input string: "deletarEvento"
Event Class
package com.vestibulartio.models;
Home
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table (name="event")
public class Event {
@Id
@Column(name="codigo")
private Long codigo;
//@OneToMany
//private List<Convidado> convidado;
@Column(name="nome")
private String nome;
@Column(name="local")
private String local;
@Column(name="data")
private String data;
@Column(name="horario")
private String horario;
public Long getCodigo() {
return codigo;
}
public void setCodigo(Long codigo) {
this.codigo = codigo;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getLocal() {
return local;
}
public void setLocal(String local) {
this.local = local;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getHorario() {
return horario;
}
public void setHorario(String horario) {
this.horario = horario;
}
} package com.vestibulartio.models;
import java.util.List;
import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table;
@Entity @Table (name="event") public class Event {
@Id
@Column(name="codigo")
private Long codigo;
//@OneToMany
//private List<Convidado> convidado;
@Column(name="nome")
private String nome;
@Column(name="local")
private String local;
@Column(name="data")
private String data;
@Column(name="horario")
private String horario;
public Long getCodigo() {
return codigo;
}
public void setCodigo(Long codigo) {
this.codigo = codigo;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getLocal() {
return local;
}
public void setLocal(String local) {
this.local = local;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getHorario() {
return horario;
}
public void setHorario(String horario) {
this.horario = horario;
}
}