Home  >  Article  >  Java  >  How to solve the problem of 404 after calling SpringBoot interface

How to solve the problem of 404 after calling SpringBoot interface

王林
王林forward
2023-05-24 15:04:072200browse

My interface is like this:

How to solve the problem of 404 after calling SpringBoot interface

TestCase has no problem testing the method of the Impl class, but Swgger and the front-end will report a 404 error when calling the interface:

How to solve the problem of 404 after calling SpringBoot interface

I checked a lot of information on the Internet, and they all said it was an address problem. I checked the port in the context

server.port and there was no problem, nor did my local IP. There's no problem with the context, and the address is fine anyway.

After reading the annotations of my interface, the annotation used by my Controller class is @RestResultController, not @RestController.

Using @RestResultController, if the return value is a String type, there will be a directional problem. If the String type is returned, the pointed address is the address of the String string, so the front-end http access to my interface will report 404. (Just provide An explanation, not found online)

Solution:

There are two solutions. I chose one of them, which is to encapsulate the errMessage in a Body.

@Data(lombok的注解)
public class BpResp{
private String errMessage;
}

What is returned is BpResp

public BpResp add.........

Another solution is to add a @ResponseBody to the method, but because there are many tasks, I have not tried them one by one. Interested friends can try it.

Notes on learning spring boot and requesting Postman

Directly above the picture

The method of requesting data must be consistent with the requested http

The following Take deletion as an example

The key and value values ​​in the brackets below are obtained by using ?attribute=attribute value,

How to solve the problem of 404 after calling SpringBoot interface

The above is the detailed content of How to solve the problem of 404 after calling SpringBoot interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete