Spring13 [Spring] @ModelAttribute와 @RequestBody의 데이터 바인딩 1. @ModelAttribute를 사용한 경우@Getter@Setter // @Setter가 빠진다면?public class FileUploadDto { private String description; private MultipartFile file;}@Controllerpublic class FileUploadController { @PostMapping public void uploadFile(@ModelAttribute FileUploadDto fileUploadDto) { MultipartFile file = fileUploadDto.getFile(); String description = fileUploadDto.getDescription(); .. 2024. 4. 5. [Spring] 코틀린 쓸 때 @Valid 동작이 안된다면 data class OwnerSignUpRequest( @field:Email(message = "이메일 형식을 입력해주세요.") val email: String?, @field:Size(min = 8, message = "비밀번호는 8글자 이상이어야 합니다.") val password: String?, @field:Size(min = 11, message = "잘못된 휴대전화 번호입니다.") val phoneNumber: String?, val storeName: String? = null, val ownerName: String, @field:Size(min = 10, message = "사업자번호는 10글자 이상이어야 합니다.") val businessRegistrationNumber: String.. 2024. 1. 18. [Spring] 스웨거 안되는 버전이 너무 많아요! 스웨거 버전이 다양해서 찾기가 어려웠다. // build.gradle.ktsimplementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0") 2023년 12월 31일 기준 가장 최신 버전은 위와 같다. 추가적인 `SwaggerConfig`나 `@EnableSwagger2` 등의 설정 없이 바로 `~/swagger-ui/index.html`로 사용 가능하다. 최신 버전은 아래에서 확인해주세요!https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui 이후 스웨거 UI가 마음에 안들어서 `ReDoc`으로 UI를 커스터마이징 했다. 2023. 12. 31. [Kotlin] 정적 팩토리 메소드 enum class IssueType { BUG, TASK; companion object { fun of (type: String) = valueOf(type.uppercase()) }}자바 느낌의 정적 팩토리 메소드 enum class IssueType { BUG, TASK; companion object { operator fun invoke(type: String) = valueOf(type.uppercase()) }}fun test() { IssueType("BUG")}코틀린에서 자체 지원하는 정적 팩토리 메소드 `.invoke`를 생략해도 위처럼 enum을 사용할 수 있다.// invoke 생략 가능IssueType.invoke.. 2023. 12. 26. [Spring] JPA 사용 시 프록시 객체 사용 주의점 프록시 객체는 처음 사용할 때 한 번만 초기화 프록시 객체를 초기화 할 때, 프록시 객체가 실제 엔티티로 바뀌는 것은 아님. 초기화되면 프록시 객체를 통해서 실제 엔티티에 접근 가능 프록시 객체는 원본 엔티티를 상속받음. 따라서 타입 체크 시 주의해야함 (==으로 비교시 실패. 대신 instance of 사용해서 비교) 영속성 컨텍스트에 찾는 엔티티가 이미 있으면 em.getReference()를 호출해도 실제 엔티티 반환 2023. 12. 5. 이전 1 2 3 다음