π± 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");
}
}
@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Δ±)
}
}
@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;
}
}
@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();
}
}
@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();
}
}
@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();
}
@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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@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);
}
@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();
}
}
- Should you like this text, you may give me a like on. π
Thanks for studying. π
Hibernate Information