같은 키값을 갖는 데이터가 있다면 덮어쓰기되어 기존 데이터가 날아감
중괄호로 시작해서 중괄호로 끝남(전세계 표준)
(대괄호 = 리스트, 중괄호 = 오브젝트)
ex. Type은 key가 String, value가 Integer일때, {key:value, key:value}의 형태로 담김
👉 {"Yoonseo":1}
저장할 때 key에는 hash값, value에 key값과 value를 리스트로 만들어서 오브젝트로 넣음
👉 최악의 경우 : 한칸에 모두 들어가는 경우
👉 찾을 때 : 해당 value를 전체 스캔해서 key가 같으면 return
일단 넣고 중복이 발생하면 다른 빈칸을 찾아서 넣음
(찾을 때 해당 key가 없는 경우 중복이므로 주변 칸들을 검색하면서 key가 같으면 그 값을 뽑음)
import java.util.ArrayList;
import java.util.List;
public class HashTableFunctionImprove {
class Node {
private String key;
private Integer value;
public Node(String key, Integer value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public Integer getValue() {
return value;
}
}
private int size = 1000;
private List<Node>[] table = new ArrayList[1000];
public HashTableFunctionImprove() {
}
public HashTableFunctionImprove(int size) {
this.size = size;
this.table = new ArrayList[size];
}
public int hash(String key) {
int asciiSum = 0;
for (int i = 0; i < key.length(); i++) {
asciiSum += key.charAt(i);
}
return asciiSum % size;
}
public void insert(String key, Integer value) {
int hashCode = hash(key);
if(this.table[hashCode] == null){
this.table[hashCode] = new ArrayList<>();
}
// Map, Object
this.table[hashCode].add(new Node(key, value));
System.out.println(key + " " + hashCode + "방에 저장이 완료되었습니다.");
}
public Integer search(String key) {
List<Node> nodes = this.table[hash(key)];
for (Node node : nodes) {
if(key.equals(node.getKey())){
return node.getValue();
}
}
return null;
}
public static void main(String[] args) {
HashTableFunctionImprove ht = new HashTableFunctionImprove();
ht.insert("Yoonseo", 1);
ht.insert("Seoyoon", 2);
int result = ht.search("Yoonseo");
if(result == 1) {
System.out.println("테스트 성공");
} else{
System.out.println("테스트 실패");
}
result = ht.search("Seoyoon");
if(result == 2) {
System.out.println("테스트 성공");
} else{
System.out.println("테스트 실패");
}
}
}
1차원 배열
int[] a = new int[10];: int를 담는 크기가 10인 배열 생성(크기 정적)List<Node>[] table = new ArrayList[1000];: Node를 담는 크기가 1000인 배열 생성(크기 정적)List<Node> table = new ArrayList<>();: Node를 담는 리스트 생성(크기 동적)
2차원 배열
int[][] arr = new int[10][20];: int를 담는 10*20 배열 생성(크기 정적)List<Integer>[] table = new List[1000]; 이후 for문으로 table [i] = new ArrayList<>() 생성: 이 방식으로 만들 수도 있음(외부는 1000고정, 내부는 동적)
(🔸 단, List에는 primitive type으로 제네릭을 걸 수 없음)List<List<Integer>>: 두 크기 모두 동적
엔터프라이즈 애플리케이션 개발
(엔터프라이즈 애플리케이션 : 개인용이 아닌 여러 사람이 쓰는 애플리케이션)
new를 직접 사용 (객체를 직접 생성)
🟢 Spring boot에서는 해당 코드 위에 @Autowired를 붙여서 의존성 주입
Spring boot를 쓰지 않으면 많은 설정과 테스트가 필요함
(이들은 서로 충돌이 발생할 수도 있음 - 버전 충돌)
👉 Spring boot가 등장하면서 설정 시간이 많이 단축됨
ex) 전에 DAO 실습할 때 dependencies에 spring-boot-starter-jdbc, spring-boot-starter-test를 사용했음 👉 원래 Spring만 사용하려고 했다면 많은 설정이 필요함)
SpringBoot는 WAS가 아님
(Web Application Server - Tomcat, Jetty)
(WAS를 포함하고 있지만 WAS는 아님)
MSA : Microservice Architecture
과거에는 서비스 규모가 하나로 이루어졌지만, MSA는 쪼개져서 서버 간 통신 API로 함
DB에 저장되었을 때 (저장하는 단계라면 영속성이 아직 없다고 볼 수 있음)
/을 포함하지 않음_)를 사용하지 않음. 대신 하이픈(-)을 사용함Gradle과 비슷한 도구(Gradle보다 먼저 나옴)
라이브러리(dependency) 관리 + 빌드 관리 도구
Lombok, Spring Configuration Processor, Spring Web 추가 후 생성결과
8080포트에 연결됨
👉 http://localhost:8080에 접속 가능
application.properties에서 server.port = 8081 : 8081로 변경됨
Talend API Tester or PostMan 중 Talend로 테스트
Talend API Tester : API를 만들고 테스트 할 수 있는 Tool
크롬 화장프로그램으로 Talend API Tester을 추가 후 실행
종류 : GET, POST, PUT, DELETE
👉 그냥 RequestMapping은 Post, Get, Delete, Put이 다 됨
특정 요청만 받고 싶을 때 : RequestMapping의 method에 RequestMethod.GET
👉 하지만 스프링 4.3이후로 바뀜
👉 @GetMapping처럼 앞에 메소드를 붙여서 나옴(PostMapping, PutMapping, DeleteMapping)
클래스 위에 RequestMapping(path)로 입력하면 기본 경로 변경
🟢 GET은 통과, POST는 실패
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1/get-api")
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello() {
return "Hello World";
}
@GetMapping(value = "/name")
public String getName() {
return "Kwanwun";
}
}
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/v1/get-api")
public class HelloController {
@GetMapping(value = "/variable1/{variable}")
public String getVariable1(@PathVariable String variable) {
return variable;
}
@GetMapping(value = "/variable2/{variable}")
public String getVariable2(@PathVariable("variable") String var) {
return var;
}
}
