0301 - 0307


# 0301 - 0307

# 0301 - Spring boot & Mybatis

# @MapperScan

@MapperScan(basePackages = "co.worker.sponge_scheduler.repository")

# mybatis properties

mybatis.type-aliases-package=co.worker.sponge_scheduler.model
mybatis.mapper-locations=mybatis-mapper/**/*.xml
#mybatis.type-handlers-package=com.example.typehandler
mybatis.configuration.map-underscore-to-camel-case=true
#mybatis.configuration.default-fetch-size=100
#mybatis.configuration.default-statement-timeout=30

# @Mapper

# mapper.xml

  • namespace


# 0302 - quartz-scheduler

# ๊ตฌ์กฐ

# Job

Quartz API์—์„œ ๋‹จ ํ•˜๋‚˜์˜ ๋ฉ”์„œ๋“œ execute(JobExecutionContext context)๋ฅผ ๊ฐ€์ง„ Job ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•œ๋‹ค. Quartz๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฐœ๋ฐœ์ž๋Š” ์ˆ˜ํ–‰ํ•ด์•ผ ํ•˜๋Š” ์‹ค์ œ ์ž‘์—…์„ ์ด ๋ฉ”์„œ๋“œ์—์„œ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค.

# JobDetail

Job์„ ์‹คํ–‰์‹œํ‚ค๊ธฐ ์œ„ํ•œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ๊ฐ์ฒด์ด๋‹ค. Job์˜ ์ด๋ฆ„, ๊ทธ๋ฃน, JobDataMap ์†์„ฑ ๋“ฑ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. Trigger๊ฐ€ Job์„ ์ˆ˜ํ–‰ํ•  ๋•Œ ์ด์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ์Šค์ผ€์ค„๋ง์„ ํ•œ๋‹ค.

# JobDataMap

JobDataMap์€ Job ์ธ์Šคํ„ด์Šค๊ฐ€ execute ์‹คํ–‰ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ฒŒ ์›ํ•˜๋Š” ์ •๋ณด๋ฅผ ๋‹ด์„ ์ˆ˜ ์žˆ๋Š” ๊ฐ์ฒด์ด๋‹ค. JobDetail์„ ์ƒ์„ฑํ•  ๋•Œ JobDataMap๋„ ๊ฐ™์ด ์„ธํŒ…ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

# Trigger

Trigger๋Š” Job์„ ์‹คํ–‰์‹œํ‚ฌ ์Šค์ผ€์ค„๋ง ์กฐ๊ฑด(ex. ๋ฐ˜๋ณต ํšŸ์ˆ˜, ์‹œ์ž‘์‹œ๊ฐ„) ๋“ฑ์„ ๋‹ด๊ณ  ์žˆ๊ณ  Scheduler๋Š” ์ด ์ •๋ณด๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ Job์„ ์ˆ˜ํ–‰์‹œํ‚จ๋‹ค. N Trigger = 1 Job ๋ฐ˜๋“œ์‹œ ํ•˜๋‚˜์˜ Trigger๋Š” ๋ฐ˜๋“œ์‹œ ํ•˜๋‚˜์˜ Job์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. SimpleTrigger - ํŠน์ •์‹œ๊ฐ„์— Job์„ ์ˆ˜ํ–‰ํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋ฉฐ ๋ฐ˜๋ณต ํšŸ์ˆ˜์™€ ์‹คํ–‰ ๊ฐ„๊ฒฉ๋“ฑ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค CronTrigger - CronTrigger๋Š” cron ํ‘œํ˜„์‹์œผ๋กœ Trigger๋ฅผ ์ •์˜ ํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค.



# 0303 - arrow function expression

# ์ผ๋ฐ˜ ํ•จ์ˆ˜์™€ ์ฐจ์ด์ 

  • this๋ฅผ ๊ฐ€์ง€์ง€ ์•Š๋Š”๋‹ค.
  • arguments๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • new์™€ ํ•จ๊ป˜ ํ˜ธ์ถœํ•  ์ˆ˜ ์—†๋‹ค.
  • super๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š”๋‹ค.


  • ํŠน์ง•
    • ์›น ์š”์ฒญ์€ ์ฟ ํ‚ค ์ •๋ณด๋ฅผ ํฌํ•จํ•˜์—ฌ ์„œ๋ฒ„์— ์ „์†ก
    • ๊ฐœ์ˆ˜์™€ ์šฉ๋Ÿ‰์— ์ œํ•œ
    • ์œ ํšจ๊ธฐ๊ฐ„
  • ์žฅ์ 
    • ์žฅ์  : ๋Œ€๋ถ€๋ถ„์˜ ๋ธŒ๋ผ์šฐ์ € ์ง€์›
    • ๋‹จ์  : api๊ฐ€ ํ•œ๋ฒˆ ๋” ํ˜ธ์ถœ - ์„œ๋ฒ„์— ๋ถ€๋‹ด

# WebStorage

  • ํŠน์ง•
    • ์ €์žฅ ๋ฐ์ดํ„ฐ๊ฐ€ ํด๋ผ์ด์–ธํŠธ์—๋งŒ ์กด์žฌ - ์„œ๋ฒ„๋กœ ์ „์†กํ•˜์ง€ ์•Š๋Š”๋‹ค.
    • ์šฉ๋Ÿ‰์˜ ์ œํ•œ์ด ์—†๋‹ค
    • ์ €์žฅํ•œ ๋ฐ์ดํ„ฐ๋Š” ์˜๊ตฌ์ ์œผ๋กœ ์กด์žฌ
    • ๋„๋ฉ”์ธ์„ ๊ธฐ์ค€
    • HTML4๋งŒ ์ง€์›๋˜๋Š” ๋ธŒ๋ผ์šฐ์ €์—๋Š” ์ง€์›์ด ์•ˆ๋จ
  • LocalStorage
    • ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ข…๋ฃŒํ•ด๋„ ๋ฐ์ดํ„ฐ๋Š” ๋ณด๊ด€
localStorage.setItem("key", "value");
localStorage.getItem("key");
localStorage.removeItem("key");
localStorage.clear();
  • SessionStorage
    • ์„ธ์…˜์ข…๋ฃŒ์‹œ ์ •๋ณด ์‚ญ์ œ(๋ธŒ๋ผ์šฐ์ €๋ฅผ ๋‹ซ์„๊ฒฝ์šฐ)
sessionStorage.setItem("key", "value");
sessionStorage.getItem("key");
sessionStorage.removeItem("key");
sessionStorage.clear();


# 0305 - OS๋ณ„ ํฌํŠธ. ํ”„๋กœ์„ธ์Šค ํ™•์ธ

# mac

  • ํฌํŠธ ํ™•์ธ
    lsof -i : {port}
  • ํ”„๋กœ์„ธ์Šค ํ™•์ธ
    ps -ef | grep
  • ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ
    kill -9 {PID}

# window

  • ํฌํŠธ ํ™•์ธ
    netstat -ano | findstr {port}
  • ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ
    taskkill /f /pid {PID}

# linux

  • ํฌํŠธ ํ™•์ธ
    netstat -tnlp | grep {port}
  • ํ”„๋กœ์„ธ์Šค ํ™•์ธ
    ps -ef | grep
  • ํ”„๋กœ์„ธ์Šค ์ข…๋ฃŒ
    kill -9 {PID}


# 0306 - enum

# ์‚ฌ์šฉ๋ชฉ์ 

  1. ์ƒ์ˆ˜๋ฅผ ํ‘œํ˜„ํ•˜๊ธฐ์— ์ฝ”๋“œ๊ฐ€ ๋‹จ์ˆœํ•ด์ง€๋ฉฐ ๊ฐ€๋…์„ฑ์ด ์ข‹๋‹ค.
  2. ์ธ์Šคํ„ด์Šค ์ƒ์„ฑ๊ณผ ์ƒ์†์„ ๋ฐฉ์ง€.
  3. ํ‚ค์›Œ๋“œ enum์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ตฌํ˜„์˜ ์˜๋„๊ฐ€ ์—ด๊ฑฐ์ž„์„ ๋ถ„๋ช…ํ•˜๊ฒŒ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์Œ.

# enum ํŠน์ง•

  • enum์˜ ๊ฒฝ์šฐ ๋””ํดํŠธ ์ƒ์„ฑ์ž์˜ ์ ‘๊ทผ ์ œ์–ด์ž๊ฐ€ private, ์ปดํŒŒ์ผํƒ€์ž„์— ๋ชจ๋“  ๊ฐ’์„ ์•Œ๊ณ  ์žˆ์–ด์•ผ ํ•˜๋ฉฐ ๋™์ ์œผ๋กœ ๊ฐ’์„ ํ• ๋‹น ํ•ด์„œ ์•ˆ๋จ.

# ๋ฉ”์†Œ๋“œ

  • values() ๋ชจ๋“  ์ƒ์ˆ˜ ๋ฐ˜ํ™˜
  • ordinal() ์ƒ์ˆ˜ ์ธ๋ฑ์Šค ๋ฐ˜ํ™˜
  • valueOf() ์ƒ์ˆ˜ ๋ฌธ์ž ๊ฐ’ ๋ฐ˜ํ™˜

# ์˜ˆ์ œ

    public enum  Winner {
    	WINNER("์Šน๋ฆฌ", Arrays.asList("kyle","pobi","hello","world")),
    	LOSER("ํŒจ๋ฐฐ", Arrays.asList("hodol","dunddoung","rutgo");
    
    	private final String winner;
    	private final List<String> list;
    
    	Winner(String winner, List<String> list) {
    		this.winner = winner;
    		this.list = list;
    	}
    }  
    public enum Statistic {
    	THREE(3, 5000),
    	FOUR(4, 50_000),
    	FIVE(5, 1_500_000),
    	BONUS(5, 3_000_000),
    	SIX(6, 2_000_000_000);
    
    	private final int matchingNumbers;
    	private final int prize;
    
    	Statistic(int matchingNumbers, int prize) {
    		this.matchingNumbers = matchingNumbers;
    		this.prize = prize;
    	}
    
    public static Statistic getRank(int numberOfMatch) {
    		return Arrays.stream(values())
    			.filter(statistic -> statistic.matchingNumbers == numberOfMatch)
    			.findFirst()
    			.orElseThrow(new IllegalArgumentException("์ผ์น˜ํ•˜๋Š” ๋ฒˆํ˜ธ๊ฐ€ 3๋ฏธ๋งŒ์ž…๋‹ˆ๋‹ค."))
    	}
    import java.util.function.BiFunction;
    
    public enum Operator {
    	PLUS("๋”ํ•˜๊ธฐ", (a, b) -> (a + b)),
    	MINUS("๋นผ๊ธฐ", (a, b) -> (a - b)),
    	MULTIPLY("๊ณฑํ•˜๊ธฐ", (a, b) -> (a * b)),
    	DIVIDE("๋‚˜๋ˆ„๊ธฐ", (a, b) -> (a / b));
    
    	private final String name;
    	private final BiFunction<Double, Double, Double> biFunction;
    
    	Operator(String name, BiFunction<Double, Double, Double> biFunction) {
    		this.name = name;
    		this.biFunction = biFunction;
    	}
    
    	public Double calculate(double a, double b) {
    		return this.biFunction.apply(a,b);
    	}
    }

๊ณ ๊ธ‰ (opens new window)



# 0307 - Builder

๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ• ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํŒจํ„ด์ค‘ ํ•˜๋‚˜

# ๊ฐ์ฒด ์ƒ์„ฑ ํŒจํ„ด

  • ์ ์ธต์  ์ƒ์„ฑ์ž ํŒจํ„ด > ๊ฐ€๋…์„ฑ ๋ฐ ์ธ์ž์˜ ์ˆ˜๋งŒํผ ์ƒ์„ฑ์ž ์ˆซ์ž๊ฐ€ ๋งŽ์•„์ง
  • ์ž๋ฐ”๋นˆ ํŒจํ„ด > setter ๋ฉ”์†Œ๋“œ ์‚ฌ์šฉ์œผ๋กœ ๊ฐ์ฒด ์ผ๊ด€์„ฑ์ด ๋ถˆํ™•์‹ค
  • ๋นŒ๋” ํŒจํ„ด

# ์˜ˆ์ œ

// Effective Java์˜ Builder Pattern
public class NutritionFacts {
    private final int servingSize;
    private final int servings;
    private final int calories;
    private final int fat;
    private final int sodium;
    private final int carbohydrate;

    public static class Builder {
        // Required parameters(ํ•„์ˆ˜ ์ธ์ž)
        private final int servingSize;
        private final int servings;

        // Optional parameters - initialized to default values(์„ ํƒ์  ์ธ์ž๋Š” ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ ์ดˆ๊ธฐํ™”)
        private int calories      = 0;
        private int fat           = 0;
        private int carbohydrate  = 0;
        private int sodium        = 0;

        public Builder(int servingSize, int servings) {
            this.servingSize = servingSize;
            this.servings    = servings;
        }

        public Builder calories(int val) {
            calories = val;
            return this;    // ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด . ์œผ๋กœ ์ฒด์ธ์„ ์ด์–ด๊ฐˆ ์ˆ˜ ์žˆ๋‹ค.
        }
        public Builder fat(int val) {
            fat = val;
            return this;
        }
        public Builder carbohydrate(int val) {
            carbohydrate = val;
            return this;
        }
        public Builder sodium(int val) {
            sodium = val;
            return this;
        }
        public NutritionFacts build() {
            return new NutritionFacts(this);
        }
    }

    private NutritionFacts(Builder builder) {
        servingSize  = builder.servingSize;
        servings     = builder.servings;
        calories     = builder.calories;
        fat          = builder.fat;
        sodium       = builder.sodium;
        carbohydrate = builder.carbohydrate;
    }
}
NutritionFacts facts = NutritionFacts.builder()
    .calories(230)
    .fat(10)
    .build();

# lombok ์‚ฌ์šฉ

  • @Builder
    • ํด๋ž˜์Šค ์œ„ ์„ ์–ธ๋ณด๋‹ค๋Š” ์‚ฌ์šฉํ•˜๊ณ ์žํ•˜๋Š” ์ƒ์„ฑ์ž ์œ„์— ์„ ์–ธ
Last update: September 13, 2022 21:44
Contributors: ahnjs , jaesungahn91