import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class TreeNode {
int value;
List<TreeNode> children;
public TreeNode(int value) {
this.value = value;
this.children = new ArrayList<>();
}
}
public class ListToTreeConverter {
public static void main(String[] args) {
List<Map<String, Object>> flatList = createFlatList();
TreeNode root = convertListToTree(flatList);
// 이제 'root'를 사용하여 트리를 조작하거나 출력할 수 있습니다.
}
private static TreeNode convertListToTree(List<Map<String, Object>> flatList) {
Map<Integer, TreeNode> nodeMap = new HashMap<>();
for (Map<String, Object> item : flatList) {
int parentId = (int) item.get("parentId");
int nodeId = (int) item.get("id");
TreeNode currentNode = nodeMap.computeIfAbsent(nodeId, TreeNode::new);
if (parentId != 0) {
TreeNode parentNode = nodeMap.computeIfAbsent(parentId, TreeNode::new);
parentNode.children.add(currentNode);
}
}
return nodeMap.get(1); // 1은 루트 노드의 ID라고 가정합니다.
}
private static List<Map<String, Object>> createFlatList() {
// 예시로 사용할 평면 리스트 생성
List<Map<String, Object>> flatList = new ArrayList<>();
Map<String, Object> node1 = new HashMap<>();
node1.put("id", 1);
node1.put("parentId", 0);
Map<String, Object> node2 = new HashMap<>();
node2.put("id", 2);
node2.put("parentId", 1);
Map<String, Object> node3 = new HashMap<>();
node3.put("id", 3);
node3.put("parentId", 1);
Map<String, Object> node4 = new HashMap<>();
node4.put("id", 4);
node4.put("parentId", 2);
flatList.add(node1);
flatList.add(node2);
flatList.add(node3);
flatList.add(node4);
return flatList;
}
}
전체 글
- chat gpt java list to tree 2024.01.15
- 고 2023.11.28
- spring Resttemplate get 으로 가져오기 정리 2023.10.14 2
- vue input 실시간 확인 (input 이 비어있거나 혹은 공백 처리) 2023.10.13
- 스크립트 Object.entries 배열 을 다시 맵으로 2023.09.13
- git 원본 유지 와 동시에 파일 추적 중지 명령 2023.09.07
- vue accessing the dynamic ref 다이나믹 ref 생성 2023.08.28
- vue axios 60초 마다 갱신 2023.08.21
- LG OLED 48C1ENB 모니터 추천 2023.08.15
- 쿠팡 레노버 노트북 특가 2022 v15 g3 38만원 추천합니다. 2023.08.15
chat gpt java list to tree
고
spring Resttemplate get 으로 가져오기 정리
@GetMapping("/GetkobisData")
public String callAPI() throws JsonProcessingException {
HashMap<String, Object> result = new HashMap<String, Object>();
String jsonInString = "";
try {
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setConnectTimeout(5000); //타임아웃 설정 5초
factory.setReadTimeout(5000);//타임아웃 설정 5초
RestTemplate restTemplate = new RestTemplate(factory);
HttpHeaders header = new HttpHeaders();
HttpEntity<?> entity = new HttpEntity<>(header);
String url = "http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json";
UriComponents uri = UriComponentsBuilder.fromHttpUrl(url+"?"+"key=430156241533f1d058c603178cc3ca0e&targetDt=20120101").build();
//이 한줄의 코드로 API를 호출해 MAP타입으로 전달 받는다.
ResponseEntity<Map> resultMap = restTemplate.exchange(uri.toString(), HttpMethod.GET, entity, Map.class);
result.put("statusCode", resultMap.getStatusCodeValue()); //http status code를 확인
result.put("header", resultMap.getHeaders()); //헤더 정보 확인
result.put("body", resultMap.getBody()); //실제 데이터 정보 확인
//데이터를 제대로 전달 받았는지 확인 string형태로 파싱해줌
ObjectMapper mapper = new ObjectMapper();
jsonInString = mapper.writeValueAsString(resultMap.getBody());
} catch (HttpClientErrorException | HttpServerErrorException e) {
result.put("statusCode", e.getRawStatusCode());
result.put("body" , e.getStatusText());
System.out.println("dfdfdfdf");
System.out.println(e.toString());
} catch (Exception e) {
result.put("statusCode", "999");
result.put("body" , "excpetion오류");
System.out.println(e.toString());
}
return jsonInString;
}
출처.. https://vmpo.tistory.com/27
[Springboot] Resttemplate으로 api호출하기 (ex,영진위 데이터 호출 resttemplate.exchange 활용)
오늘은 springboot를 기반으로 웹서버를 생성한 후 API를 호출해 데이터를 전달 받아 화면에 출력해보도록 하겠습니다. Springboot 기본 설정은 아래 URL에서 확인 부탁드립니다. 인텔리J에서 Springboot
vmpo.tistory.com
response 고민하지 말고 한방에 이걸로..
vue input 실시간 확인 (input 이 비어있거나 혹은 공백 처리)
<template>
<div>{{ this.titleChk }}</div>
</template>
data() {
return {
title:'',
}
},
watch: {
title(){
// title input 이 비어있거나 혹은 공백일때 처리
var blank_pattern = /^\s+|\s+$/g;
if( _.isEmpty(this.title) || this.title.replace( blank_pattern, '' ) == "" ){
this.titleChk= false
}else{
this.titleChk= true
}
}
},
'Front > ::: Vue:::' 카테고리의 다른 글
vue accessing the dynamic ref 다이나믹 ref 생성 (0) | 2023.08.28 |
---|---|
vue axios 60초 마다 갱신 (0) | 2023.08.21 |
webpack 오류 vue-loader was used without the corresponding plugin (0) | 2023.08.13 |
lodash _.remove 가 잘 안됨 (0) | 2023.08.10 |
vue tree menu test code (0) | 2023.08.01 |
가져온 object에서 특정 key 제외 출력 (0) | 2023.07.12 |
vue SSO 작업 중 error 해결 정리 (0) | 2023.02.07 |
회사에서 npm install 안될때 (0) | 2023.01.26 |
스크립트 Object.entries 배열 을 다시 맵으로
let prices = {
banana: 1,
orange: 2,
meat: 4,
};
let doublePrices = Object.fromEntries(
// 객체를 배열로 변환해서 배열 전용 메서드인 map을 적용하고 fromEntries를 사용해 배열을 다시 객체로 되돌립니다.
Object.entries(prices).map(([key, value]) => [key, value * 2])
);
alert(doublePrices.meat); // 8
//객체 > 배열
// 배열 > 객체 전환
let list = {
banana: {
title: '서울 바나나',
배송유무: true
},
orange: {
title: '서울 오랜지',
배송유무: false
},
};
let 배송체크 = Object.fromEntries(
// 객체를 배열로 변환해서 배열 전용 메서드인 map을 적용하고
// fromEntries를 사용해 배열을 다시 객체로 되돌립니다.
Object.entries(list).map(([key, value]) => [key, value.배송유무])
);
console.log(배송체크); //{banana: true, orange: false}
자료구조를 언제쯤 검색 안하고 다룰수 있을까요~~~~~~~
https://ko.javascript.info/keys-values-entries
'Front > ::: JSCRIPT :::' 카테고리의 다른 글
콜백 함수 정의 (0) | 2022.08.31 |
---|---|
node (node.js) 노드 에서 || 설정 (0) | 2022.08.30 |
node js Ajax 에서 response 2번 이상 오류 ERR_HTTP_HEADERS_SENT (0) | 2022.06.23 |
스크립트 js script timer,setInterval,clearTimeout (0) | 2022.05.03 |
node-js express post호출 request의 body에서 undefined가 발생 (0) | 2020.03.08 |
node js , sequelize , postgres 개발 세팅 2 (0) | 2020.03.06 |
node js , sequelize , postgres 개발 세팅 1 (0) | 2020.03.05 |
넥사크로 grid 글자 수 제한 (0) | 2019.08.14 |
git 원본 유지 와 동시에 파일 추적 중지 명령
원본 유지 & 파일추적 중지
git update-index --skip-worktree file1
// 위 건 영구히 추적하지 않음.
// 아래 건 변화있으면 풀림.
git update-index --assume-unchanged file1
사용 예 ) git update-index --skip-worktree ./.gitignore
넌 좀 가만히 ~~ 있어 ㅋㅋㅋ
'BackEnd > ::: Git :::' 카테고리의 다른 글
git cursor remote connect 깃 커서 리모트 깃 허브 연결 (0) | 2025.03.12 |
---|---|
git 특정 상태 (타임머신) 커밋 버전 테스트 하기 (0) | 2022.12.24 |
소스트리 sourceTree ssh 연결 (0) | 2021.09.16 |
자꾸 까먹는 git 로컬에서 원격 ,원격에서 로컬 (0) | 2018.12.18 |
Git Remote 기준으로 덮어쓰기 (2) | 2017.12.09 |
git 아이디 암호 저장 (0) | 2017.12.07 |
GITHUB 저장소 로컬 연결 하기 (0) | 2017.11.29 |
git remote 올리고 받기 (2) | 2017.11.26 |
vue accessing the dynamic ref 다이나믹 ref 생성
<script>
export default {
data() {
return {
inputs: [
{ id: Date.now(), name: '', lastName: '' }
]
}
},
methods: {
displayRef(ref) {
console.log(this.$refs[ref]) // <= accessing the dynamic ref
console.log('The value of input is:',this.$refs[ref][0].value) //<= outpouting value of input
},
displayAllRefs() {
console.log(this.$refs)
}
}
}
</script>
참조 : https://stackoverflow.com/questions/45563329/how-to-add-dynamic-ref-in-vue-js
'Front > ::: Vue:::' 카테고리의 다른 글
vue input 실시간 확인 (input 이 비어있거나 혹은 공백 처리) (0) | 2023.10.13 |
---|---|
vue axios 60초 마다 갱신 (0) | 2023.08.21 |
webpack 오류 vue-loader was used without the corresponding plugin (0) | 2023.08.13 |
lodash _.remove 가 잘 안됨 (0) | 2023.08.10 |
vue tree menu test code (0) | 2023.08.01 |
가져온 object에서 특정 key 제외 출력 (0) | 2023.07.12 |
vue SSO 작업 중 error 해결 정리 (0) | 2023.02.07 |
회사에서 npm install 안될때 (0) | 2023.01.26 |
vue axios 60초 마다 갱신
methods: {
btcTrkAPICall: function () {
axios
.get('https://www.api1.com/api/ticker')
.then(response => (this.btctrk = response.data))
.catch(error => console.log(error))
},
bnncAPICall: function () {
axios
.get('https://api.api2.com/api/v3/ticker/bookTicker')
.then(response => (this.bnnc = response.data))
.catch(error => console.log(error))
},
intervalFetchData: function () {
setInterval(() => {
this.btcTrkAPICall();
this.bnncAPICall();
}, 1000);
}
},
mounted () {
// Run the functions once when mounted
this.btcTrkAPICall();
this.bnncAPICall();
// Run the intervalFetchData function once to set the interval time for later refresh
this.intervalFetchData();
}
'Front > ::: Vue:::' 카테고리의 다른 글
vue input 실시간 확인 (input 이 비어있거나 혹은 공백 처리) (0) | 2023.10.13 |
---|---|
vue accessing the dynamic ref 다이나믹 ref 생성 (0) | 2023.08.28 |
webpack 오류 vue-loader was used without the corresponding plugin (0) | 2023.08.13 |
lodash _.remove 가 잘 안됨 (0) | 2023.08.10 |
vue tree menu test code (0) | 2023.08.01 |
가져온 object에서 특정 key 제외 출력 (0) | 2023.07.12 |
vue SSO 작업 중 error 해결 정리 (0) | 2023.02.07 |
회사에서 npm install 안될때 (0) | 2023.01.26 |
LG OLED 48C1ENB 모니터 추천

해당
모니터 구매한지 1달 조금 넘었다.
일반적인 화질이 아니다 특히 게임을 할때 120Hz 일반적인 윈도우 10 에서도 120HZ 와 고 해상도는
맥 을 쓰는 느낌이다.
코딩 할때도 맥 느낌의 화질이여서 더 좋았던거 같다
정상적인 해상도와 hz 지원을 받을려면 3060 이상의 그래픽 카드가 필요하다
게임은 잘 안하는데.. 드디어 그래픽카드를 이용할 수 있다 ㅎㅎㅎ
한번씩 경험해보시길 추천 드린다.
거실도 oled로 가고 싶은데 인치가 올라가면 너무 비싸서 고민 고민

이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
'유용 유틸' 카테고리의 다른 글
윈도우(wsl) 리눅스 설치 명령어 모음 (0) | 2025.01.22 |
---|---|
팟플레이어 구버전 카카오TV 알리미 끄기 (0) | 2024.11.19 |
가벼운 토렌트 프로그램 torrent 클라이언트 (0) | 2024.08.15 |
pc에 설치된 시디키,시리얼 확인 프로그램 (0) | 2024.05.23 |
윈도우 시스템 정리 팁 모음 (2) | 2022.12.29 |
다음팟 플레이어 다음곡 단축키 (0) | 2021.07.08 |
시놀로지 MariaDB 10 외부접속 허용 (0) | 2021.04.14 |
커세어(CORSAIR) k60 pro 키보드 led 끄기 프로그램 없이 (4) | 2021.03.23 |
쿠팡 레노버 노트북 특가 2022 v15 g3 38만원 추천합니다.


https://link.coupang.com/a/6SUYG
레노버 2022 V15 G3 IAP
COUPANG
www.coupang.com
20230815 쿠팡 특가 공유합니다.
평상시 보다 많이 저렴합니다
^_^
이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.
'돈버는기술' 카테고리의 다른 글
유입이 많은 블로그 글을 작성하기 위한 2025년 최신 전략 (0) | 2025.03.17 |
---|---|
판매용 맥북에어 M1 이미지 (2) | 2024.09.26 |
오늘 하루 유튜브 숏츠 만들면서 찾아본 정보 정리 (6) | 2024.09.25 |
유튜브 쇼츠 자동화 시작 (6) | 2024.09.25 |
연금 저축, IRP 란 (0) | 2023.07.03 |
ISA 계좌 알귀~ (0) | 2023.07.03 |
비즈넵 사용 후기 (0) | 2023.01.11 |
난방비 가스비 절약 팁 (0) | 2022.12.18 |