Annotation Part2
There are some more annotations supported by Spring boot which we will be discussing in this blog.
In previous blog we already had a discussion on @RestController, @Controller, @ResponseBody, @RequestMapping, @RequestParam, @PathVariable, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping annotations.
To understand other annotations in detail, lets again create a sample application or we can continue in the same project we create as part of above blog. To create new Spring Boot Application project please follow below steps:
- Lets create a project using Spring Initilizr using link
- Fill Group and Artifact detail as com.javadoubts and practice respectively.
- Add dependencies as Spring Web and Spring boot actuator as mentioned in below screenshot.
- information as mentioned in below screenshot. Add dependencies as Spring Web and Spring boot actuator.
3. Unzip the downloaded file and import in eclipse. It will show below dependencies as part of pom.xml
4. Create a User.java bean class with username and password as a String field with setter and getter as shown below.
5. Create a UserController.java class with @RestController used to created RESTful web services which can be accessed using http methods like GET, POST, etc. and it is the combination of @Controller and @ResponseBody.
@PostMapping annotation to handle POST request.
@RequestBody use to map data coming as part of request with an Object.
@ResponseBody will generate response in predefined format mentioned as part of @PostMapping annotation.
6. Run application with the help of Apache Tomcat.
7. Open Postman chrome plugin and click on send after filling below highlighted information will generate below output highlighted green in color.
Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.