|
| 1 | +package com.baeldung.annotations; |
| 2 | + |
| 3 | +import org.springframework.http.HttpStatus; |
| 4 | +import org.springframework.stereotype.Controller; |
| 5 | +import org.springframework.web.bind.annotation.CrossOrigin; |
| 6 | +import org.springframework.web.bind.annotation.ExceptionHandler; |
| 7 | +import org.springframework.web.bind.annotation.ModelAttribute; |
| 8 | +import org.springframework.web.bind.annotation.PathVariable; |
| 9 | +import org.springframework.web.bind.annotation.PostMapping; |
| 10 | +import org.springframework.web.bind.annotation.RequestBody; |
| 11 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 12 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 13 | +import org.springframework.web.bind.annotation.RequestParam; |
| 14 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 15 | +import org.springframework.web.bind.annotation.ResponseStatus; |
| 16 | + |
| 17 | +@Controller |
| 18 | +@RequestMapping(value = "/vehicles", method = RequestMethod.GET) |
| 19 | +public class VehicleController { |
| 20 | + |
| 21 | + @CrossOrigin |
| 22 | + @ResponseBody |
| 23 | + @RequestMapping("/hello") |
| 24 | + public String hello() { |
| 25 | + return "Hello World!"; |
| 26 | + } |
| 27 | + |
| 28 | + @RequestMapping("/home") |
| 29 | + public String home() { |
| 30 | + return "home"; |
| 31 | + } |
| 32 | + |
| 33 | + @PostMapping("/save") |
| 34 | + public void saveVehicle(@RequestBody Vehicle vehicle) { |
| 35 | + } |
| 36 | + |
| 37 | + @RequestMapping("/{id}") |
| 38 | + public Vehicle getVehicle(@PathVariable("id") long id) { |
| 39 | + return null; |
| 40 | + } |
| 41 | + |
| 42 | + @RequestMapping |
| 43 | + public Vehicle getVehicleByParam(@RequestParam("id") long id) { |
| 44 | + return null; |
| 45 | + } |
| 46 | + |
| 47 | + @RequestMapping("/buy") |
| 48 | + public Car buyCar(@RequestParam(defaultValue = "5") int seatCount) { |
| 49 | + return null; |
| 50 | + } |
| 51 | + |
| 52 | + @ExceptionHandler(IllegalArgumentException.class) |
| 53 | + @ResponseStatus(HttpStatus.BAD_REQUEST) |
| 54 | + public void onIllegalArgumentException(IllegalArgumentException exception) { |
| 55 | + } |
| 56 | + |
| 57 | + @PostMapping("/assemble") |
| 58 | + public void assembleVehicle(@ModelAttribute("vehicle") Vehicle vehicle) { |
| 59 | + } |
| 60 | + |
| 61 | + @ModelAttribute("vehicle") |
| 62 | + public Vehicle getVehicle() { |
| 63 | + return null; |
| 64 | + } |
| 65 | + |
| 66 | +} |
0 commit comments