Sorry I'm starting on the site. How can I make a controller Generic restfull post JSON? My DAOS and services work perfectly. DAOS already are ready more do not know where to start ..!
I tried to do so:
public class AbstractControllerCrud<T extends IDomainObject> {
protected IGenericService<T> service;
public AbstractControllerCrud(IGenericService<T> service) {
this.service = service;
}
@RequestMapping(value = "all", method = RequestMethod.GET)
protected
@ResponseBody
List<T> getAll() {
List<T> listaGenerica = new ArrayList<>();
listaGenerica = service.getBeans();
return listaGenerica;
}
@RequestMapping(value = "{id}", method = RequestMethod.GET)
protected
@ResponseBody
T get(@PathVariable int id) {
Long idRequest = (long) id;
T retorno = this.service.getObjeto(idRequest);
return retorno;
}
@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
@ResponseBody
protected void delete(@PathVariable int id) {
Long idRequest = (long) id;
T T = this.service.getObjeto(idRequest);
service.deleta(T);
}
}
but it does not work: error 404;
@Controller("/test")
public class TestController extends AbstractControllerCrud<Profissoes> {
@Autowired
public TestController(@Qualifier("profissoesServicesImpl") IGenericService<Profissoes> profissaoService) {
super(profissaoService);
}
}
this works, it does not display 404.
@Controller
@RequestMapping("/profissoes")
public class ProfissoesController {
@Autowired
private IProfissoesService profissaoServ;
@RequestMapping(value = "all", method = RequestMethod.GET)
public
@ResponseBody
List<Profissoes> getProfissoes() {
List<Profissoes> listaProfissoes = new ArrayList<>();
listaProfissoes = profissaoServ.getBeans();
return listaProfissoes;
}
@RequestMapping(value = "{id}", method = RequestMethod.GET)
public
@ResponseBody
Profissoes get(@PathVariable int id) {
Long idRequest = (long) id;
Profissoes profissoes = this.profissaoServ.getObjeto(idRequest);
return profissoes;
}
@RequestMapping(value = "{id}", method = RequestMethod.DELETE)
@ResponseBody
public void delete(@PathVariable int id) {
Long idRequest = (long) id;
Profissoes profissao = this.profissaoServ.getObjeto(idRequest);
profissaoServ.deleta(profissao);
}
}