-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloController.java
More file actions
26 lines (19 loc) · 918 Bytes
/
HelloController.java
File metadata and controls
26 lines (19 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package com.example.demo.controller;
import org.springframework.web.bind.annotation.RestController;
import com.example.demo.dto.ApiResponse;
import com.example.demo.model.Hello;
import java.util.concurrent.atomic.AtomicLong;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@RestController
@RequestMapping("/api/hello")
public class HelloController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@GetMapping("/hello-world")
public ResponseEntity<ApiResponse<Hello>> hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return ResponseEntity.ok(ApiResponse.success(new Hello(counter.incrementAndGet(), String.format(template, name))));
}
}