<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>hosung.log</title>
        <link>https://velog.io/</link>
        <description></description>
        <lastBuildDate>Sat, 26 Nov 2022 06:24:20 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>hosung.log</title>
            <url>https://images.velog.io/images/hack_ho/profile/5f7b1f0f-b792-4caf-b18c-6d6b8ce33fc2/KakaoTalk_20211012_164240724.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. hosung.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/hack_ho" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[HEROKU 명령어]]></title>
            <link>https://velog.io/@hack_ho/HEROKU-%EB%AA%85%EB%A0%B9%EC%96%B4</link>
            <guid>https://velog.io/@hack_ho/HEROKU-%EB%AA%85%EB%A0%B9%EC%96%B4</guid>
            <pubDate>Sat, 26 Nov 2022 06:24:20 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>자주 사용하는 명령어를 정리한 내용입니다.</p>
</blockquote>
<ul>
<li><p>서비스 중단</p>
<pre><code>$ heroku ps:scale web=0 --app [앱 이름]</code></pre></li>
<li><p>서비스 시작</p>
<pre><code>$ heroku ps:scale web=1 --app [앱 이름]</code></pre></li>
<li><p>로그 보기</p>
<pre><code>$ heroku logs --tail --app [앱 이름]</code></pre></li>
<li><p>깃 초기화</p>
<pre><code>$ git init</code></pre></li>
<li><p>커밋 &amp; push(배포까지)</p>
<pre><code>$ git add .
$ git commit -am &quot;코멘트&quot;
$ git push heroku master</code></pre></li>
<li><p>Clear</p>
<pre><code>$ heroku buildpacks:clear --app [앱이름];</code></pre></li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[HEROKU - WAR 배포]]></title>
            <link>https://velog.io/@hack_ho/HEROKU-WAR-%EB%B0%B0%ED%8F%AC</link>
            <guid>https://velog.io/@hack_ho/HEROKU-WAR-%EB%B0%B0%ED%8F%AC</guid>
            <pubDate>Sat, 26 Nov 2022 06:17:01 GMT</pubDate>
            <description><![CDATA[<p>먼저 이클립스를 통해 작업한 프로젝트를 war 로 추출한다.</p>
<p>그 다음 war 가 있는 위치로 이동한 후 아래와 같은 명령어를 입력한다.</p>
<p>*기본적으로 heroku login이 먼저 되어있어야 한다.</p>
<pre><code>heroku deploy:war [war파일명] -a [앱이름]</code></pre><p>아래와 같이 빌드 되는것을 볼수 있다.
<img src="https://velog.velcdn.com/images/hack_ho/post/c6370acf-aafc-4ca4-9c6a-2eb1107d8c53/image.png" alt=""></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[HEROKU-Spring boot 배포하기]]></title>
            <link>https://velog.io/@hack_ho/HEROKU</link>
            <guid>https://velog.io/@hack_ho/HEROKU</guid>
            <pubDate>Sat, 26 Nov 2022 04:52:19 GMT</pubDate>
            <description><![CDATA[<p>사전작업 : JawsDB를 만들어 외부에서도 사용가능한 DB를 만든다.</p>
<blockquote>
<ol>
<li>디렉토리를 먼저 만들어 준다.</li>
</ol>
</blockquote>
<p>git Repositories를 만들 디렉토리를 만들어 준다.</p>
<p>그 후 터미널을 열어 아래와 같은 명령어를 입력해준다.</p>
<pre><code>$ heroku login</code></pre><p>그 후 아까 만든 디렉토리로 경로를 이동 후 아래와 같은 명령어를 입력해준다.</p>
<pre><code>$ git init</code></pre><p>이 후 그 디렉토리에 아래 사진과 같이 spring boot 파일을 넣는다.
<img src="https://velog.velcdn.com/images/hack_ho/post/b2695f84-6378-4ba7-b8d2-28613adcfbb6/image.png" alt=""></p>
<p>그 후 아래와 같은 명령어를 입력한다.</p>
<pre><code>$ git add .
$ git commit -am &quot;코멘트&quot;
$ git push heroku master</code></pre><p>그럼 자동으로 빌드와 배포가 완료된다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Spring Boot Scheduling]]></title>
            <link>https://velog.io/@hack_ho/Spring</link>
            <guid>https://velog.io/@hack_ho/Spring</guid>
            <pubDate>Mon, 17 Oct 2022 13:07:53 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>Spring Boot 에서 스케줄 만들기</p>
</blockquote>
<p>다음 예제는 업비트 open api 와 Spring Boot의 스케쥴러 기능을 통하여 매 시간 마다 업비트의 다양한 정보를 Mysql 에 적재하는 방법을 서술한다.</p>
<pre><code>package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.example.demo.vo.UserInfo;
@EnableScheduling
@SpringBootApplication
public class StartApplication {

    public static void main(String[] args) {
        SpringApplication.run(StartApplication.class, args);
    }

}
</code></pre><p>먼저 spring boot 가 시작되는 지점에 &quot;@EnableScheduling&quot; 을 작성해준다. 그 이후 위 의 작성한 자바 파일과 같은 패키지에 스케줄 class를 아래와 같이 작성해준다. </p>
<pre><code>package com.example.demo;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.common.Common;
/**
 * 배치 목록입니다.
 * @author kimhosung
 *
 */
@Component
public class BatchScheduler {
    Logger logger = LoggerFactory.getLogger(this.getClass());


    // 업비트에 있는 종목정보를 가져옵니다.
    @Scheduled(fixedRate = 10000)
    public void scheduleFixedRateTask() {
            SimpleDateFormat sdf = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss.SSS&quot;);
            Date now = new Date();
            String strDate = sdf.format(now);
            System.out.println(&quot;작업 날짜 시간 fixedRate::&quot; + strDate);

            Common.openapi(&quot;http://localhost:8081/batch/list&quot;);
    }
}</code></pre><p>Common.openapi 메소드는 아래와 같이 작성하였다.</p>
<pre><code>package com.common;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
/**
 * 공통 메소드 
 * @author kimhosung
 *
 */
public class Common {

    //단순 url call 
    public static void openapi(String url) {
        try {
            HttpClient client = HttpClientBuilder.create().build();
            HttpGet request = new HttpGet(url);
            request.setHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);
            HttpResponse response = client.execute(request);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
</code></pre><p>그럼 결국 &quot;<a href="http://localhost:8081/batch/list&quot;">http://localhost:8081/batch/list&quot;</a> url 을 통해 아래와 같이 REST 방식으로 컨트롤러를 호출할것이다. 컨트롤러의 소스는 아래와 같다.</p>
<pre><code>package com.upbit.openapi;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.mapper.LoginMapper;
import com.example.demo.mapper.MarketListMapper;
import com.example.demo.vo.MartListVO;
import com.example.demo.vo.UserInfo;

@RestController
@CrossOrigin(origins = &quot;http://localhost:8080&quot;) // 컨트롤러에서 설정
@Service
public class BatchProgram {

    @Autowired
    MarketListMapper mrMapper;

    /*
     * 마켓의 종목의 명칭을 가져옵니다. 
     */
    @RequestMapping(value=&quot;/batch/list&quot;, method=RequestMethod.GET)
    public void testpp() {

        try {
            HttpClient client = HttpClientBuilder.create().build();
            HttpGet request = new HttpGet(&quot;https://api.upbit.com/v1/market/all&quot;);
            request.setHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);

            HttpResponse response = client.execute(request);
            HttpEntity entity = response.getEntity();
            String json = EntityUtils.toString(entity, &quot;UTF-8&quot;);

            JSONParser parser = new JSONParser();
            JSONArray jsonarray = (JSONArray) parser.parse(json);

            //테이블 초기
            mrMapper.initMarketList();

            for (int i = 0; i &lt; jsonarray.size(); i++) {
                JSONObject obj = (JSONObject) jsonarray.get(i);
                MartListVO vo = new MartListVO();
                vo.setMr_cd(obj.get(&quot;market&quot;).toString());
                vo.setEng_nm(obj.get(&quot;english_name&quot;).toString());
                vo.setKor_nm(obj.get(&quot;korean_name&quot;).toString());
                 try {
                     mrMapper.insertMarketList(vo);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }


        } catch (org.apache.http.ParseException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (org.json.simple.parser.ParseException e) {
            e.printStackTrace();
        }    
    }
}
</code></pre><p>여기서 중요하게 봐야될 부분은 json 형식의 파싱 방법이다.</p>
<p>JSONParser parser = new JSONParser();
            JSONArray jsonarray = (JSONArray) parser.parse(json);</p>
<p>  위와 같이 JSONParser를 만들고 JSON이 [] 로 시작한다면 배열이기 때문에 사용하였다.</p>
<p>  jsonarray에 String으로 된 json 을 담아 파싱한다.</p>
<p>  그 다음 아래와 같은 서비스를 호출하고 이 서비스는 @Mapper로 선언 되어있기 때문에 mapper 파일을 만들어 준다.</p>
<pre><code>package com.example.demo.mapper;


import org.apache.ibatis.annotations.Mapper;

import com.example.demo.vo.MartListVO;

@Mapper
public interface MarketListMapper {

    int insertMarketList(MartListVO vo);

    int initMarketList();
}
</code></pre><p>mapper.xml</p>
<pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;!DOCTYPE mapper PUBLIC &quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;
        &quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;&gt;

&lt;mapper namespace=&quot;com.example.demo.mapper.MarketListMapper&quot;&gt;

    &lt;insert id=&quot;insertMarketList&quot; parameterType=&quot;MartListVO&quot; &gt;
        INSERT INTO `shoppingMall`.`TB_MR_LIST`
        (`MR_CD`,
        `KOR_NM`,
        `ENG_NM`,
        `SYS_DT`)
        VALUES
        (#{mr_cd},
        #{kor_nm},
        #{eng_nm},
        sysdate())    
    &lt;/insert&gt;

    &lt;delete id=&quot;initMarketList&quot;&gt;
        TRUNCATE TB_MR_LIST;
    &lt;/delete&gt;
&lt;/mapper&gt;</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[특정구간의 합⭐⭐]]></title>
            <link>https://velog.io/@hack_ho/%ED%8A%B9%EC%A0%95%EA%B5%AC%EA%B0%84%EC%9D%98-%ED%95%A9arr</link>
            <guid>https://velog.io/@hack_ho/%ED%8A%B9%EC%A0%95%EA%B5%AC%EA%B0%84%EC%9D%98-%ED%95%A9arr</guid>
            <pubDate>Wed, 13 Oct 2021 07:27:13 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>배열의 구간 합을 계산할 때 부분 합을 미리 계산해두어 빠르게 값을 얻어내는 것</p>
</blockquote>
<p><strong>입력</strong>
첫 줄에 배열의 숫자 개수
다음 줄에 공백으로 구별하면서 배열에 수 입력
합을 구하고자 하는 구간</p>
<p><strong>출력</strong>
구간의 합</p>
<p><strong>코드</strong></p>
<pre><code>import java.io.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        int[] arr = new int[Integer.valueOf(input)];
        int result = 0;
        int i = 0;
        //배열 값넣기
        String arr_size = br.readLine();
        String[] arr_value = arr_size.split(&quot; &quot;);

        //구간의 합
        String sum_arr = br.readLine();
        String[] arr_sum = sum_arr.split(&quot; &quot;);


        for(i = 0; i &lt; arr_value.length; i++){
            if (i &gt;= Integer.valueOf(arr_sum[0])-1 &amp;&amp; i &lt;= Integer.valueOf(arr_sum[1])-1)
                result += Integer.valueOf(arr_value[i]);

        }
        System.out.println(result);

    }
}</code></pre><p>일단 입력받은 배열의 값들을 split으로 나누어 arr_value에 저장한다.
그 이후 더하는 시작지점, 종료지점을 조건문을 이용하여 그 사이값 만큼 result 에 더해주어 결과를 출력한다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[배열 합쳐서 정렬하기⭐⭐⭐]]></title>
            <link>https://velog.io/@hack_ho/%EB%B0%B0%EC%97%B4-%ED%95%A9%EC%B3%90%EC%84%9C-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@hack_ho/%EB%B0%B0%EC%97%B4-%ED%95%A9%EC%B3%90%EC%84%9C-%EC%A0%95%EB%A0%AC%ED%95%98%EA%B8%B0</guid>
            <pubDate>Wed, 13 Oct 2021 02:57:14 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>정렬된 배열A,B가 주어지면 배열을 합친 후 다시 정렬하는 프로그램을 작성하시오.</p>
</blockquote>
<p>일단 문제를 보고 정처기에서 나왔던 mergeSort 가 생각났지만 알고리즘 자체가 생각 나지 않았습니다...
어떤식으로 풀가 생각중 이전 ArrayList에서 정렬 하는 메소드를 썼던적이 있어서 그부분을 이용해서 풀어보겠습니다.</p>
<p>ps. 정답이 아닐수도 있어요 출제자의 의도는 이게 아닐거 거든요...</p>
<p><strong>입력</strong>
첫 번쨰 줄에 배열A, B의 크기 순서대로 입력
다음 줄에 배열 A의 내용, 그 다음 줄에 배열 B의 내용 입력</p>
<p><strong>출력</strong>
두 배열을 합친 결과 출력한다.</p>
<pre><code>import java.io.*;
import java.util.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        String[] Size = input.split(&quot; &quot;);

        int leng = Integer.valueOf(Size[0]) +  Integer.valueOf(Size[1]);


        ArrayList&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt;(leng);
        String input1= br.readLine();
        String[] Size1= input1.split(&quot; &quot;);
        for(int i = 0; i &lt; Size1.length; i++){
            arr.add(Integer.valueOf(Size1[i]));
        }
        String input2= br.readLine();
        String[] Size2= input2.split(&quot; &quot;);
        for(int i = 0; i &lt; Size2.length; i++){
            arr.add(Integer.valueOf(Size2[i]));
        }


        arr.sort(Comparator.naturalOrder());
        for(int i = 0; i &lt; arr.size(); i++){
            System.out.print(arr.get(i)+&quot; &quot;);
        }
    }
}</code></pre><p>일단 먼저 두 배열의 사이즈를 구하여서 leng에 저장한 다음 그 크기만큼 ArrayList를 만들어 줍니다.</p>
<p>그리고 ArrayList에 배열 A, B를 차곡차곡 넣어준 후
Comparator.naturalOrder() → 오름차순
Comparator.reverseOrder() → 내림차순
을 사용하여 정렬 후</p>
<p>순서대로 출력해줍니다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[완전수 구하기⭐⭐]]></title>
            <link>https://velog.io/@hack_ho/%EC%99%84%EC%A0%84%EC%88%98-%EA%B5%AC%ED%95%98%EA%B8%B0</link>
            <guid>https://velog.io/@hack_ho/%EC%99%84%EC%A0%84%EC%88%98-%EA%B5%AC%ED%95%98%EA%B8%B0</guid>
            <pubDate>Tue, 12 Oct 2021 18:19:50 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>문제 : 완전수 구하기</p>
</blockquote>
<p>완전수란 : 약수의 합의 내 자신과 같을때
Ex: 6은 완전수(1,2,3,6) → 1+2+3의 합이 6과 같기 때문</p>
<pre><code>import java.io.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        String[] num = input.split(&quot; &quot;);

        int start = Integer.valueOf(num[0]);
        int end = Integer.valueOf(num[1]);


            int sum=0;
            for(int i=start; i&lt;=end; i++) {
                    for(int j=1; j&lt;i; j++) {
                            //약수를 구하기
                            if(i%j==0) {
                                    //약수를 sum에 모두 더하기
                                    sum = sum + j;
                            }
                    }
                    if(sum==i) {
                            System.out.print(i + &quot; &quot;);
                    }
                    sum=0;
            }
    }
}</code></pre><ul>
<li>먼저 입력받은수를 &quot; &quot;공백으로 분리후 숫자로 변경 시켜줌 그 이후 그 값만큼 반복문</li>
<li>큰 수, 작은수 로 나누어 나누어 지면 약수이기 때문에 더해주고 그 합이 큰수(내자신)과 같으면 완전수이기 때문에 출력</li>
<li>그리고 합계 초기화</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[문자열 뒤집기⭐⭐]]></title>
            <link>https://velog.io/@hack_ho/%EB%AC%B8%EC%9E%90%EC%97%B4-%EB%92%A4%EC%A7%91%EA%B8%B0</link>
            <guid>https://velog.io/@hack_ho/%EB%AC%B8%EC%9E%90%EC%97%B4-%EB%92%A4%EC%A7%91%EA%B8%B0</guid>
            <pubDate>Tue, 12 Oct 2021 17:23:19 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>문제 : 입력받은 문자를 거꾸로 출력하세요~</p>
</blockquote>
<pre><code>import java.io.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        int lastpos = input.length()-1;

        while(true){
            System.out.print(input.charAt(lastpos--));;
            if(lastpos == -1) break;
        }

    }
}</code></pre><blockquote>
<p>해설</p>
</blockquote>
<p>이전 문자열 번갈아 출력하는 문제와 상당히 비슷하지만 이문제는 거꾸로만 출력하면 되기 때문에 시작 위치를 안만들고 lastpos(종료위치) 를 문자열의 길이-1 만큼 설정한다음 charAt을 통하여 거꾸로 출력하였습니다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[문자 번갈아 출력⭐⭐⭐]]></title>
            <link>https://velog.io/@hack_ho/%EB%AC%B8%EC%9E%90-%EB%B2%88%EA%B0%88%EC%95%84-%EC%B6%9C%EB%A0%A5</link>
            <guid>https://velog.io/@hack_ho/%EB%AC%B8%EC%9E%90-%EB%B2%88%EA%B0%88%EC%95%84-%EC%B6%9C%EB%A0%A5</guid>
            <pubDate>Tue, 12 Oct 2021 17:13:27 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>문제 : 문자가 들어오면 해당 문자를 번갈아가며 출력</p>
</blockquote>
<pre><code>import java.io.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();

        int start = 0;
        int end = input.length()-1; // 5


        while(true) {
                System.out.print(input.charAt(start++)); //0, 1, 2, 3
                System.out.print(input.charAt(end--));   //5, 4, 3, 2

                if(start == end ) {
                        System.out.print(input.charAt(start));
                        break;
                } else if(start &gt; end) 
                        break;
        }
    }
}</code></pre><p>해당 문자열의 길이를 먼저 파악한다음</p>
<ul>
<li>해당 문자 앞의 문자 하나</li>
<li>해당 문자 뒤의 문자 하나 
계속하여 출력 이때 반복과 증감연산자를 통하여 앞에서 이동하는 위치, 뒤에서 이동하는 위치 파악
앞, 뒤 위치의 값이 역전되면 반복문 빠져나오기</li>
</ul>
]]></description>
        </item>
        <item>
            <title><![CDATA[소수 판별⭐⭐]]></title>
            <link>https://velog.io/@hack_ho/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%AC%B8%EC%A0%9C</link>
            <guid>https://velog.io/@hack_ho/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98-%EB%AC%B8%EC%A0%9C</guid>
            <pubDate>Tue, 12 Oct 2021 16:56:00 GMT</pubDate>
            <description><![CDATA[<blockquote>
<p>문제 : 입력된 수가 소수인지 판별하세요</p>
</blockquote>
<p>소수란 1보다 큰 자연수중 1과 자기 자신만을 약수로 같는 수</p>
<pre><code>import java.io.*;
import java.util.*;
class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();


        int num = Integer.valueOf(input);
        int cnt = 0;
        int i = 0;
        for(i = 2; i &lt; num ; i++){
            if(num % i == 0) 
                cnt++;
        }

        if (cnt == 0)
            System.out.println(&quot;True&quot;);
        else
            System.out.println(&quot;False&quot;);
    }
}</code></pre><p>아주 쉬운문제...
해당 값을 입력 받은다음 그 값의 하위값들을 2로 나누었을때 하나라도 있으면 소수가 아니게 됩니다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Java Swing(Game1)]]></title>
            <link>https://velog.io/@hack_ho/%EA%B0%9C%EB%B0%9C%EC%9E%90%EA%B0%80-%EC%8B%AC%EC%8B%AC%ED%95%A0%EB%95%8C</link>
            <guid>https://velog.io/@hack_ho/%EA%B0%9C%EB%B0%9C%EC%9E%90%EA%B0%80-%EC%8B%AC%EC%8B%AC%ED%95%A0%EB%95%8C</guid>
            <pubDate>Tue, 12 Oct 2021 16:07:25 GMT</pubDate>
            <description><![CDATA[<blockquote>
</blockquote>
<ul>
<li>박스의 객체를 쓰레드를 사용하여 계속하여 움직여줌</li>
<li>박스, 사람의 객체를 만들어 크기 지정- 키 이벤트를 통하여 사람 움직임</li>
</ul>
<blockquote>
<p>Result</p>
</blockquote>
<p><img src="https://images.velog.io/images/hack_ho/post/60f68498-d713-49e0-9066-d00e3489137e/image.png" alt=""></p>
<blockquote>
<h4 id="code">Code</h4>
</blockquote>
<pre><code>    public GameScreen() throws InterruptedException {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(300,500);
        setTitle(&quot;박스피하기&quot;);
        setLocationRelativeTo(null);
        gamePanel = new JPanel();
        gamePanel.setLayout(null);
        player = new Man();
        score = new Score();
        gamePanel.add(player);
        gamePanel.add(score);
        add(gamePanel);
        addKeyListener(this);
        setVisible(true);

        while(nowplay)
        {
            Bomb bomb = new Bomb();
            Thread newthread = new Thread(bomb);
            gamePanel.add(bomb);
            newthread.start();            
            Thread.sleep(1000);
        }
        gameOver();
    }
</code></pre><p><strong>기본적으로 Jframe을 이용하여 게임의 판을 만들고 nowplay(게임의 상태를 통해) 박스 객체를 쓰레드를 통해 시작시킴 이때 박스의 생성 시간은 Thread.sleep(1000); 1초로 지정</strong></p>
<pre><code>    //개임종료
    public static void gameOver()
    {
        JLabel over = new JLabel(&quot;Game Over&quot;);
        over.setSize(200, 40);
        over.setLocation(110,200);
        gamePanel.add(over);
        gamePanel.repaint();
    }</code></pre><p><strong>게임 종료시 Jlable을 통해 게임의 종료를 나타냄</strong></p>
<pre><code>class Bomb extends JLabel implements Runnable{
        int Image_w=18;
        int Image_h=18;
        Bomb()
        {
            super(new ImageIcon(&quot;.\\res\\images\\box.png&quot;));
            int x = (int)(Math.random()*(gamePanel.getWidth()-20));
            setLocation(x,0);
            setSize(Image_w,Image_h);
        }
        public void run() {
            try {
                while(GameScreen.nowplay){
                    Thread.sleep(100);
                    Point now = getLocation();
                    now.y+=10;
                    if(now.y&gt;=(gamePanel.getHeight()+10))
                    {GameScreen.score.upScore(10);break;}
                    setLocation(now);
                    Point playerL=GameScreen.player.getLocation();
                    Point bombL=getLocation();
                    int bombLeft=bombL.x;
                    int bombRight=bombL.x+Image_w;
                    int bombTop=bombL.y;
                    int bombBottom=bombL.y+Image_h;
                    int playerLeft=playerL.x;
                    int playerRight=playerL.x+GameScreen.player.Image_w-2;
                    int playerTop=playerL.y;
                    int playerBottom=playerL.y+GameScreen.player.Image_h-2;
                    boolean collision = true;
                    if(bombRight&lt;playerLeft)
                        collision=false;
                    else if(bombLeft&gt;playerRight)
                        collision=false;
                    else if(bombBottom&lt;playerTop)
                        collision=false;
                    else if(bombTop&gt;playerBottom)
                        collision=false;
                    if(collision==true){
                        System.out.println(&quot;충돌&quot;);
                        GameScreen.nowplay=false;
                    }
                }
            }
            catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
        }        
    }</code></pre><p><strong>해당 코드는 박스의 객체 생성 가로 새로 18로 지정한 이유는 아래와 같이 18픽셀로 되어 있기 때문입니다.
중요 포인트는 랜덤값을  이용하여 X(가로) 위치에 박스를 생성한뒤 플레이어 객체의 위치와 같아지기 전까지 박스의 Y(세로축을) 계속하여 더해줌으로써 박스를 아래로 이동시킴</strong>
<img src="https://images.velog.io/images/hack_ho/post/36f2274e-7a5a-406c-b0b0-04881b886897/image.png" alt=""></p>
<pre><code>    //사람 객체
    class Man extends JLabel
    {
        int Image_w=26;
        int Image_h=56;
        Man()
        {
            super(new ImageIcon(&quot;.\\res\\images\\man2.png&quot;));
            setLocation(0,400);
            setSize(Image_w,Image_h);
        }
        public void moveLeft()
        {
            Point now = getLocation();            
            if(now.x&gt;0)
                setLocation(now.x-5,now.y);
        }
        public void moveRight()
        {
            Point now = getLocation();
            if(now.x&lt;(GameScreen.gamePanel.getWidth()-(Image_w)))
                setLocation(now.x+5,now.y);
        }
    }
        //키 이벤트
    @Override
    public void keyPressed(KeyEvent arg0) {
        // TODO Auto-generated method stub
        switch(arg0.getKeyCode()){
        case KeyEvent.VK_LEFT: //왼쪽 키
            player.moveLeft();
            break;
        case KeyEvent.VK_RIGHT: //오른쪽 방향키
            player.moveRight();
            break;    
        }
    }</code></pre><p><strong>사람 객체의 방향키를 통하여 5씩 이동시킴 키이벤트 오바라이딩을 통하여 이벤트 활성화</strong></p>
<pre><code>    //점수판
    class Score extends JLabel
    {
        Score()
        {
            super(&quot;000&quot;);
            setLocation(250,20);
            setSize(28,10);
        }
        public void upScore(int score)
        {
            int now = Integer.parseInt(getText());
            now+=score;
            setText(Integer.toString(now));
        }
    }</code></pre><p><strong>점수는 위의 박스 객체의 RUN() 메소드에서 해당 사람 객체를 지나치면 10 씩 더해줌</strong></p>
]]></description>
        </item>
        <item>
            <title><![CDATA[XSS(크로스사이트 스크립트)]]></title>
            <link>https://velog.io/@hack_ho/XSS%ED%81%AC%EB%A1%9C%EC%8A%A4%EC%82%AC%EC%9D%B4%ED%8A%B8-%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8</link>
            <guid>https://velog.io/@hack_ho/XSS%ED%81%AC%EB%A1%9C%EC%8A%A4%EC%82%AC%EC%9D%B4%ED%8A%B8-%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8</guid>
            <pubDate>Tue, 12 Oct 2021 08:39:15 GMT</pubDate>
            <description><![CDATA[<p>크로스사이트 스크립트는 SQL Injection과 다르게 JS태그 구문의 오류를 이르키는 방법을 말합니다.</p>
<p>예를 들어 게시판에 입력창에 정상적인 제목을 입력하는게 아닌 </p>
<pre><code>&lt;script&gt;alert(&quot;XSS 공격!!!&quot;);&lt;/script&gt;</code></pre><p>이런식으로 입력하게 된다면 게시판에 내용에는 내용이 보여주는것이 아닌 스크립트 코드가 실행되어 해당 페이지를 오픈할때 마다 Alert 메시지가 나타날 것입니다. 이밖에 location.href 등을 활용하여 해당 페이지를 절때 열수 없게 할수도 있겠네요...</p>
<p>이러한 방법을 막기위해선 여러 방법들이 있지만 저는 해당 &lt;&gt; 태그의 문자를 문자열로 바꾸어 태그로 인식할수 없도록 하였습니다.</p>
<pre><code>    var filter = title.replace(/&lt;/g, &quot;&amp;lt;&quot;).replace(/&gt;/g, &quot;&amp;gt;&quot;); //xss 필터
    title = filter; //xss 필터된 내용 넣기   &lt; → 문자형태의 &#39;&lt;&#39;, &gt; → 문자형태의 &#39;&gt;&#39;
    location.href = &quot;UpdateSql.jsp?no=&quot;+no+&quot;&amp;title=&quot; + title +&quot;&amp;content=&quot; + result;</code></pre><p>filter 에 들어온 값이 게시판에 제목에 넣을 입력값이라고 생각하시면 됩니다.
해당 데이터에 &lt; 나 &gt; 문자열이 있으면 문자형태로 변경하여 태그로 인식되지 못하게 하는 코드입니다.
게시판으로 예를 들었지만 내가 데이터를 입력하여 태크 형태로 보여주는 곳은 XSS 공격이 가능하니 주의하여 개발하시면 될거같습니다.</p>
]]></description>
        </item>
        <item>
            <title><![CDATA[SQL Injection]]></title>
            <link>https://velog.io/@hack_ho/SQL-Injection</link>
            <guid>https://velog.io/@hack_ho/SQL-Injection</guid>
            <pubDate>Tue, 12 Oct 2021 08:29:33 GMT</pubDate>
            <description><![CDATA[<p>SQL Injection 은 말 그대로 SQL 구문의 취약점을 이용하여 공격하는 방식입니다.
예를 들어 로그인시 해당 유저의 아이디와 패스워드가 맞는지  검사하기 위해 아래와 같은 구문을 사용할 것으로 생각됩니다.</p>
<p><strong>//SELECT * FROM USER WHERER ID=&#39;&#39; AND PW =&#39;&#39;;
**
만약 아이디 입력창에 TESTID&#39; 를 입력하게 되면 &#39;가 하나 더찍혀서 오류
**//SELECT * FROM USER WHERER ID=&#39;TESTID&#39;&#39; AND PW =&#39;&#39;;</strong></p>
<p>만약 아이디 입력창에 &#39; or 1=1# 를 입력하게 되면 # 뒤로 주석처리 되어서 전체 데이터가 출력되어 로그인이 될수 있습니다.
<strong>//SELECT * FROM USER WHERER ID=&#39;&#39; or 1=1#&#39; AND PW =&#39;&#39;;</strong></p>
<p>그 외 여러가지 sql injection 방법들이 있습니다. 이러한 부분을 조금이라도 해결하기 위해서는 S<strong>tatement 클래스가 아닌
PreparedStatement 를 사용하여</strong> 해당 아이디와 패스워드를 인자값으로 받아서 위와 같은 부분을 해결할수 있었습니다. 
(해당 테스트는 Mysql, Eclipse, JDBC 사용하였습니다.)</p>
<pre><code>//SQL Injection 방지
PreparedStatement stmt = con.prepareStatement(&quot;select * from member where id=? and pw=?&quot;);
stmt.setString(1, id);
stmt.setString(2, pw);</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[Travel Guide]]></title>
            <link>https://velog.io/@hack_ho/PortfolioTravel-Guide</link>
            <guid>https://velog.io/@hack_ho/PortfolioTravel-Guide</guid>
            <pubDate>Tue, 12 Oct 2021 08:05:27 GMT</pubDate>
            <description><![CDATA[<p><img src="https://images.velog.io/images/hack_ho/post/1836135e-6da3-4d99-9f86-f7fbfdb8e001/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/07ac34a6-59f5-4a22-a873-7088243921a2/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/623374a6-0b04-41e1-9cb4-2b32ec674090/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/6092560d-38d0-4045-ab51-827d87da6438/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/5cae44b2-16e8-442f-ab26-c28d391bc5fb/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/94c12774-a50d-4de6-8a7b-41503e40e85b/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/9d97c52a-5793-42c0-bdd3-ee7137f81f22/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/677bab60-83b7-4bd9-8512-a24fd69fa73a/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/6a62b247-a502-45fc-83fa-a2595f00fa09/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/69fde710-9071-465a-9ba0-850149f895a0/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/0f9512fb-485c-40f7-b33f-e4062927de91/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/9839024c-836b-46c8-ae3f-282fa8c88942/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/1dd13935-6fa5-4df3-8fc1-8c0ad142cb7a/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/b4fa2e93-1799-45a7-8933-1c121725d74e/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/ac7c15ce-d099-4462-8b0b-54c87e1a03d7/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/5804dc65-ced9-4a0f-be8a-e5e0a49326a0/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/754774fd-1cc9-4c13-9d38-0945b46365b0/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/e6f75245-1f3d-4e19-bca7-6eb7b1783e6a/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/53cb218a-c68a-435e-b812-96aa69549619/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/ceb2475d-b296-46cf-b248-378cd0d23b02/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/c61cbd8d-07ae-4d45-beb9-57c4a21b740d/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/cd6b2d78-66a8-4112-87a4-18a6a1365c1b/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/db2fd7ca-77b5-46c4-8483-d4c7cd2b4b2f/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/e2ea5b88-d09b-47d7-bdb4-621a435fceb7/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/b9878a66-b2a8-4218-8e69-c47c1244fd19/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/80cbd5ed-69fd-4cda-8393-14298828119c/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/bed57849-0978-4348-88a1-a5a6afb34a26/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/987b0ae3-8428-472a-b3ad-9b431566d260/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/c5ebc173-afdf-401a-8a40-1ca2d1fb999b/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/d4269b78-33d9-44b0-b12a-cbfefd7850b6/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/c36f914d-1a7a-4510-bf3d-fc209794ff8f/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/305412c9-b13d-422e-bede-0bad06e7e13b/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/a2b943c6-2c8b-4402-bd13-dca53d63be48/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/46fd0e6c-6fef-4ca6-a1b5-acbe880d821b/image.png" alt="">
<img src="https://images.velog.io/images/hack_ho/post/a2983be0-080c-47a6-89f0-0b34d3517156/image.png" alt=""></p>
]]></description>
        </item>
    </channel>
</rss>