layout : post
title : "Controller Interface 이용하기"
category : Spring
아래와 같이 설정해준 다음
@RequestMapping("/default")
public interface Test {
@GetMapping("/")
List<TestDto> getAll();
@GetMapping("/{id}")
Optional<TestDto> getById(@PathVariable int id);
@PostMapping("/save/{id}")
void save(@RequestBody TestDto testDto, @PathVariable int id);
}
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController implements Test {
private final TestService testService;
@Override
public List<TestDto> getAll() {
this.testService.getAll();
}
@Override
public Optional<TestDto> getById(int id) {
this.testService.getById(id);
}
@Override
public void save(TestDto testDto, int id) {
this.testService.save(testDto, id);
}
}
테스트 전송
```http request
curl http://localhost:8080/test/
GET http://localhost:8080/test/
###
```
'IT > Spring' 카테고리의 다른 글
2021-06-09-Memoery-setting (0) | 2023.02.28 |
---|---|
2021-06-08-외부라이브러리Bean등록 (0) | 2023.02.28 |
2021-05-24-SpringBoot-Authentication-null (0) | 2023.02.28 |
2021-05-13-Message-properties-특수문자 (0) | 2023.02.28 |
2021-05-03-JPA-Valid-Message (0) | 2023.02.28 |
댓글