Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 27 | 28 |
29 | 30 |
Tags
- spring boot
- 회원가입
- 백준
- 서버개발
- SwiftUI
- swagger
- 통신
- Java
- 앱
- java spring
- 알고리즘
- 아이폰
- 백엔드
- Swift
- IOS
- JavaScript
- UI
- Node.js
- db
- database
- mac
- post
- 앱개발
- spring
- Xcode
- node
- 개발
- Alamofire
- 개발자
- API
Archives
- Today
- Total
YagSill
Java Spring Boot + swagger API 만들기 본문
728x90
안녕하세요 Yagsill 입니다.
controller부분입니다.
//controller
@RestController
@RequestMapping("/first")
@Tag(name = "first", description = "App 실행시 최초 실행")
public class firstController {
@Autowired
private FirstService firstService;
@Operation(summary = "버전체크", description = "앱 실행시 버전체크", tags = {"first"})
@ApiResponses(
value = {
@ApiResponse(description = "OK", responseCode = "200",
content = {@Content(mediaType = MediaType.APPLICATION_JSON_VALUE
,schema = @Schema(implementation = first.In.class)
)}),
}
)
@PostMapping(value = "", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<?> index(@Parameter first.In in) {
return new ResponseEntity<>(firstService.index(in), HttpStatus.OK);
}
}
dao 부분입니다.
// Dao
@Mapper
public interface InitDao {
public FirstDto.Out SQL이름(FirstDto.In in);
}
Mapper Annotation을 사용하여 XML 파일에 접근할 수 있습니다.
dto 부분입니다.
//Dto
@Data
public class FirstDto {
@Data
public static class In {
@Schema(example = "홍길동", description = "이름")
private String name;
}
@Data
public static class Out {
@Schema(example = "20", description = "나이")
private Integer age;
}
@Data
@Builder
public static class Result {
@Builder.Default
@Schema(example = "200")
private Integer resultCode = 200;
@Builder.Default
@Schema(example = "OK")
private String resultMsg = "OK";
@Schema(implementation = FirstDto.Out.class)
private Map<String, Object> data;
}
}
In -> swagger의 입력부분입니다.
Out -> 리턴값이라고 생각하면 됩니다.
Service
//Service
public class FirstService {
@Autowired
private FirstDao FirstDao;
public FirstDto.Result index(FirstDto.In in) {
FirstDto.Out out = new FirstDto.Out();
out = FirstDao.SQL이름(in);
if(out == null) {
System.out.println("에러가 나버렸습니다.")
}
System.out.println(out.getName());
return FirstDto.Result.builder().build();
}
}
끝!
728x90
'JAVA Spring' 카테고리의 다른 글
Spring boot + Swagger API 만들기(로그인 기능) (0) | 2023.01.17 |
---|---|
Spring boot + Swagger API 만들기(회원가입 기능) (0) | 2023.01.16 |
java Spring boot / FCM Push 연동하기 (0) | 2023.01.11 |
JAVA Spring boot DB데이터 전체 조회해보기 (0) | 2022.01.14 |
JAVA Spring boot 웹에서 데이터 조회 해보기 (0) | 2022.01.13 |