Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long' always says request parameter type error

Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long' always says that the parameter type is wrong. Could it be that the interface is not well written?

Made a super dumb mistake today

After writing the interface, I always can’t enter the interface, and always report an error:

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

I tested that the implementation class and Mapper data can be queried normally, but I can't enter the debug interface!

When I tried it, it said that my parameter type was wrong.
But my interface obviously didn't write parameters, supernatural event?

insert image description here
Later, I found out that the path was written wrong when my front-end sent the request.

But I accidentally discovered a knowledge point ,
/businessPaymentApply/info/getUserPostCode This is the correct interface path
/businessPaymentBatch/info/getUserPostCode This is the wrong interface path (that is, the path I wrote wrong on the front end)
I used to write it on the front end I wrote this wrong path when I wrote the path, and I obviously didn’t write the getUserPostCode interface in the interface class businessPaymentBatch. Instead of giving me an error 404, he actually gave me an error type conversion error.

Later, I found out that I wrote a get request interface in the businessPaymentBatch class,
insert image description here
so the request I sent came here. I said that I obviously did not pass parameters, but I always said that the parameters I passed were String. And it's still "getUserPostCode", this is my interface name.

The reason is that I did not write the getUserPostCode interface in the businessPaymentBatch class. Since the request I wrote in the front end is a GET request, the background directly goes to the GET interface in businessPaymentBatch, and this interface is PathVariable, so I directly put my " getUserPostCode" interface name to replace the PathVariable path, so I always say that I cannot convert String to Long, and the required parameter is Long type, but you gave String type.

So in fact, this
@GetMapping("/{businessPaymentBatchId}") is very similar
to
@GetMapping("/getUserPostCode")
, it is not recommended to write this way, it is better to add a path in front of them, for example:
@GetMapping("/business/{ businessPaymentBatchId}")
and
@GetMapping("/postCode/getUserPostCode")
are different, so they are distinguished!

Guess you like

Origin blog.csdn.net/qq_44627822/article/details/128562873