Friday 22 July 2022

What is @RequestMapping Annotation in JAVA Spring? : JAVA Interview Question-2022

 @RequestMapping Annotation:

This is one of the basic annotations in Spring that maps HTTP requests with methods. This is used to map the request into the specific method in Spring.

The method is run every time an end-user makes an HTTP request. The mapping can also be done at the method or class level.

@RequestMapping("/hello")

public class HelloController() 

{

        @RequestMapping("/helloworld")

        public String show() 

        {

        return "JAVA means Silan Software";

        }

        @RequestMapping("/helloall")

        public String display() 

        {

        return "javabytrilochan";

        }

}


From here, the 
/hello is assigned on the class level. And each method has separate mappings and this allows to have a prefix before creating the mapping.


Regards:

Trilochan Tarai

Associate Manager-Senior Lead Engineer,

Majesco India

+91-9439202111




No comments:

Post a Comment