【发布时间】:2014-12-17 18:09:02
【问题描述】:
抱歉,我从网站开始。 如何制作控制器通用 restfull 后 JSON? 我的 DAOS 和服务完美运行。 DAOS 已经准备好了更多不知道从哪里开始..!
我试过这样做:
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);
}
}
但它不起作用:错误404;
@Controller("/test")
public class TestController extends AbstractControllerCrud<Profissoes> {
@Autowired
public TestController(@Qualifier("profissoesServicesImpl") IGenericService<Profissoes> profissaoService) {
super(profissaoService);
}
}
这有效,它不显示 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);
}
}
【问题讨论】:
-
大家好,我需要通用控制器..
标签: java angularjs spring-mvc