#How to map HTTP requests to Controllers in Spring?

1 messages · Page 1 of 1 (latest)

wise steppe
#

We have a Spring Boot API. But when I checked the controller there are no @GetMappings or similar annotations. I searched the project but it's not defined in an XML file either. What I found was an interface but I think it's related to swagger. Not sure how the mapping is being done

gleaming wadiBOT
#

<@&1004656351647117403> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
We have a Spring Boot API. But when I checked the controller there are no @GetMappings or similar annotations. I searched the project but it's not defined in an XML file either. What I found was an interface but I think it's related to swagger. Not sure ho

In Spring Boot, you can map HTTP requests to Controllers using the @RequestMapping annotation. This annotation allows you to specify the URL path and HTTP method for a particular method in your controller.

For example, if you want to map a GET request to a method in your controller, you can use the following code snippet:

@Controller
public class MyController {

    @RequestMapping(value = "/myEndpoint", method = RequestMethod.GET)
    public ResponseEntity<String> handleGetRequest() {
        return ResponseEntity.ok("Hello, World!");
    }
}

In this example, the handleGetRequest() method will be called when a GET request is made to the "/myEndpoint" path.

If you are not seeing any @GetMapping or similar annotations in your project, it is possible that the developers have opted to use the @RequestMapping annotation instead. You can also check if there are any custom annotations or configurations that might be handling the mapping of HTTP requests to controllers.

Overall, using the @RequestMapping annotation allows for more flexibility in specifying URL paths and HTTP methods for your controller methods. Make sure to consult the Spring documentation for more information on mapping HTTP requests to controllers in Spring Boot.

dry zealot
# gleaming wadi

@wise steppe check this , also check is there is spring boot web dependency in the pom.xml file otherwise u can copy paste the dependency from mvnrepository