0% found this document useful (0 votes)
3 views

Program 2

@RequestMapping and its specialized annotations (@GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PathMapping) are used to map HTTP requests to handler methods in Spring. Other important annotations include @RestController, @ResponseBody, @RequestBody, @PathVariable, @RequestParam, and @RequestHeader, which facilitate data binding and request handling. Additionally, annotations like @Autowired, @Configuration, @ComponentScan, @Bean, @Component, @Controller, @Service, @Repository, and @EnableAutoConfiguration are used for bean management and application configuration in Spring.

Uploaded by

Karthik karas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Program 2

@RequestMapping and its specialized annotations (@GetMapping, @PostMapping, @PutMapping, @DeleteMapping, @PathMapping) are used to map HTTP requests to handler methods in Spring. Other important annotations include @RestController, @ResponseBody, @RequestBody, @PathVariable, @RequestParam, and @RequestHeader, which facilitate data binding and request handling. Additionally, annotations like @Autowired, @Configuration, @ComponentScan, @Bean, @Component, @Controller, @Service, @Repository, and @EnableAutoConfiguration are used for bean management and application configuration in Spring.

Uploaded by

Karthik karas
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

@RequestMapping: it is used to map the web requests.

it has many optional elements


like consumes, header, method, name, params, path, produces and value. we use it
with the class as well as the method.

@GetMapping: it maps the HTTP GET requests on the specific handler method. it is
used to create a web services endpoint that fetches it is used instead of
using:@RequestMapping(method=ReqeustMethod.GET)

@PostMapping: it maps the HTTP POST requests on the specific handler method. it is
used to create a web service endpoint that creates it is used instead of
using:@RequestMapping(method=RequestMethod.POST)

@PutMapping: it maps the HTTP PUT requests on the specific handler method. it is
used to create a web service endpoint that creates or updates it is used instead of
using:@RequestMapping(method=RequestMethod.PUT)

@DeleteMapping: it maps the HTTP DELETE requests on the specific handler method. it
is used to create a web service endpoint that delete a resource. it is used instead
of using:@RequetMapping(method=RequestMethod.DELETE)

@PathMapping: it maps the HTTP PATCH requests on the specific handler method. it is
used instead of using: @RequestMapping(method=RequestMethod.PATCH)

@RestController : It can be considered as a combination of @ Controller and


@ResponseBody annotations. The @Restcontroller annotation is itself annotated with
the @ResponseBody annotation. It eliminates teh need for annotating each method
with @ResponseBody.

@ResponseBody : it binds the method return value to the response body.it tells teh
Spring Boot Framework to serialize a return an object into JSON and XML format.

@RequestBody: it is used to bind HTTP request with an object in a method


parameter.internally it uses HTTP message converters to convert the body of the
request. when we annotate a method parameter with @RequestBody, the spring
framework binds the incoming HTTP request body to the parameter.

@pathVariable: it is used to extract the values from the uri. it is most suitable
for the Restful web service, where the url contains a path variabe. we can define
multiple @PathVariable in a method.

@RequestParam: it is used to extract the query parameters form the url. it is also
known as a query parameter. it is most suitable for web applications. it can
specify default values if the query parameter is not present in the url.

@RequestHeader: it is use to get the details about the HTTP request headers. We use
this annotation as a method parameter. The optional elements of the annotation are
name, required, value, defalutValue. for each detail in the header, we should
specify separate annotations. we can use it multiple time in a method.

@RequestAttribute: it binds a method parameter to request attribute. it provides


convenient access to the request atrributes from a controller method. with the help
of @RequestAttribute annotaion, we can access objects that arepopulated on the
server-side.

@Required: it applies to the bean setter method. it indicates that the annotated
been must be populated at configuration time with the required property, else it
throws an exception BeaninitilizationException.
@Autowired: Spring provides annotation-based auto-wiring by providing @Autowired
annotation. it is used to autowire spring bean on setter methods, instance
variable, and constructor. when we use @Autowired annotation, the spring container
auto-wires the bean by matching data-type.

@Configuration: it is a class-level annotion. the class annotated with


@Configuration used by containers as a source of bean definitions.

@ComponentScan: it is used when we want to scan a package for beans. it is used


with the annotation @Configuration. We can also specify the base packages to scan
for spring components.

@Bean: it is a method-level annotation. it is an alternative of XML<bean> tag. it


tells the method to produce a bean to be managed by spring container.

@Component: it is a class-level annotation. it is used to mark a java class as a


bean. A java class annotated with @Component is found during the classpath. The
spring framework pick it up and configure it in the applicaiton context as a spring
bean.

@Controller: the @Controller is a class-level annotation. it is a specialization of


@Component. it marks a class as a web request handler. it is often used to serve
web pages.By default, it returns a string that indicates which route to redirect.
it is mostly used with @RequestMapping annotation.

@Service: it is also used at class-level. it tells the spring that class contains
the business logic.

@Repository: it is a class-level annotation. The repository is a DAOs(Data Access


Object) that access the database directly. The repository does all the operations
related to the database.

@EnableAutoConfiguration: it auto-configures the bean that is present in the


classpath and configures it to run the methods. The use of this annotation is
reduced in spirng boot 1.2.0 release because developers provided an alternative of
the annotation, i.e. @SpringBootApplication.

@SpringBootApplicaiton: it is a combination of three annotations


@EnableAutoConfiguration, @ComponentScan and @Configuration.

You might also like