Posts

Spring Boot Basic Controller

  @RestController @RequestMapping ( "/api" ) 1. @RestController: Usage : It is typically used in classes where you are defining API endpoints that return data (like JSON objects), which is common in REST APIs //Code @RestController public class MyController { @GetMapping("/hello") public String sayHello() { return "Hello, World!"; } } 2. @RequestMapping("/api") Usage : At the class level, @RequestMapping("/api") could mean that all the API endpoints in this controller will start with /api . You can define additional sub-paths or HTTP methods at the method level. @RestController @RequestMapping("/api") public class MyController { @GetMapping("/users") public List<String> getAllUsers() { return List.of("John", "Jane", "Doe"); } @PostMapping("/users") public String addUser(@RequestBody String user) { return "U...

Spring Boot Entity Class You must Know About [Indetail]

Entity --> [Which is used to create a table & DatabaseStructure)   import jakarta.persistence.Entity;  import jakarta.persistence.GeneratedValue;  import jakarta.persistence.GenerationType;  import jakarta.persistence.Id;  import jakarta.persistence.Table;  @Entity  @Table  public class UserDetail { @Id @GeneratedValue(strategy = GenerationType.IDENTITY)   private Long id;    1. GenerationType.AUTO Description: This option allows the persistence provider (JPA implementation, such as Hibernate) to choose the generation strategy for the primary key automatically. It may use different strategies based on the database and its configuration.    Usage: It's a good default choice, especially when you want to rely on the JPA provider to manage the key generation for you.   ##Code   @Id  @GeneratedValue(strategy = GenerationType.AUTO)  private Long id;   2. Generat...