반응형

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;
   }
}

반응형

반응형
 @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 고민하지 말고 한방에 이걸로..

반응형
반응형
<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
                }
            }
    },

 

반응형
반응형
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

 

반응형
반응형

원본 유지 & 파일추적 중지

git update-index --skip-worktree file1
// 위 건 영구히 추적하지 않음.
// 아래 건 변화있으면 풀림.
git update-index --assume-unchanged file1

사용 예 ) git update-index --skip-worktree  ./.gitignore

 

넌 좀 가만히 ~~ 있어 ㅋㅋㅋ

반응형
반응형
<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

반응형
반응형

 

  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();
    }

https://stackoverflow.com/questions/54601694/how-to-auto-refresh-a-computed-property-at-axios-in-vuejs

반응형
반응형

 

 

 

 

해당 

 

모니터 구매한지 1달 조금 넘었다.

일반적인 화질이 아니다 특히 게임을 할때 120Hz 일반적인 윈도우 10 에서도 120HZ 와 고 해상도는

맥 을 쓰는 느낌이다.

 

코딩 할때도 맥 느낌의 화질이여서 더 좋았던거 같다

 

정상적인 해상도와 hz 지원을 받을려면 3060 이상의 그래픽 카드가 필요하다

게임은 잘 안하는데.. 드디어 그래픽카드를 이용할 수 있다 ㅎㅎㅎ

 

한번씩 경험해보시길 추천 드린다.

 

거실도 oled로 가고 싶은데 인치가 올라가면 너무 비싸서 고민 고민

 

LG전자 올레드 TV, 120cm, OLED48C1ENB, 스탠드형, 방문설치

 

 

 

이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

반응형
반응형

특가 싼거 공유합니다.

레노버 2022 V15 G3 IAP, Iron Gray, 코어i3, 256GB, 8GB, Free DOS, Lenovo V15 G3 IAP - 82TT007PKR

레노버 2022 V15 G3 IAP, Iron Gray, 코어i3, 256GB, 8GB, Free DOS, Lenovo V15 G3 IAP - 82TT007PKR

https://link.coupang.com/a/6SUYG

 

레노버 2022 V15 G3 IAP

COUPANG

www.coupang.com

 

20230815 쿠팡 특가 공유합니다. 

 

평상시 보다 많이 저렴합니다 

^_^

 

 

이 포스팅은 쿠팡 파트너스 활동의 일환으로, 이에 따른 일정액의 수수료를 제공받습니다.

반응형

+ Recent posts