Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of reporting 404 after calling SpringBoot interface

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Most people do not understand the knowledge points of this article, "SpringBoot interface call report 404 how to solve", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "SpringBoot interface call report 404 how to solve" article.

My interface is like this:

There is no problem with TestCase testing the method of the Impl class, but the Swgger and the front-end call interface will report a 404 error:

I looked up a lot of information on the Internet and said it was the address. I referred to the context.

The port in server.port is fine, my local IP is fine, the context is fine, anyway, the address is fine.

After looking at the annotations for my interface, my Controller class uses @ RestResultController instead of @ RestController.

Using @ RestResultController, there is a directivity problem if the return value is of type String. The String type is returned, and the address pointed to is the address of the String string, so the front-end http visits my interface will report 404. (just provide an explanation, which can not be found on the Internet)

Solution:

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

@ Data (comments on lombok) public class BpResp {private String errMessage;}

The return is BpResp.

Public BpResp add.

Another solution is to add @ ResponseBody to the method, but there is no one to try because there are so many tasks, so interested friends can give it a try.

Considerations for learning spring boot and requesting Postman

Directly above the picture

The way the data is requested must be consistent with the requested http

Take deletion as an example

The key and value values in parentheses below are passed through? Attribute = the way in which the attribute value is taken

The above is about the article "how to solve the problem after calling the SpringBoot interface". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report