Advertisement
avengerbot

Java Spring Rest Controller Example (Simple + ResponseEntity)

Jul 11th, 2022
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.55 KB | None | 0 0
  1. @RestController
  2. @RequestMapping (value = "/test")
  3. public class TestController {
  4.    
  5.     // localhost:8080/test/greeting
  6.     @RequestMapping(value = "/greeting", method = RequestMethod.GET)
  7.     public String getSimpleGreeting() {
  8.         return "Hello World!";
  9.     }
  10.    
  11.     // localhost:8080/test/greeting/entity
  12.     @RequestMapping(value = "/greeting/entity", method = RequestMethod.GET)
  13.     public ResponseEntity<String> getGreetingWithReponseEntity {
  14.         return ResponseEntity.status(HttpStatus.OK).body("Hello World!");
  15.     }
  16.      
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement