์ „์ฒด ๊ธ€ 62

[์ž๋ฐ”์›น๊ฐœ๋ฐœ์›Œํฌ๋ถ] 2. ์›น๊ณผ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค

/* * * ์ž๋ฐ”์›น๊ฐœ๋ฐœ์›Œํฌ๋ถ์˜ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ํฌ์ŠคํŒ…์ž…๋‹ˆ๋‹ค. * MariaDB, JDBC, Lombok, ConnectionPool, VO/DTO, CRUD์˜ˆ์ œ, Log4j2 */ 1. @Test : ํ…Œ์ŠคํŠธ์ฝ”๋“œ ํ˜น์€ ํ…Œ์ŠคํŠธ๋ฉ”์†Œ๋“œ๋ผ๊ณ  ํ•˜๋Š”๋ฐ @Test๋ฅผ ์ ์šฉํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋Š” ๋ฐ˜๋“œ์‹œ public์œผ๋กœ ์„ ์–ธ๋˜์–ด์•ผ ํ•˜๊ณ , ํŒŒ๋ผ๋ฏธํ„ฐ๋‚˜ ๋ฆฌํ„ดํƒ€์ž…์ด ์—†์ด ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. 2. Assertions.assertEquals() : ๋ง๊ทธ๋Œ€๋กœ '๊ฐ™๋‹ค๊ณ ํ™•์‹ ํ•œ๋‹ค'๋Š” ์˜๋ฏธ์ด๊ณ , ๋‘๋ณ€์ˆ˜์˜ ๋‚ด์šฉ์ด ๊ฐ™์•„์•ผ๋งŒ ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. EX) Assertions.assertEquals(v1, v2); 3. ์ฝ”๋“œ์„ค๋ช… @Test public void testConnection() throws Exception { Class.forName("org..

[์ž๋ฐ”์›น๊ฐœ๋ฐœ์›Œํฌ๋ถ] 1. ์›นํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ์‹œ์ž‘

/* * * ์ž๋ฐ”์›น๊ฐœ๋ฐœ์›Œํฌ๋ถ์˜ ๋‚ด์šฉ์„ ์ •๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ํฌ์ŠคํŒ…์ž…๋‹ˆ๋‹ค. * ์„œ๋ธ”๋ฆฟ/JSP, GET/POST, PRGํŒจํ„ด, HTTPServlet, EL/JSTL */ 1. intellij๋ฅผ ํ†ตํ•ด ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ์‹œ 'Jakarta EE'ํ•ญ๋ชฉ์œผ๋กœ ์ƒ์„ฑํ•˜๋ ค๋ฉด Java Enterprise๋กœ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. 2. ํ†ฐ์บฃ9๋ฒ„์ „์„ ์‚ฌ์šฉํ•œ ์ด์œ  : ํ†ฐ์บฃ10๋ฒ„์ „์€ ์„œ๋ธ”๋ฆฟ ๋ฒ„์ „์ด 5๋ฒ„์ „์œผ๋กœ ์‹œ์ž‘๋˜๋ฉด์„œ javax๊ฐ€ ์•„๋‹Œ jakarta๋กœ ์‹œ์ž‘๋˜๋Š” ํ˜•ํƒœ๋กœ ํŒจํ‚ค์ง€๋ช…์ด ๋ณ€๊ฒฝ๋˜์–ด ์„œ๋ธ”๋ฆฟ์„ ์ž‘์„ฑํ•  ๋•Œ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. 3. intellij์—์„œ exploded๋œ artifact๋ฅผ ๋ชป์ฐพ๋Š” ๋ฌธ์ œ๋ฐœ์ƒ : ๊ธด ๊ฒฝ๋กœ๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ๊ธฐ์œ„ํ•ด ๊ธฐ์กด '.war'๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  artifact๋ฅผ (exploded)๊ฐ€ ํฌํ•จ๋œ ํ•ญ๋ชฉ์œผ๋กœ ์ง€์ • ํ›„ ์‹คํ–‰์‹œ์ผฐ๋”๋‹ˆ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ..

๋กœ์ปฌ์—์„œ CORS policy๊ด€๋ จ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š” ์ด์œ 

๋‹ค์Œ htmlํŒŒ์ผ์„ ๋กœ์ปฌํ™˜๊ฒฝ์—์„œ ํฌ๋กฌ๋ธŒ๋ผ์šฐ์ €๋กœ ์‹คํ–‰ ์‹œ์ผฐ๋”๋‹ˆ Access to script at 'file:///๊ฒฝ๋กœ/hello.js' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https, isolated-app. ์ด์™€ ๊ฐ™์€ ์—๋Ÿฌ๋ฉ”์‹œ์ง€๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. 1. ๋ฐœ์ƒ์›์ธ ์˜ ํŠน์„ฑ ๋จผ์ € MDN์˜ javascript modules์— ๊ด€ํ•œ ์„ค๋ช…์— ๋”ฐ๋ฅด๋ฉด ๋ฌธ์ œ๊ฐ€ ๋œ ๋ถ€๋ถ„๊ฐ™์ด type์„ module๋กœ ์„ค์ •ํ•œ ํƒœ๊ทธ๊ฐ€ ํฌํ•จ๋œ HTML ํŒŒ์ผ์„ ๋กœ์ปฌ์—์„œ ๋กœ๋“œํ•  ๊ฒฝ์šฐ..

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋น„๋™๊ธฐ์ฒ˜๋ฆฌ(Promise, async, await)

์ฃผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ž‘์—…๋“ค์„ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. Ajax Web API ์š”์ฒญ ์„œ๋ฒ„์ชฝ์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์™€์•„์•ผ ํ•  ๋•Œ, ์š”์ฒญ์„ ํ•˜๊ณ  ์„œ๋ฒ„์—์„œ ์‘๋‹ต์„ ํ•  ๋•Œ ๊นŒ์ง€ ๋Œ€๊ธฐ๋ฅผ ํ•ด์•ผ ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ž‘์—…์„ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ผ ์ฝ๊ธฐ ์ฃผ๋กœ ์„œ๋ฒ„ ์ชฝ์—์„œ ํŒŒ์ผ์„ ์ฝ์–ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์—๋Š” ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ์•”ํ˜ธํ™”/๋ณตํ˜ธํ™” ์•”ํ˜ธํ™”/๋ณตํ˜ธํ™”๋ฅผ ํ•  ๋•Œ์—๋„ ๋ฐ”๋กœ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์ง€ ์•Š๊ณ , ์‹œ๊ฐ„์ด ์–ด๋Š์ •๋„ ๊ฑธ๋ฆฌ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ์ž‘์—… ์˜ˆ์•ฝ ๋‹จ์ˆœํžˆ ์–ด๋–ค ์ž‘์—…์„ ๋ช‡์ดˆ ํ›„์— ์Šค์ผ€์ฅด๋ง ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์—๋Š”, setTimeout ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋น„๋™๊ธฐ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๋น„๋™๊ธฐ ์ž‘์—…์„ ๋‹ค๋ฃฐ ๋•Œ์—๋Š” callback ํ•จ์ˆ˜ ์™ธ์—๋„ Promise, ๊ทธ๋ฆฌ๊ณ  async/await ๋ผ๋Š” ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜์—ฌ ์ฒ˜๋ฆฌ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ..

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ Scope์— ๋Œ€ํ•œ ์ดํ•ด

1. Scope ๋ž€? ์šฐ๋ฆฌ๊ฐ€ ๋ณ€์ˆ˜ ํ˜น์€ ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ฒŒ ๋  ๋•Œ ํ•ด๋‹น ๋ณ€์ˆ˜ ๋˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์œ ํšจํ•œ ๋ฒ”์œ„๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. Scope ๋Š” ์ด 3๊ฐ€์ง€ ์ข…๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. Global (์ „์—ญ) Scope: ์ฝ”๋“œ์˜ ๋ชจ๋“  ๋ฒ”์œ„์—์„œ ์‚ฌ์šฉ๊ฐ€๋Šฅ. Function (ํ•จ์ˆ˜) Scope: ํ•จ์ˆ˜ ์•ˆ์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ. Block (๋ธ”๋ก) Scope: if, for, switch ๋“ฑ ํŠน์ • ๋ธ”๋ก ๋‚ด๋ถ€์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ. const value = 'hello!'; function myFunction() { console.log('myFunction: '); console.log(value); } function otherFunction() { console.log('otherFunction: '); const value = 'bye!'; conso..

spread์™€ rest

์ด๋ฒˆ์—๋Š” ES6 ์—์„œ ๋„์ž…๋œ spread ์™€ rest ๋ฌธ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์„œ๋กœ ์™„์ „ํžˆ ๋‹ค๋ฅธ ๋ฌธ๋ฒ•์ธ๋ฐ, ์€๊ทผํžˆ ํ—ท๊ฐˆ๋ฆฝ๋‹ˆ๋‹ค. 1. spread spread ๋ผ๋Š” ๋‹จ์–ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์˜๋ฏธ๋Š” 'ํŽผ์น˜๋‹ค', 'ํผ๋œจ๋ฆฌ๋‹ค' ์ž…๋‹ˆ๋‹ค. ์ด ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด, ๊ฐ์ฒด ํ˜น์€ ๋ฐฐ์—ด์„ ํŽผ์น ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค. const slime = { name: '์Šฌ๋ผ์ž„' }; const cuteSlime = { name: '์Šฌ๋ผ์ž„', attribute: 'cute' }; const purpleCuteSlime = { name: '์Šฌ๋ผ์ž„', attribute: 'cute', color: 'purple' }; console.log(slime); console.log(cuteSlime); console.log(purpleCuteSlime); ์ด ์ฝ”..

๋น„๊ตฌ์กฐํ™” ํ• ๋‹น(๊ตฌ์กฐ๋ถ„ํ•ด) ๋ฌธ๋ฒ•

๋น„๊ตฌ์กฐํ™” ํ• ๋‹น ๋ฌธ๋ฒ•์„ ์‚ฌ์šฉํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐ์ฒด ์•ˆ์— ์žˆ๋Š” ๊ฐ’์„ ์ถ”์ถœํ•ด์„œ ๋ณ€์ˆ˜ ํ˜น์€ ์ƒ์ˆ˜๋กœ ๋ฐ”๋กœ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. const object = { a: 1, b: 2 }; const { a, b } = object; console.log(a); // 1 console.log(b); // 2 ๊ทธ๋ฆฌ๊ณ , ํ•จ์ˆ˜์˜ ํŒŒ๋ผ๋ฏธํ„ฐ์—์„œ๋„ ๋น„๊ตฌ์กฐํ™” ํ• ๋‹น์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. const object = { a: 1, b: 2 }; function print({ a, b }) { console.log(a); console.log(b); } print(object); ๊ทธ๋Ÿฐ๋ฐ ์—ฌ๊ธฐ์„œ ๋งŒ์•ฝ b ๊ฐ’์ด ์ฃผ์–ด์ง€์ง€ ์•Š์•˜๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. const object = { a: 1 }; function print({ a, b }) { con..

์กฐ๊ฑด๋ฌธ ์Šค๋งˆํŠธํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๊ธฐ

1. ํŠน์ • ๊ฐ’์ด ์—ฌ๋Ÿฌ ๊ฐ’์ค‘ ํ•˜๋‚˜์ธ์ง€ ํ™•์ธํ•ด์•ผ ํ•  ๋•Œ ๋งŒ์•ฝ ํŠน์ • ๊ฐ’์ด ์—ฌ๋Ÿฌ ๊ฐ’ ์ค‘ ํ•˜๋‚˜์ธ์ง€ ํ™•์ธ์„ ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์ด ์ƒ๊ฒผ๋‹ค๋ฉด ์ด๋Ÿฌํ•œ ์‹œ๋„๋ฅผ ํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. function isAnimal(text) { return ( text === '๊ณ ์–‘์ด' || text === '๊ฐœ' || text === '๊ฑฐ๋ถ์ด' || text === '๋„ˆ๊ตฌ๋ฆฌ' ); } console.log(isAnimal('๊ฐœ')); // true console.log(isAnimal('๋…ธํŠธ๋ถ')); // false ๋น„๊ต๊ฐ’์ด ๋งŽ์•„์งˆ ์ˆ˜๋ก ์ฝ”๋“œ๊ฐ€ ๊ธธ์–ด์ง‘๋‹ˆ๋‹ค. ์ด๋ฌธ์ œ์˜ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์€, ๋ฐฐ์—ด์„ ๋งŒ๋“ค๊ณ  ๋ฐฐ์—ด์˜ includes ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. function isAnimal(name) { const animals = ['๊ณ ์–‘์ด', '๊ฐœ', '๊ฑฐ..

ํ•จ์ˆ˜์˜ ๊ธฐ๋ณธ ํŒŒ๋ผ๋ฏธํ„ฐ

ํ•จ์ˆ˜์˜ ๊ธฐ๋ณธ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ ์›์˜ ๋„“์ด๋ฅผ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. function calculateCircleArea(r) { return Math.PI * r * r; } const area = calculateCircleArea(4); console.log(area); // 50.26548245743669 ์—ฌ๊ธฐ์„œ Math.PI ๋Š” ์›์ฃผ์œจ ํŒŒ์ด(π) ๊ฐ’์„ ๊ฐ€๋ฅดํ‚ต๋‹ˆ๋‹ค. ๋งŒ์•ฝ ์ด ํ•จ์ˆ˜์— r ๊ฐ’์„ ๋„ฃ์–ด์ฃผ์ง€ ์•Š์œผ๋ฉด ์–ด๋–ค ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜ํƒ€๋‚ ๊นŒ์š”? function calculateCircleArea(r) { return Math.PI * r * r; } const area = calculateCircleArea(); console.log(area); // NaN ๊ฒฐ๊ณผ๋Š” NaN ์ด..

๋‹จ์ถ•ํ‰๊ฐ€ ๋…ผ๋ฆฌ๊ณ„์‚ฐ๋ฒ•

๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋ฅผ ์กฐ๊ธˆ ๋” ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ๋ฐฐ์›Œ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. true && true // true true && false // false true || false // true false || true // true ๋…ผ๋ฆฌ ์—ฐ์‚ฐ์ž๋ฅผ ์‚ฌ์šฉ ํ•  ๋•Œ์—๋Š” ๋ฌด์กฐ๊ฑด ์šฐ๋ฆฌ๊ฐ€ true ํ˜น์€ false ๊ฐ’์„ ์‚ฌ์šฉํ•ด์•ผ ๋˜๋Š” ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์ด๋‚˜ ์ˆซ์ž, ๊ฐ์ฒด๋ฅผ ์‚ฌ์šฉ ํ•  ์ˆ˜๋„ ์žˆ๊ณ , ํ•ด๋‹น ๊ฐ’์ด Truthy ํ•˜๋ƒ Falsy ํ•˜๋ƒ์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ๊ฐ€ ๋‹ฌ๋ผ์ง‘๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด์„œ, const dog = { name: '๋ฉ๋ฉ์ด' }; function getName(animal) { return animal.name; } const name = getName(dog); console.log(name); // ๋ฉ๋ฉ์ด ๊ทธ๋Ÿฐ๋ฐ ๋งŒ์•ฝ..