【发布时间】:2018-03-02 06:27:57
【问题描述】:
我在一个带有 Spring Data Rest 的 Spring Boot 项目中,我已经实现了一个获取数据休息的方法,并且它的工作正常:
@CrossOrigin
@RepositoryRestResource(collectionResourceRel="categorias-perguntas",path="categorias-perguntas")
public interface CategoriaPerguntaRepository extends CrudRepository<CategoriaPergunta, Long>{}
在我实现了一个普通的 RestController 之后:
@CrossOrigin
@RestController("motoristas")
public class MotoristaController {...}
一次获得:
@GetMapping
@ResponseStatus(code=HttpStatus.OK)
@ResponseBody
public Motorista buscaMotoristaPeloUsuario(@RequestParam(value="idUsuario") Long idUsuario) {
return this.motoristaService.findByUsuarioId(idUsuario);
}
实现这个控制器后,我的 DataRest "/categorias-perguntas" 已经停止工作,并返回:
"error": "Bad Request",
"exception": "org.springframework.web.bind.MissingServletRequestParameterException",
"message": "Required Long parameter 'idUsuario' is not present",
"path": "/categorias-perguntas"
但是“/categorias-perguntas”没有这个参数。 为什么我的 RestController 改变了 Data Rest Resource 的行为?
【问题讨论】:
-
尝试使用 URL - /categorias-perguntas?idUsuario=1L 访问您的后端。
标签: spring spring-data-rest spring-restcontroller spring-rest