스웨거 가동시켰는데 2024-02-16T09:42:22.674+09:00 ERROR 13444 --- [nio-8080-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column s1_0.address does not exist
Hint: Perhaps you meant to reference the column "s1_0.adress".
Position: 16
2024-02-16T09:42:22.732+09:00 ERROR 13444 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL [select s1_0.id,s1_0.address,s1_0.approval_evaluation,s1_0.business_information_evaluation,s1_0.business_type,s1_0.cancel_membership,s1_0.certification_mark,s1_0.created_at,s1_0.customer_complaint_board,s1_0.delivery_date,s1_0.domain,s1_0.email,s1_0.first_report_date,s1_0.initial_screen,s1_0.main_item,s1_0.mall_name,s1_0.monitoring_date,s1_0.payment,s1_0.phone_number,s1_0.privacy_evaluation,s1_0.privacy_statement,s1_0.refund_delivery_fee,s1_0.request_term_over,s1_0.safety_service,s1_0.sale_number,s1_0.security_server,s1_0.shop_name,s1_0.site_opening,s1_0.situation,s1_0.term_compliance,s1_0.terms_evaluation,s1_0.total_evaluation,s1_0.withdraw_possible,s1_0.withdrawal_evaluation from store s1_0] [ERROR: column s1_0.address does not exist
Hint: Perhaps you meant to reference the column "s1_0.adress".
Position: 16] [n/a]; SQL [n/a]] with root cause
org.postgresql.util.PSQLException: ERROR: column s1_0.address does not exist
Hint: Perhaps you meant to reference the column "s1_0.adress".
Position: 16
이 에러는 데이터베이스에 address가 아니라 adress라고 해서 생긴 문제고
2024-02-16T09:53:22.506+09:00 ERROR 3412 --- [nio-8080-exec-8] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: column s1_0.term_compliance does not exist
Hint: Perhaps you meant to reference the column "s1_0.term_compliance ".
Position: 571
2024-02-16T09:53:22.523+09:00 ERROR 3412 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: JDBC exception executing SQL [select s1_0.id,s1_0.address,s1_0.approval_evaluation,s1_0.business_information_evaluation,s1_0.business_type,s1_0.cancel_membership,s1_0.certification_mark,s1_0.created_at,s1_0.customer_complaint_board,s1_0.delivery_date,s1_0.domain,s1_0.email,s1_0.first_report_date,s1_0.initial_screen,s1_0.main_item,s1_0.mall_name,s1_0.monitoring_date,s1_0.payment,s1_0.phone_number,s1_0.privacy_evaluation,s1_0.privacy_statement,s1_0.refund_delivery_fee,s1_0.request_term_over,s1_0.safety_service,s1_0.sale_number,s1_0.security_server,s1_0.shop_name,s1_0.site_opening,s1_0.situation,s1_0.term_compliance,s1_0.terms_evaluation,s1_0.total_evaluation,s1_0.withdraw_possible,s1_0.withdrawal_evaluation from store s1_0] [ERROR: column s1_0.term_compliance does not exist
Hint: Perhaps you meant to reference the column "s1_0.term_compliance ".
Position: 571] [n/a]; SQL [n/a]] with root cause
org.postgresql.util.PSQLException: ERROR: column s1_0.term_compliance does not exist
Hint: Perhaps you meant to reference the column "s1_0.term_compliance ".
Position: 571
이건 term_compliance 라고 또 전처럼 띄어쓰기가 들어가서 그런거였다! 역시 오타 문제는 중요하다.
024-02-16T10:03:27.142+09:00 ERROR 16956 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.orm.jpa.JpaSystemException: Null value was assigned to a property [class cohttp://m.teamsparta.hoop.model.Store.approvalEvaluation] of primitive type: 'cohttp://m.teamsparta.hoop.model.Store.approvalEvaluation' (setter)] with root cause
java.lang.IllegalArgumentException: Can not set final int field cohttp://m.teamsparta.hoop.model.Store.approvalEvaluation to null value
at java.base/jdk.internal.reflect.FieldAccessorImpl.throwSetIllegalArgumentException(FieldAccessorImpl.java:228) ~[na:na]
at java.base/jdk.internal.reflect.FieldAccessorImpl.throwSetIllegalArgumentException(FieldAccessorImpl.java:232) ~[na:na]
at java.base/jdk.internal.reflect.MethodHandleIntegerFieldAccessorImpl.set(MethodHandleIntegerFieldAccessorImpl.java:111) ~[na:na]
이런 에러들이 발생했는데, 평가 항목에 null이 들어갈수 있어서 생기는 에러라고 했다. 그래서,
package com.teamsparta.hoop.model
import jakarta.persistence.*
@Entity
@Table(name = "store")
data class Store(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int,
@Column(name = "created_at")
val createdAt: String,
@Column(name = "shop_name")
val shopName: String,
@Column(name = "mall_name")
val mallName: String,
@Column(name = "domain")
val domain: String,
@Column(name = "email")
val email: String,
@Column(name = "phone_number")
val phoneNumber: String,
@Column(name = "business_type")
val businessType: String,
@Column(name = "address")
val address: String,
@Column(name = "sale_number")
val saleNumber: String,
@Column(name = "first_report_date")
val firstReportDate: String,
@Column(name = "situation")
val situation: String,
@Column(name = "total_evaluation")
val totalEvaluation: Int? = null,
@Column(name = "withdrawal_evaluation")
val withdrawalEvaluation: Int?,
@Column(name = "business_information_evaluation")
val businessInformationEvaluation: Int? = null,
@Column(name = "approval_evaluation")
val approvalEvaluation: Int?,
@Column(name = "terms_evaluation")
val termsEvaluation: Int?l,
@Column(name = "privacy_evaluation")
val privacyEvaluation: Int?,
@Column(name = "main_item")
val mainItem: String,
@Column(name = "withdraw_possible")
val withdrawPossible: String,
@Column(name = "initial_screen")
val initialScreen: String,
@Column(name = "payment")
val payment: String,
@Column(name = "term_compliance")
val termCompliance: String,
@Column(name = "privacy_statement")
val privacyStatement: String,
@Column(name = "request_term_over")
val requestTermOver: String,
@Column(name = "safety_service")
val safetyService: String,
@Column(name = "security_server")
val securityServer: String,
@Column(name = "certification_mark")
val certificationMark: String,
@Column(name = "delivery_date")
val deliveryDate: String,
@Column(name = "refund_delivery_fee")
val refundDeliveryFee: String,
@Column(name = "customer_complaint_board")
val customerComplaintBoard: String,
@Column(name = "cancel_membership")
val cancelMembership: String,
@Column(name = "site_opening")
val siteOpening: String,
@Column(name = "monitoring_date")
val monitoringDate: String
)
이렇게 int를 Int? = null로 바꿔주었다. 그런데, 이걸 해결하는게 시간이 좀 걸렸는데, 이유는 오류가 하나씩만 떠서 하나 null넣고 다시 시작하고 스웨거에서 버튼 누르고 오류 발생하고 인텔리제이에서 확인하고 null넣고를 반복하느라 그랬다. 하고보니 평가 부분만 문제가 생겼던데, 숫자 0,1,2,3 으로 구성되어 있는게 문제였던 모양이다. 왜그런진 모르겠지만.
그 다음엔 file:///C:/Users/asdf/Desktop/��뷮%20������Ʈ/hoop/src/main/kotlin/com/teamsparta/hoop/dto/StoreDto.kt:27:27 Type mismatch: inferred type is Int? but Int was expected 라는 오류가 발생했는데, 이것도 storedto를 이렇게
data class StoreDto(
val id: Int,
val shopName: String,
val mallName: String,
val domain: String,
val email: String,
val phoneNumber: String,
val businessType: String?,// String를 String?로 변경
val address: String,
val totalEvaluation: Int?, // Int를 Int?로 변경
val situation: String,
val monitoringDate: String
그러면 이제 전부 작동이 된다! 평가야 앞과 같은 이유로 그런거겠지만, 비즈니스타입은? 아마도 null만 있는것도 아니고 null과 쇼핑몰 이런식으로 혼재되어 있어서?? 어쨋든 해결 했다.
package com.teamsparta.hoop.controller
import com.teamsparta.hoop.dto.StoreDto
import com.teamsparta.hoop.service.StoreService
import io.swagger.v3.oas.annotations.Operation
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
import org.springframework.web.bind.annotation.RestController
@RestController
@RequestMapping("/api/stores")
class StoreController(
private val storeService: StoreService
) {
@GetMapping("/rating")
@Operation(summary = "전체 점수 조회", description = "0~3 까지의 숫자를 입력하세요.")
fun getStoresByTotalEvaluation(
@RequestParam rating: Int
): ResponseEntity<List<StoreDto>> {
val stores = storeService.getStoresByTotalEvaluation(rating)
return ResponseEntity.ok(stores)
}
@GetMapping("/status")
@Operation(summary = "점포 상태 조회", description = "사이트운영중단, 휴업중, 광고용(홍보용), 등록정보불일치, 사이트폐쇄, 영업중, 확인안됨 상태 중 1개를 선택하세요.")
fun getStoresBySituation(
@RequestParam status: String
): ResponseEntity<List<StoreDto>> {
val stores = storeService.getStoresBySituation(status)
return ResponseEntity.ok(stores)
}
@GetMapping("/rating-status")
@Operation(summary = "전체평가, 점포 상태 조회", description = "0~3 까지의 숫자와 사이트운영중단, 휴업중, 광고용(홍보용), 등록정보불일치, 사이트폐쇄, 영업중, 확인안됨 상태 중 1개를 선택하세요.")
fun getStoresByTotalEvaluationAndSituation(
@RequestParam rating: Int,
@RequestParam status: String
): ResponseEntity<List<StoreDto>> {
val stores = storeService.getStoresByTotalEvaluationAndSituation(rating, status)
return ResponseEntity.ok(stores)
}
}
그리고 이렇게 opration으로 설명을 넣어서 보기 좋게 만들어준다.
이제 나머지의 변한 모습을 감상하자.
package com.teamsparta.hoop.dto
import com.teamsparta.hoop.model.Store
data class StoreDto(
val id: Int,
val shopName: String,
val mallName: String,
val domain: String,
val email: String,
val phoneNumber: String,
val businessType: String?,
val address: String,
val totalEvaluation: Int?, // 타입을 Int?로 변경
val situation: String,
val monitoringDate: String
) {
constructor(store: Store) : this(
id = store.id,
shopName = store.shopName,
mallName = store.mallName,
domain = store.domain,
email = store.email,
phoneNumber = store.phoneNumber,
businessType = store.businessType,
address = store.address,
totalEvaluation = store.totalEvaluation,
situation = store.situation,
monitoringDate = store.monitoringDate
)
}
package com.teamsparta.hoop.model
import jakarta.persistence.*
@Entity
@Table(name = "store")
data class Store(
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
val id: Int,
@Column(name = "created_at")
val createdAt: String,
@Column(name = "shop_name")
val shopName: String,
@Column(name = "mall_name")
val mallName: String,
@Column(name = "domain")
val domain: String,
@Column(name = "email")
val email: String,
@Column(name = "phone_number")
val phoneNumber: String,
@Column(name = "business_type")
val businessType: String,
@Column(name = "address")
val address: String,
@Column(name = "sale_number")
val saleNumber: String,
@Column(name = "first_report_date")
val firstReportDate: String,
@Column(name = "situation")
val situation: String,
@Column(name = "total_evaluation")
val totalEvaluation: Int?,
@Column(name = "withdrawal_evaluation")
val withdrawalEvaluation: Int?,
@Column(name = "business_information_evaluation")
val businessInformationEvaluation: Int?,
@Column(name = "approval_evaluation")
val approvalEvaluation: Int?l,
@Column(name = "terms_evaluation")
val termsEvaluation: Int?l,
@Column(name = "privacy_evaluation")
val privacyEvaluation: Int?,
@Column(name = "main_item")
val mainItem: String,
@Column(name = "withdraw_possible")
val withdrawPossible: String,
@Column(name = "initial_screen")
val initialScreen: String,
@Column(name = "payment")
val payment: String,
@Column(name = "term_compliance")
val termCompliance: String,
@Column(name = "privacy_statement")
val privacyStatement: String,
@Column(name = "request_term_over")
val requestTermOver: String,
@Column(name = "safety_service")
val safetyService: String,
@Column(name = "security_server")
val securityServer: String,
@Column(name = "certification_mark")
val certificationMark: String,
@Column(name = "delivery_date")
val deliveryDate: String,
@Column(name = "refund_delivery_fee")
val refundDeliveryFee: String,
@Column(name = "customer_complaint_board")
val customerComplaintBoard: String,
@Column(name = "cancel_membership")
val cancelMembership: String,
@Column(name = "site_opening")
val siteOpening: String,
@Column(name = "monitoring_date")
val monitoringDate: String
)
package com.teamsparta.hoop
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
import org.springframework.boot.runApplication
@SpringBootApplication(exclude = [SecurityAutoConfiguration::class])//exclude 부분이 있어야 로그인 화면 안뜸
class HoopApplication
fun main(args: Array<String>) {
runApplication<HoopApplication>(*args)
}
package com.teamsparta.hoop
import io.swagger.v3.oas.models.Components
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.info.Info
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration
class SwaggerConfig {
@Bean
fun openAPI(): OpenAPI {
return OpenAPI()
.components(Components())
.info(
Info()
.title("Store API")
.description("Store API schema")
.version("1.0.0")
)
}
}
이녀석은 그냥 짧게 줄였다. 보기 좋으라고.
끝!