Spring Framework Tutorial
Software Setup and Configuration (STS/Eclipse/IntelliJ)
Core Spring
Spring Annotations
Spring Data
Spring JDBC
Spring Security
Spring @Controller example project:
@Controller
.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MyController { @RequestMapping("/hello") public String hello() { return "hello"; } }
Creating controllers with @Controller annotation in Spring:
@Controller
and defining request mapping methods.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MyController { @RequestMapping("/welcome") public String welcome() { return "welcome"; } }
Handling requests with @Controller in Spring framework:
@Controller
annotation to handle HTTP requests in a Spring MVC application.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MyController { @RequestMapping("/greet") public String greet() { return "greet"; } }
Mapping URLs to controller methods using @Controller in Spring:
@RequestMapping
annotation.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MyController { @RequestMapping("/custom-url") public String handleCustomURL() { return "customPage"; } }
Request handling and response in Spring @Controller:
@Controller
by defining appropriate methods.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @Controller public class MyController { @RequestMapping("/json-response") @ResponseBody public String jsonResponse() { return "{'message': 'Hello, JSON!'}"; } }
Working with ModelAndView in Spring @Controller:
ModelAndView
to work with models and views in a Spring @Controller
.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView; @Controller public class MyController { @RequestMapping("/model-view") public ModelAndView modelView() { ModelAndView modelAndView = new ModelAndView("myView"); modelAndView.addObject("message", "Hello, ModelAndView!"); return modelAndView; } }
Customizing request mappings with @Controller in Spring:
@Controller
by specifying URL patterns and handling different HTTP methods.// MyController.java import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/custom-mappings") public class MyController { @GetMapping("/get-request") public String handleGetRequest() { return "getMapping"; } @PostMapping("/post-request") public String handlePostRequest() { return "postMapping"; } }