Annotations
@SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }
@RestController public class MyController { // Controller methods here }
@RestController public class MyController { @GetMapping("/hello") public String sayHello() { return "Hello, World!"; } }
@GetMapping("/hello/{name}") public String sayHello(@PathVariable String name) { return "Hello, " + name + "!"; }
@GetMapping("/greet") public String greet(@RequestParam String name) { return "Greetings, " + name + "!"; }
@PostMapping("/create") public ResponseEntity<String> create(@RequestBody MyEntity entity) { // Process the entity and return a response }
@PostMapping("/create") @ResponseStatus(HttpStatus.CREATED) public ResponseEntity<String> create(@RequestBody MyEntity entity) { // Process the entity and return a response }
@CrossOrigin(origins = "http://localhost:8080") @RestController public class MyController { // Controller methods here }
Last updated