๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

Jackson ObjectMapper ๋น„์ง๋ ฌํ™” ๊ณผ์ •

ObjectMapper? Jackson ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํด๋ž˜์Šค ์ค‘ ํ•˜๋‚˜์ธ ObjectMapper ํ†ตํ•ด JSON → Object(์—ญ์ง๋ ฌํ™”), Object → JSON(์ง๋ ฌํ™”)๋ฅผ ๊ฐ„๋‹จํ•˜๊ฒŒ ํŒŒ์‹ฑํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž…๋‹ˆ๋‹ค. readValue() test.json { "name" : "john", "age" : 20 } json → Object ๋น„์ง๋ ฌํ™” ์ฝ”๋“œ People people = objectMapper.readValue(new File("static/test.json"), People.class); people์˜ ๊ฐ ๊ฐ’์„ ์ฐ์–ด๋ณด๋ฉด ์ž˜ ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค. System.out.println(people.getName() + ", " + people.getAge()); // john, 20 ๊ทธ๋Ÿฐ๋ฐ ๋ง์ž…๋‹ˆ๋‹ค.. Peopl..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[JAVA] System.getProperties๋กœ ํ”„๋กœํผํ‹ฐ ๊ฐ’ ๋ฐ›๊ธฐ

System.getProperties๋กœ ํ”„๋กœํผํ‹ฐ ๊ฐ’ ๋ฐ›๊ธฐ ๊ธฐ์กด์—๋Š” ์ด๋Ÿฐ์‹์œผ๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด, $ java -jar XXX.jar arg1 arg2 arg3 ์ž๋ฐ”์—์„œ๋Š” ์ด๋ ‡๊ฒŒ ๋ฐ›์œผ๋ฉด ๋œ๋‹ค. public class Main { public static void main(String[] args) { String arg1 = args[0]; String arg2 = args[1]; String arg3 = args[2]; } } ๋ฌธ์ œ๋Š” ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค๋‹ค๊ฐ€ ENV ๋ณ€์ˆ˜๋กœ ์‹คํ–‰์‹œํ‚ค๊ฒŒ๋” ํ•˜๋ ค๋Š”๋ฐ ์ž๊พธ ENV๊ฐ€ ์•ˆ๋‹ด๊ฒจ๋‚˜๊ฐ€์„œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ณด๋‹ค๊ฐ€ ๋ฐœ๊ฒฌํ–ˆ๋‹ค. ๋ฐ”๋กœ.. System.getProperty("key") ํŒŒ๋ผ๋ฏธํ„ฐ ๋„˜๊ฒจ์ค„ ๋•Œ๋Š”, -D์˜ต์…˜์œผ๋กœ -D{key}={value} ์ด๋Ÿฐ์‹์œผ๋กœ ๋„˜๊ฒจ์ฃผ๋ฉด ๋œ๋‹ค. $ java -D..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

ํ•ด์‹œ(Hash)?์†”ํŠธ(Salt)? ํŒจ์Šค์›Œ๋“œ ์•”ํ˜ธํ™” ๋Œ€ํ•ด์„œ

ํ•ด์‹œ๋ฅผ ํ†ตํ•œ ์•”ํ˜ธํ™” Hash(ํ•ด์‹œ)๋ž€? ๋‹จ๋ฐฉํ–ฅ ์•”ํ˜ธํ™” ๊ธฐ๋ฒ•์œผ๋กœ ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์•”ํ˜ธํ™” ๋œ ๋ฌธ์ž์—ด์„ ๋งŒ๋“œ๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ex) SHA-256, Bcrypt .. ์‚ฌ์šฉ์ž์˜ ํŒจ์Šค์›Œ๋“œ๋Š” ํ‰๋ฌธ์œผ๋กœ ์ €์žฅํ•˜๋Š” ๊ฒƒ์€ ์œ„ํ—˜ํ•œ ์ผ์ž…๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋ณดํ†ต ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ์•”ํ˜ธํ™”๋ฅผ ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ์ด๋„ ๊ทธ๋ ‡๊ฒŒ ์•ˆ์ „ํ•œ ๊ฒƒ์€ ์•„๋‹™๋‹ˆ๋‹ค. ๊ณต๊ฒฉ์ž๊ฐ€ ๋ชจ๋“  ํ‰๋ฌธ์„ ํ•ด์‹œํ™”ํ•˜์—ฌ ๋Œ€์กฐ๋ฅผ ํ•˜์—ฌ ํŒจ์Šค์›Œ๋“œ๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜๋„ ์žˆ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค. ํ•ด์ปค๋Š” ๋ฌดํ•œ๋Œ€๋กœ ๊ณต๊ฒฉ์„ ํ•œ๋‹ค๋ฉด ์–ด๋–ค ์•”ํ˜ธํ™”๋ฅผ ํ•ด๋„ ํŒจ์Šค์›Œ๋“œ๋ฅผ ์•Œ์•„๋‚ผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ํ•ด์ปค๋“ค์ด ๋ฌดํ•œ๋Œ€๋กœ ๊ณต๊ฒฉ์„ ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”? X ํ•ด๋…ํ•  ๋•Œ ์กฐ๊ธˆ์ด๋ผ๋„ ๋” ์•”ํ˜ธํ™”๋ฅผ ํ•ด์„œ ํ•ด์ปค๋“ค์—๊ฒŒ ๋‹จ ๋ช‡์ดˆ๋ผ๋„ ์ง€์—ฐ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค๋ฉด ํ•ด์ปค๋“ค์—๊ฒŒ๋Š” ์น˜๋ช…์ ์ธ ์‹œ๊ฐ„์ด ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋”๋ณด๊ธฐ ์•”ํ˜ธ๋ฅผ ํ•ด๋…ํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[JAVA] properties ๊ฐ’ ์ฝ์–ด์˜ค๊ธฐ

application.properties people.name="iseunghan" people.age=26 people.city="Daejeon" Main.java public class Main { static String name; static String age; static String city; private static void read_properties() { // resource ์œ„์น˜ String resource = "META-INF/application.properties"; Properties properties = new Properties(); try { InputStream inputStream = Main.class.getClassLoader().getResourceAsStr..

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

intellij์—์„œ Java ํ”„๋กœ์ ํŠธ jar ํŒŒ์ผ ์ƒ์„ฑํ•˜๊ธฐ

์ž๋ฐ” ํ”„๋กœ์ ํŠธ๋ฅผ intellij์—์„œ jar ํŒŒ์ผ ๋งŒ๋“œ๋Š” ๋ฒ• ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ์„ ํ–ˆ์Šต๋‹ˆ๋‹ค. hello world!๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฉ”์ธ ํด๋ž˜์Šค์ž…๋‹ˆ๋‹ค. cmd + :๋กœ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์„ค์ •์œผ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. (Mac OS ๋‹จ์ถ•ํ‚ค) Artifacts -> + -> JAR -> From modules ... ํด๋ฆญ! Main Class๋ฅผ ์ง€์ •ํ•ด์ค๋‹ˆ๋‹ค. ์ด๋•Œ ํŒจํ‚ค์ง€๋ช…๊นŒ์ง€ ๋‹ค ์ ์–ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค! ์ดํ›„์— Apply -> OK๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค. ์ด์ œ intellij ์ƒ๋‹จ๋ฐ”์—์„œ build -> artifacts๋ฅผ ํด๋ฆญํ•ด์ค๋‹ˆ๋‹ค. build๋ฅผ ํด๋ฆญํ•ด์ค๋‹ˆ๋‹ค. out/artifacts/[project๋ช…]์— jar ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. jar ํŒŒ์ผ ์‹คํ–‰ํ•˜๊ธฐ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์‹คํ–‰๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!

๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ

[JAVA] ๋ฌธ์ž์—ด ์—ฌ๋Ÿฌ ๊ฐœ ๊ณต๋ฐฑ์„ ์ œ๊ฑฐํ•˜๊ธฐ (์ •๊ทœํ‘œํ˜„์‹)

์„œ๋ก  ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€๋‹ค๊ฐ€, 2๊ฐœ ์ด์ƒ์˜ ์—ฌ๋Ÿฌ ๊ฐœ ๊ณต๋ฐฑ์„ ํ•˜๋‚˜์˜ ๊ณต๋ฐฑ์œผ๋กœ ๋ฐ”๊ฟ”์•ผ ํ•˜๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋Š”๋ฐ, ์ด ์ฐธ์— ์ •๋ฆฌํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๋ฌธ์ œ "๋‚ด์šฉ์—์„œ 2๊ฐœ ์ด์ƒ์˜ ๊ณต๋ฐฑ์„ ํ•˜๋‚˜์˜ ๊ณต๋ฐฑ์œผ๋กœ ๋ฐ”๊ฟ” ์ฃผ์„ธ์š”." ์›ํ•˜๋Š” ๊ฒฐ๊ณผ "๋‚ด์šฉ์—์„œ 2๊ฐœ ์ด์ƒ์˜ ๊ณต๋ฐฑ์„ ํ•˜๋‚˜์˜ ๊ณต๋ฐฑ์œผ๋กœ ๋ฐ”๊ฟ” ์ฃผ์„ธ์š”." ์ •๊ทœํ‘œํ˜„์‹ String str = "๋‚ด์šฉ์—์„œ 2๊ฐœ ์ด์ƒ์˜ ๊ณต๋ฐฑ์„ ํ•˜๋‚˜์˜ ๊ณต๋ฐฑ์œผ๋กœ ๋ฐ”๊ฟ” ์ฃผ์„ธ์š”."; String result = str.replaceAll("\\s+", " "); System.out.print(result); ์‹คํ–‰ ๊ฒฐ๊ณผ ์•ž์œผ๋กœ ์ •๊ทœ ํ‘œํ˜„์‹์— ๋Œ€ํ•ด์„œ ์ž˜ ์•Œ๊ณ ์žˆ์œผ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

iseunghan
'๐ŸŒป JAVA/์ •๋ฆฌ์ •๋ฆฌ์ •๋ฆฌ' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก