Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?

Spring Boot Cheat Sheet – DEV Community



🌱 Spring Annotations



@Repository :

  • Class Stage Annotation
  • It will possibly attain the database and do all of the operations.
  • It make the connection between the database and the enterprise logic.
  • DAO is a repository.
  • It’s a marker interface.
@Repository
public class TestRepo{
   public void add(){
      System.out.println("Added");
   }
}
Enter fullscreen mode

Exit fullscreen mode




@Service :

  • Class Stage Annotation
  • It’s a marker interface.
  • It’s a enterprise logic.
  • It’s a service layer.
  • It used to create a service layer.
@Service
public class TestService{
   public void service1(){
      //enterprise code (iş kodları)
   }
}
Enter fullscreen mode

Exit fullscreen mode




@Autowired :

  • Subject Stage Annotation
  • It’s used to inject the dependency.
  • It’s used to inject the thing.
  • It’s used to inject the thing reference.
  • Dependency Injection is a design sample.
public class Model{
   non-public int id;
   non-public String title;

   @Autowired
   public Model(int id, String title){
     this.id = id;
     this.title = title;
   }
}
Enter fullscreen mode

Exit fullscreen mode




@Controller :

  • Class Stage Annotation
  • It’s a marker interface.
  • It’s a controller layer.
  • It’s used to create a controller layer.
  • It use with @RequestMapping annotation.
@Controller
@RequestMapping("/api/manufacturers")
public class BrandsController{
   @GetMapping("/getall")
   public Worker getAll(){
       return brandService.getAll();
   }
}
Enter fullscreen mode

Exit fullscreen mode




@RequestMapping :

  • Methodology Stage Annotation
  • It’s used to map the HTTP request with particular methodology.
@Controller
@RequestMapping("/api/manufacturers")
public class BrandsController{
   @GetMapping("/getall")
   public Worker getAll(){
       return brandService.getAll();
   }
}
Enter fullscreen mode

Exit fullscreen mode




@GetMapping :

  • Methodology Stage Annotation
  • It’s used to map the HTTP GET request with particular methodology.
  • It’s used to get the info.
  • It’s used to learn the info.
  @GetMapping("/getall")
  public Worker getAll(){
      return brandService.getAll();
  }
Enter fullscreen mode

Exit fullscreen mode




@PostMapping :

  • Methodology Stage Annotation
  • It’s used to map the HTTP POST request with particular methodology.
  • It’s used so as to add the info.
  • It’s used to create the info.
  @PostMapping("/add")
  public void add(@RequestBody Model model){
      brandService.add(model);
  }
Enter fullscreen mode

Exit fullscreen mode




@PutMapping :

  • Methodology Stage Annotation
  • It’s used to map the HTTP PUT request with particular methodology.
  • It’s used to replace the info.
  @PutMapping("/replace")
  public void replace(@RequestBody Model model){
      brandService.replace(model);
  }
Enter fullscreen mode

Exit fullscreen mode




@DeleteMapping :

  • Methodology Stage Annotation
  • It’s used to map the HTTP DELETE request with particular methodology.
  • It’s used to delete the info.
  @DeleteMapping("/delete")
  public void delete(@RequestBody Model model){
      brandService.delete(model);
  }
Enter fullscreen mode

Exit fullscreen mode




@PathVariable :

  • Methodology Stage Annotation
  • It’s used to get the info from the URL.
  • It’s the best suited for RESTful internet service that comprises a path variable.
  @GetMapping("/getbyid/{id}")
  public Model getById(@PathVariable int id){
      return brandService.getById(id);
  }
Enter fullscreen mode

Exit fullscreen mode




@RequestBody:

  • It’s used to get the info from the request physique.
  • It’s used to get the info from the HTTP request.
  • It’s used to get the info from the HTTP request physique.
  @PostMapping("/add")
  public void add(@RequestBody Model model){
      brandService.add(model);
  }
Enter fullscreen mode

Exit fullscreen mode




@RequestParam:

  • It’s used to get the info from the URL.
  • It’s used to get the info from the URL question parameters.
  • It’s also often called question parameter.
@GetMapping("/getbyid")
public Model getById(@RequestParam int id){
    return brandService.getById(id);
}
Enter fullscreen mode

Exit fullscreen mode




@RestController:

  • Class Stage Annotation
  • It’s a marker interface.
  • It’s a controller layer.
  • It’s used to create a controller layer.
  • It use with @RequestMapping annotation.
  • It’s a mixture of @Controller and @ResponseBody annotations.
  • @RestController annotation is defined with @ResponseBody annotation.
  • @ResponseBody eliminates the necessity to add a remark to each methodology.
@RestController
@RequestMapping("/api/manufacturers")
public class BrandsController{
   @GetMapping("/getall")
   public Worker getAll(){
       return brandService.getAll();
   }
}
Enter fullscreen mode

Exit fullscreen mode


  • Should you like this text, you may give me a like on. 😎
    Thanks for studying. πŸ™

Hibernate Information

Visit my pageβœ…

Add a Comment

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?