Validation 필요한 이유 유효성 검증 하는 코드의 길이가 너무 길다. -> annotation 으로 해결 service logic에 대해서 방해가 된다. 흩어져 있는 경우 어디서 검증 되었는지 찾기 힘들다. 검증 로직이 변경되는 경우 테스트 코드 등, 전체 로직이 흔들릴 수 있다. -> 한 곳에 몰아서 검증 가능 JSR-380 BeanValidation build.gradle.kts 세팅 DeleteApiController // https://beanvalidation.org/2.0-jsr380/spec/ // JSR-320 // hibernate Validation // Spring boot Validation @RestController @RequestMapping("/api") @Valida..
문제 이해 실패율 : 스테이지에 도달, but 클리어 하지 못한 플레이어의 수 / 스테이지에 도달한 플레이어 수 스테이지에 도달한 유저가 없을 경우 실패율 0 N = 전체 스테이지의 갯수 stage = 사용자가 멈춰있는 스테이지의 번호가 담긴 배열 Return -> 실패율이 높은 스테이지부터 내림차순 배열 접근 2개의 Map 작성 스테이지, 사람수 스테이지, 실패율 내림차순 정리 answer 도출 풀이 class Solution { fun solution(N: Int, stages: IntArray): IntArray { var answer = IntArray(N) val indexMap: MutableMap = mutableMapOf() // 스테이지, 사람수 val failureMap: Mutable..
문제 이해 정수 n, m 가로 n, 세로 m 직사각형 출력 접근 이 중 포문으로 찍기 풀이 fun main(args: Array) { val (a, b) = readLine()!!.split(' ').map(String::toInt) for (i in 0 until b) { for (j in 0 until a) { print("*") } println() } }
ResponseApiController data class UserRequest( var name: String? = null, var age: Int? = null, var email: String? = null, var address: String? = null, var phoneNumber: String? = null ) @RestController @RequestMapping("/api/response") class ResponseApiController { // 1. get 4XX -> Error // GET http://localhost:8080/api/response?age=10 @GetMapping("") fun getMapping(@RequestParam age: Int?): Respon..
DeleteApiController @RestController @RequestMapping("/api") class DeleteApiController { // 가질수 있는 것 // 1. path variable // 2. request param @DeleteMapping(path = ["/delete-mapping"]) fun deleteMapping( // 이름 지정 가능 @RequestParam(value = "name") _name: String, @RequestParam(name = "age") _age: Int ): String { println(_name) println(_age) return _name + " " + _age } @DeleteMapping(path = ["/delete-..
절차 지향적 프로그래밍, 객체 지향형 프로그래밍, 함수형 프로그래밍 등 다양한 프로그래밍 기법중 하나이다. 기존의 명령형 프로그램 방식(Pull) 컴퓨터 하드웨어를 대상으로 프로그래머가 작성한 코드가 정해진 절차에 따라 순서대로 실행 리액티브 프로그래밍(Push) 데이터의 흐름을 미리 정의, 데이터의 값이 변경되었을 때, 관련 함수나 수식 업데이트 됨 즉, 프로그래머가 기존의 명령형 프로그래밍 방식과 같이 어떤 기능을 직접적으로 실행하는 것이 아닌 프로그램 속 시스템에 특정 이벤트 발생하면, 이를 효율적으로 처리하는 것이라고 할 수 있다. 이를 옵저버 패턴이라고 한다. 다시말해, 리액티브 프로그래밍은 데이터 흐름과 변화의 전달에 관한 프로그래밍 패러다임이다. 리액티브 프로그래밍은 주변환경과 끊임없이 상호..
PutApiController @RestController @RequestMapping("/api") class PutApiController { @PutMapping("/put-mapping") fun putMapping(): String { return "put-mapping" } @RequestMapping(method = [RequestMethod.PUT], path = ["/request-mapping"]) fun requestMapping(): String { return "request-mapping - put method" } //Post와 동일, Put -> 내용없으면 생성, 있으면 수정 @PutMapping(path = ["/put-mapping/object"]) fun putMappi..
문제 이해 주어진 숫자 중 3개의 수를 더했을때 소수가 된는 경우의 개수 Return 접근 삼중 for문을 사용한 3가지 합의 경우의 수 구하기 플래그 + 합이 소수인지 판별해서 answer++ 풀이 class Solution { fun solution(nums: IntArray): Int { var answer = 0 for (i in 0 until nums.size - 2) { for (j in i + 1 until nums.size - 1) { for (k in j + 1 until nums.size) { var sum = nums[i] + nums[j] + nums[k] var flag = 0 for (l in 2 until sum) { if (sum % l == 0) { flag = 1 brea..
package com.example.mvc.controller.post import com.example.mvc.model.http.UserRequest import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api") class PostApiController { //현대 방식 @PostMapping("/post-mapping") fun postMapping(): String { return "post-mapping" } //과거 방식 @RequestMapping(method = [RequestMethod.POST], path = ["request-mapping"]) // 주소 외부 노출, url 받는 형식 다..
문제 이해 Input : x, n Return x ~ x 씩 증가 n개 array 접근 리스트 만든후 n개만큼 반복 i (index)를 곱해서 배열에 넣어줌 풀이 class Solution { fun solution(x: Int, n: Int): LongArray { val answer = mutableListOf() for (i in 1..n) { answer.add(x.toLong() * i) } return answer.toLongArray() } } 다른 사람의 풀이 class Solution { fun solution(x: Int, n: Int): LongArray = LongArray(n) { x.toLong() * (it + 1) } }
package com.example.mvc.controller.get import com.example.mvc.model.http.UserRequest import org.springframework.web.bind.annotation.* @RestController //REST API @RequestMapping("/api") //localhost:8080/api class GetApiController { //Get 주소를 노출할때 사용 하는 방법 : 최근 //@GetMapping("/hello") : http://localhost:8080/api/hello @GetMapping(path = ["/hello", "/abcd"]) //Get http://localhost:8080/api/hello, G..
REST 란 ? REST(Representational State Transfer, 자원의 상태 전달) 네트워크 아키텍쳐 원리 RESTful 이란 ? 아래의 몇가지 조건이 잘 지켜진 api가 있을때 RESTful 한 api 라고 할 수 있다. Client, Server : 클라이언트와 서버가 서로 독립적, 분리 Stateless : 요청에 대해서 클라이언트의 상태가 서버에 저장되지 않는다. 요청하는 값을 즉각 요청 ex) 햄버거 가게에서 주문할때, 치즈버거 주문 , 치즈버거 + 콜라 각각 주문, 전에 주문한걸 기억하지 않는다. 캐시 : 클라이언트는 서버의 응답을 캐시 할 수 있다. 클라이언트가 캐시를 통해서 응답을 재사용 할 수 있어야 하며, 이를 통해 서버의 부하를 낮출 수 있다. 계층화(Layered..