From the course: Spring: Spring MVC
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Use @Controller and @ResponseBody
- [Instructor] Now let us create simple RESTful services with a H plus spring MVC application. Let's create a controller, which uses two annotations, @controller, and @responsebody. Let's go back to the IDE, and on com.testwork H plus, I'm going to right click and create a new package first, which will be called REST controllers. I'm deliberately trying to keep this in a separate package so that when you refer the code, you have a clear distinction of which one was a REST controller and which one was an MVC controller. Under this, let's create a class. Let's call this products best controller. And let's designate this as controller quickly and down there let's provide a get mapping. Now there's a convention that your RESTful services generally follow when you try to define the URL pattern. So let's say this is called H plus/rest/products. Something like this. Alternatively, you could also use request…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
RESTful services recap5m 19s
-
Use @Controller and @ResponseBody5m 14s
-
Use @RequestController and @ResponseEntity4m 27s
-
Use @PathVariable and @RequestParam to get request payload3m 51s
-
Use @RequestBody and @ResponseEntity5m 18s
-
Use @ExceptionHandler3m 27s
-
Testing the @ExceptionHandler with the @ResponseEntity5m 35s
-
MVC vs. REST controllers1m 22s
-
-