带有String和Long path变量的Angular Rest API相同的URL失败400

时间:2019-05-27 00:16:24

标签: angular spring rest

我有两个带有相同URL的角度休息API findbyId和findbyLogin

api /用户

其中一个将用户ID(Long)作为路径变量,而另一个将 用户登录名(字符串)作为路径变量。我的资源类是Java中的两个API,一个用于字符串路径变量,另一个用于长路径变量。当我调用api findById时,它可以正常工作。但是,当我调用api findByLogin时,它会返回400错误的请求

Bad Request: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "xxxxxxxxx"


2019-05-27 10:00:41.602  WARN 19248 --- [ XNIO-2 task-11] .m.m.a.ExceptionHandlerExceptionResolver : Resolved exception caused by Handler execution: org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "xxxxxxxxx"

知道为什么会这样吗?目前,我通过将api URL更改为

解决了该问题

users / findbyId / {id}  和

users / findbyLogin / {login}

API是否不允许使用以前的方法?

0 个答案:

没有答案
相关问题