Hi everyone 👋 📌 Spring Boot Annotation Series Part 22– @RequestParam @RequestParam is used to read query parameters from the request URL and bind them to method parameters. It is part of the Spring Framework and commonly used in REST APIs built with Spring Boot. 🔹 Why do we use @RequestParam? Sometimes we need to pass additional information through the URL. Example: GET /users?age=25 Here, age is a query parameter. @RequestParam helps us capture that value in the controller method. 🔹 Simple Example @RestController @RequestMapping("/users") public class UserController { @GetMapping("/search") public String getUserByAge(@RequestParam int age) { return "User age is: " + age; } } 👉 Request URL: GET http://localhost:8080/users/search?age=25 Output: User age is: 25 🔹 In Simple Words @RequestParam takes values from query parameters in the URL and passes them to the controller method. 👉 🧠 Quick Understanding Used in filtering, search APIs Can be optional using required=false Can provide default values Used to read query parameters from URL Mostly used in GET APIs #SpringBoot #Java #RESTAPI #RequestParam #BackendDevelopment #LearningInPublic
Spring Boot @RequestParam Explained
More Relevant Posts
-
#Post2 In the previous post, we understood what a REST API is. Now the next question is 👇 How do we actually build REST APIs in Spring Boot? That’s where @RestController comes in 🔥 @RestController is a special annotation used to create REST APIs. It combines two things: • @Controller • @ResponseBody 👉 Meaning: Whatever method returns → it is written directly to the HTTP response body (usually JSON for objects) Example: @RestController public class UserController { @GetMapping("/user") public String getUser() { return "Hello User"; } } Output → "Hello User" (sent as response) 💡 Key difference: @Controller → used for returning views (JSP/HTML) @RestController → used for REST APIs (JSON response) Key takeaway: If you are building APIs in Spring Boot → @RestController is your starting point 🚀 In the next post, we will understand how request mapping works using @GetMapping and others 🔥 #Java #SpringBoot #BackendDevelopment #RESTAPI #LearnInPublic
To view or add a comment, sign in
-
🚀 Day 47/90 How Spring Boot loads 130+ AutoConfigurations (and how to debug them) Today’s learning connected two very important concepts: 👉 How Spring Boot loads auto-configurations internally 👉 How we can see which ones are applied or skipped 🔹 How Spring Boot loads AutoConfigurations? Spring Boot doesn’t magically configure everything. It follows a structured process: 1️⃣ Your application starts with @SpringBootApplication 2️⃣ This internally includes @EnableAutoConfiguration 3️⃣ Spring Boot then scans a special file: 📄 META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports This file contains a list of 100+ AutoConfiguration classes like: - DataSourceAutoConfiguration - HibernateJpaAutoConfiguration - WebMvcAutoConfiguration 4️⃣ These classes are loaded into the Spring context But here’s the catch 👇 👉 They are NOT blindly applied Each auto-configuration uses conditions like: @ConditionalOnClass @ConditionalOnBean @ConditionalOnProperty So Spring Boot decides: ✔ Apply if conditions match ❌ Skip if conditions fail 🔹 How to see this decision (VERY IMPORTANT 🔥) We can enable debugging using this property: debug=true 📍 Add it in application.properties 🔹 What happens after enabling this? At application startup, Spring prints a Condition Evaluation Report in logs: You will see: ✅ Positive Matches Configurations that were successfully applied ❌ Negative Matches Configurations that were skipped + reason ⚠️ Conditional Matches Dependent configurations 🔹 Example Insight You might see logs like: ✔ DataSourceAutoConfiguration matched ❌ JpaRepositoriesAutoConfiguration did not match (missing dependency) This tells you EXACTLY why something is working or not. 🔹 Why this is powerful? ▪️Understand which beans Spring created automatically ▪️Debug issues in: JPA / Hibernate Security DataSource 🔹 Pro Tip ⭐ Instead of full debug, you can use targeted logging: logging.level.org.springframework.boot.autoconfigure=DEBUG 🔹 Today's Tiny Win 💡 Today you moved from: 👉 “Spring Boot works magically” to 👉 “I can SEE and DEBUG Spring Boot decisions internally”🍀☘️ #SpringBoot #AutoConfiguration #Java #BackendDeveloper #90DaysChallenge
To view or add a comment, sign in
-
When working with APIs, you often need to pass data in the request. Spring Boot provides two common ways: @PathVariable and @RequestParam Example: @GetMapping("/users/{id}") public String getUser(@PathVariable int id) { return "User ID: " + id; } Here, id is part of the URL. Now using RequestParam: @GetMapping("/users") public String getUser(@RequestParam int id) { return "User ID: " + id; } Difference: • @PathVariable → part of URL path • @RequestParam → query parameter Example URLs: /users/10 → PathVariable /users?id=10 → RequestParam Choosing the right one improves API design. Next post: What is @RequestBody and how JSON is handled #Java #SpringBoot #BackendDevelopment #APIDesign
To view or add a comment, sign in
-
-
New to Spring Boot? You'll see these annotations in every project. Here's what they actually do: @SpringBootApplication → Entry point. Combines @Configuration, @EnableAutoConfiguration, @ComponentScan @RestController → Marks a class as an HTTP request handler that returns data (not views) @Service → Business logic layer. Spring manages it as a bean @Repository → Data access layer. Also enables Spring's exception translation @Autowired → Inject a dependency automatically (prefer constructor injection instead) @GetMapping / @PostMapping / @PutMapping / @DeleteMapping → Maps HTTP methods to your handler methods @RequestBody → Deserializes JSON from request body into a Java object @PathVariable → Extracts values from the URL path Bookmark this. You'll refer back to it constantly. Which annotation confused you the most when starting out? 👇 #Java #SpringBoot #Annotations #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
Hi everyone 👋 Continuing the Spring Boot Annotation Series 👇 📌 Spring Boot Annotation Series Part 25 – @ModelAttribute @ModelAttribute is used to bind request data (form data / query params) to a Java object. It is part of the Spring Framework and mainly used in Spring MVC applications. 🔹 Why do we use @ModelAttribute? When we receive multiple values from a request (like form data), instead of handling each parameter separately, we can bind them directly to an object. 👉 Makes code clean and structured. 🔹 Where is it used? Form submissions (HTML forms) Query parameters MVC applications (not mostly REST APIs) 🔹 In Simple Words @ModelAttribute takes request data and converts it into a Java object. 👉 🧠 Quick Understanding Binds request data to object Used in form handling Works with query/form data Not mainly used for JSON #SpringBoot #Java #ModelAttribute #SpringMVC #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
🚀 Day 6/100: Spring Boot From Zero to Production Topic: @SpringBootApplication Annotation Your setup is done, your dependencies are added, and now you are ready to write some actual code and business logic. It all begins from your Main Class. This class usually carries the name of your application and contains a main function, the exact point where the execution begins. But there is one very important part of this main class: the @Annotation. In simple terms, an annotation is metadata written after an @ sign. it tells the compiler and the framework specific information about your code. In our case, the star of the show is @SpringBootApplication. This is a "Meta-Annotation," meaning it’s a powerful 3-in-1 combo that keeps your code clean and organized: 1. @Configuration This marks the class as a source of bean definitions. It tells Spring that this class can contain methods annotated with @Bean. In the old days of Spring, you had to manage everything in bulky XML files. With this, we use pure Java to define our infrastructure. 2. @EnableAutoConfiguration This is the "secret sauce" that makes Spring Boot feel like magic. The Role: It tells Spring Boot to start adding beans based on what it finds on your classpath. If it sees h2.jar, it sets up an in-memory database for you. No more Boilerplate Nightmares. You don't have to manually set up a Data Source unless you want to override the defaults. 3. @ComponentScan 🔍 Think of this as the "Search Party" for your project. It tells Spring to hunt for other components, configurations, and services in your packages. It specifically looks for: @Component @Service @Repository @RestController The Scope: By default, it scans the package containing your main class and all sub-packages. This is why we always keep the main class in the root package! We’ve cracked open the entry point of every Spring Boot app. 🔓 See you in the next post. #Java #SpringBoot #SoftwareDevelopment #100DaysOfCode #Backend
To view or add a comment, sign in
-
-
Understanding Annotations in Spring Boot: Annotations play a key role in how Spring Boot applications are built and configured. But what exactly are they? Annotations are metadata added to Java code that tell the Spring framework how to behave or configure certain components. Instead of writing large configuration files, Spring Boot uses annotations to simplify development. Some commonly used annotations include: 🔹 @SpringBootApplication Marks the main class and enables auto-configuration, component scanning, and configuration support. 🔹 @RestController / @Controller Used to handle incoming HTTP requests and return responses. 🔹 @Service Indicates that a class contains business logic. 🔹 @Repository Used for database interaction and persistence operations. 🔹 @Autowired Allows Spring to automatically inject dependencies. ✅ These annotations help reduce boilerplate code and make Spring Boot applications easier to build and manage. Understanding how and why annotations are used is an important step toward mastering Spring Boot. #SpringBoot #Java #BackendDevelopment #SoftwareDevelopment
To view or add a comment, sign in
-
10 Spring Boot annotations — and what they ACTUALLY do. Most developers use these daily but can't explain them. 👇 1. @SpringBootApplication = @Configuration + @EnableAutoConfiguration + @ComponentScan Three annotations in one. This is why your app boots. 2. @RestController = @Controller + @ResponseBody Every method returns data directly. No view templates. 3. @Transactional Wraps your method in a DB transaction. Rolls back on RuntimeException. NOT checked exceptions by default. 4. @Autowired Injects a Spring-managed bean. Constructor injection is preferred. 5. @Value("${property}") Injects values from application.properties/yml at runtime. 6. @Async Makes a method run in a separate thread pool. Useless without @EnableAsync on your config class. 7. @Cacheable Caches the return value. Same input = no method execution. Massive performance win for read-heavy endpoints. 8. @Scheduled Runs a method on a timer/cron. Needs @EnableScheduling — easy to forget. 9. @Profile("prod") Only loads this bean in the specified environment. Lifesaver for environment-specific configs. 10. @ConditionalOnProperty Only creates the bean if a config property exists/matches. The secret weapon for feature flags in Spring Boot. Which one surprised you? And which one have you misused? 👇 Tag a Java dev who needs this cheat sheet. 🚀 #SpringBoot #Java #BackendDevelopment #JavaDeveloper #SoftwareEngineering #Programming #SpringFramework #LearnToCode
To view or add a comment, sign in
-
🚀 Exploring #XMLConfiguration in #SpringFramework As part of my learning journey in the Spring Framework, today I explored how Spring Beans can be configured using XML. 📄 In XML configuration, we define beans inside a configuration file and the Spring Container creates and manages those objects automatically. 🧩 A typical bean definition looks like this: <bean id="orv" class="com.coders.Product"></bean> Here: id → unique name of the bean class → Fully Qualified Name (FQN) of the Java class 📦 I also learned how to load the configuration file using ApplicationContext: ApplicationContext context = new ClassPathXmlApplicationContext("config.xml"); 🔎 Additionally, I explored different ways of injecting values into beans: • Constructor Injection using <constructor-arg> • Setter Injection using <property> (p-namespace) Understanding these concepts helps in managing object creation and dependencies efficiently in Spring applications. Looking forward to learning more advanced concepts and building real-world backend applications with Spring and Spring Boot! 💻 #SpringFramework #Java #BackendDevelopment #SpringBoot #LearningJourney #SoftwareDevelopment
To view or add a comment, sign in
-
-
Understanding Key Annotations in Spring Boot Annotations make Spring Boot development simple and powerful. Let’s look at three important ones 👇 🔹 @Entity → Represents a table in the database → Each instance of the class maps to a row → Used in the data layer 🔹 @RestController → Handles HTTP requests and returns responses → Used to build REST APIs → Combines @Controller + @ResponseBody 🔹 @Service → Contains business logic of the application → Acts as a bridge between Controller and Repository ✅ In simple terms: • @RestController → Handles requests • @Service → Processes logic • @Entity → Represents data Understanding these annotations helps you see how different layers in Spring Boot work together. #SpringBoot #Java #BackendDevelopment #LearningInPublic #DeveloperGrowth
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development