Spring @PathVariable Annotation

In Spring Web MVC, we can use the @PathVariable annotation to access the captured URI variables. Table of contents: 1. Basic Mapping 2. Basic Mapping – Different Name 3. Basic Mapping – Class and method levels 4. Multiple Captured URI Variables 5. Multiple Captured URI Variables – Map Version 6. Regex Mapping 7. @PathVariable variables …

Read more

Spring @RequestBody Annotation

In the Spring framework, the @RequestBody annotation maps the web request’s body to the method’s parameter, usually a domain object or a Map. Table of contents 1. Spring @RequestBody example 2. Spring @RequestBody example – Map version 3. Download Source Code 4. References 1. Spring @RequestBody example Below is a @RequestBody example to map the …

Read more

Spring @Controller and @RestController Annotations

This article shows you what @Controller and @RestController are and their differences. Table of contents: 1. Spring @Controller annotation 2. Spring @RestController annotation 3. Download Source Code 4. References 1. Spring @Controller annotation Spring 2.5 introduced the @Controller as the web controller for the MVC architecture. Spring 3.0 introduced the @ResponseBody to return the method’s …

Read more

Spring @ResponseBody Annotation

In the Spring framework, the @ResponseBody annotation tells the Spring framework to write the method’s return type to the HTTP response body (not placed in a Model or interpreted as a view name). Spring 3.0 introduced the @ResponseBody annotation on the method level. Spring 4.0 enhanced the @ResponseBody annotation to put on the class level, …

Read more

Spring MVC hello world example (Maven and Thymeleaf)

This tutorial shows you how to create a Spring Web MVC application with the Thymeleaf template. Technologies and tools used: Java 11 Spring 5.2.22.RELEASE Thymeleaf 3.0.15.RELEASE Embedded Jetty Server 9.4.45.v20220203 Servlet API 4.0.4 Bootstrap 5.2.0 (webjars) IntelliJ IDEA Maven 3.8.6 Spring Test 5.2.22.RELEASE Hamcrest 2.2 JUnit 5.9 Table of contents: 1. Spring Web MVC Basic …

Read more