I'm using retrofit with gson in android, i'm following a tutorial so the guy on the tutorial make it work but i can't it looks like my json data is lost when i call the retrofit method here are my call in android
ANDROID ACTIVITY.JAVA
public void addProspecto(Prospecto p){
prospectoService= Apis.getProspectoService();
Call<Prospecto>call=prospectoService.addProspecto(p);
call.enqueue(new Callback<Prospecto>() {
@Override
public void onResponse(Call<Prospecto> call, Response<Prospecto> response) {
if(response.isSuccessful()){
Toast.makeText(ProspectoActivity.this,"Se agrego con éxito",Toast.LENGTH_LONG).show();
}
}
@Override
public void onFailure(Call<Prospecto> call, Throwable t) {
Log.e("Error:",t.getMessage());
}
});
ANDROIDINTERFACE.JAVA
@POST("agregar")
Call<Prospecto>addProspecto(@Body Prospecto prospecto);
backend in springtools java ProspectoController.java
@RestController
@RequestMapping("/prospectos")
public class ProspectoController {
@Autowired
private ProspectoService service;
@GetMapping("/listar")
public List<Map<String, Object>> listar(){
return service.listar();
}
@PostMapping("/agregar")
@ResponseBody
public String save(@RequestBody Prospecto p) {
System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
System.out.println(p.getNombre());
int id=service.add(p);
if(id==0) {
return "No se pudo Regsitrar!";
}
return "Se registró con éxito!";
}
Prospecto model.java
@Data
public class Prospecto {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int ID;
private String nombre;
private String apPaterno;
private String apMaterno;
private String calle;
private String numero;
private String colonia;
private String cP;
private String telefono;
private String rFC;
private File documentos;
private String statusProspecto;
}
And for the last the repository or the file where i use the sql querys : ProspectoDAO
@Repository
public class ProspectoDAO implements ProspectoInterface {
@Autowired
JdbcTemplate template;
@Override
public List<Map<String, Object>> listar() {
// TODO Auto-generated method stub
List<Map<String, Object>>lista=template.queryForList("Select * from prospectos");
return lista;
}
@Override
public List<Map<String, Object>> listar(int id) {
// TODO Auto-generated method stub
return null;
}
@Override
public int add(Prospecto p) {
String sql = "insert into prospectos(Nombre, apPaterno, apMaterno, Calle, Numero, Colonia, CP, Telefono, RFC, Documentos, statusProspecto)values(?,?,?,?,?,?,?,?,?,?,?)";
return template.update(sql,
p.getNombre(),
p.getApPaterno(),
p.getApMaterno(),
p.getCalle(),
p.getNumero(),
p.getColonia(),
p.getCP(),
p.getTelefono(),
p.getRFC(),
p.getDocumentos(),
p.getStatusProspecto()
);
}
Please help, i'm sending the object ''Prospecto'' with ''nombre'' and all the data needed for it and in my backend it stills says that i don't have the data
In my database the column ''nombre'' were ''Nombre'' with capitals so thats was all i guess. For anyone who have the same problem check the getters and setters and put it the same as they are in the columns database.