Spring - [intelliJ,Thymeleaf] ๋ก๋, ๋ฒํผ ๋๋ฌ ๋๋ค ์ซ์ 6๊ฐ ์ถ๋ ฅํ๊ธฐ(2)
[ ๋ก๋, ๋ฒํผ ๋๋ฌ ๋๋คํ ์ซ์ 6๊ฐ ์ถ๋ ฅํ๊ธฐ ]
Spring - [intelliJ,Thymeleaf] ๋ก๋, ๋ฒํผ ๋๋ฌ ๋๋ค ์ซ์ 6๊ฐ ์ถ๋ ฅํ๊ธฐ
[ ๋ฒํผ ๋๋ฅด๋ฉด Hello,World! ์ถ๋ ฅ ] Spring - [intelliJ] ๋ฒํผ ๋๋ฅด๋ฉด Hello,World! ์ถ๋ ฅ[ Hello,World ์ถ๋ ฅํ๊ธฐ ] Spring - [IntelliJ] Hello World ์ถ๋ ฅํ๊ธฐ[ Spring MVC์ ๋ํ์ฌ ] Spring - Spring MVC๋ฅผ ์์์ผ ์์์ด ๊ฐ๋ฅํ๋ค
post-this.tistory.com
๋ฒํผ์ ๋๋ฅด๋ฉด
๊ณ์ํด์ ๋๋คํ ๋ฒํธ๊ฐ ์ถ๋ ฅ๋๋ค.
1. ๋์ํ๋ฉด๊ณผ ์ ์ฒด์ฝ๋
๋์ํ๋ฉด
์ ์ฒด์ฝ๋
GitHub - hyeong-ing/LuckyLotto: ๋ก๋ ๋ฒํธ๊ฐ ์ถ๋ ฅ๋๋ ์น์ฌ์ดํธ์ ๋๋ค.
๋ก๋ ๋ฒํธ๊ฐ ์ถ๋ ฅ๋๋ ์น์ฌ์ดํธ์ ๋๋ค. Contribute to hyeong-ing/LuckyLotto development by creating an account on GitHub.
github.com
2. ์ด๋ป๊ฒ ๋ง๋ค์ง ์๊ฐํ๊ธฐ ๐จ๐ป๐ป
๋ฒํผ์ ๋๋ฅด๋ฉด 6๊ฐ์ ์ซ์๊ฐ ๋๋ค์ผ๋ก ์ถ๋ ฅ๋๋๋ก ๋ง๋ค์๋ค.
์ํ๋ ์ด๋ฏธ์ง์ ๋ง์ถฐ ๋ง๋ค๋ฉด์, ๋ฒํผ์ ์ฐ์์ ์ผ๋ก ๋๋ฅด๋ฉด ์ซ์๊ฐ ๊ณ์ ๋ฐ๋๋ ๊ตฌ์กฐ๋ก ์์ ํ๊ณ ์ถ์ด์ก๋ค.
์ต๋ํ ์๋ ์ง์ ์ ์์ ์๊ฐํด๋ณด๊ธฐ๋ก ํ๋ค.
[ ์ํ๋ ์ด๋ฏธ์ง ]
[ ๋ณ๊ฒฝ์ฌํญ ]
โก ์ํ ๋ชจํ ์์ ๊ฐ๊ฐ 6๊ฐ์ ์ซ์๊ฐ ์ถ๋ ฅ๋๊ธฐ.
โป TreeSet์ผ๋ก ๋ฐ์ ์ซ์๋ฅผ ๋ฐ๋ก ๋ฐ์์ผํ๋ค.
โป ์ฌ์ ํ ์ค๋ณตX๊ณผ ์ค๋ฆ์ฐจ์์ด ์ ์ง๋์ด์ผํ๋ค.
โป ArrayList๋ก ๋ณํํ๋ฉด ๋ ๊ฒ ๊ฐ๋ค.
โก ๋ฒํผ์ ๋๋ฅด๋ฉด ๊ณ์ํด์ ์ซ์ ๋ณ๊ฒฝ๋๊ธฐ.
โป @GetMapping์ ์ ์งํ๋ฉด์ ๋ฐ๊พธ๊ณ ์ถ๋ค.
โป ๋ฌดํ ์ํ ๊ตฌ์กฐ๋ก ๋ง๋ค์ด๋ณด๋ฉด ๋์ง์์๊น?
3. ์ํ์ ๋ง๋ค๊ณ ๊ฐ ์ํ์ ๋ก๋ ์ซ์ ๋ด๊ธฐ.
โก TreeSet์ผ๋ก ๋ด์ ๋๋ค ์ซ์๋ฅผ ArrayList๋ก ๋ณํํ๋ค.
Random1.java
List<Integer> lottoList = new ArrayList<>(lottoSet);
model.addAttribute("Number1",lottoList.get(0));
model.addAttribute("Number2",lottoList.get(1));
model.addAttribute("Number3",lottoList.get(2));
model.addAttribute("Number4",lottoList.get(3));
model.addAttribute("Number5",lottoList.get(4));
model.addAttribute("Number6",lottoList.get(5));
TreeSet์ ํน์ฑ์ ์ค๋ณต์ ํ์ฉํ์ง ์์ผ๋ฉด์, ์ด์งํ์ ํธ๋ฆฌ์ ๊ตฌ์กฐ๋ก ์ค๋ฆ์ฐจ์ ๋ฐฐ์ด์ด ์ด๋ค์ง๋ค๋ ๊ฒ์ด๋ค. ์ฌ๊ธฐ๊น์ง ์ํ๋ ๋ถ๋ถ์ด์์ง๋ง, Set์ ๊ฐ ์ธ๋ฑ์ค๋ก ์์๋ค์ ๊ด๋ฆฌํ์ง ์๋๋ค. ๊ทธ๋ ๊ธฐ์ 6๊ฐ์ ์ซ์๋ฅผ ๋ฐ๋ก๋ฐ๋ก ์ํ ์์ ๋ฃ๋ ๋ฐฉ๋ฒ์ด ์์๋ค. ๊ทธ๋์ ArrayList<>๋ก Set์ธ lottoSet์ ๋ณํ์์ผฐ๋ค. ArrayList๋ ์์๋ฅผ ๋ณด์ฅํ์ฌ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ํน์ฑ์ด ์๊ธฐ ๋๋ฌธ์, ์ค๋ฆ์ฐจ์์ผ๋ก ๋์ด๋์ด์์ lottoSet์ ์์๋ฅผ ์ ์งํด์ค๊ฑฐ๋ผ ์๊ฐํ๋ค. (๋ณธ๋ ArrayList๋ ์ค๋ณต์ ํ์ฉํ๋ฉฐ ๋ค์ด์จ ์์๋ฅผ ๋ณด์ฅํ๊ธฐ ๋๋ฌธ์ ์ฒ์๋ถํฐ ๋๋ค ์ซ์๋ฅผ ArrayList๋ก ๋ฐ์ง ์์๋ค.)
์ด์ ArrayList๋ก ๋ณํ๋ lottoList๋ฅผ ๋๋ ์ html์ ์๋ ๋ณ์์ ๋ณด๋ผ ๊ฒ์ด๋ค. ์ด๋ ๋ณ์๋ Number1 ~ Number6์ด ๋๋ค.
โก style.css์ ๋ค์ด๊ฐ๋ค.
.circle-red {
display:inline-block;
width:80px;
height:80px;
border-radius:50%;
background-color:#F5A9A9;
text-align:center;
}
[๋นจ-์ฃผ-๋ ธ-์ด-ํ-๋จ] ์์๋ก ์ฐ๊ฒฐ๋์ด ๋ณด์ด๋๋ก display์ inline-block์ ์ ์ด์ฃผ์๋ค. display๋ ์ด๋ป๊ฒ ํ์ํ ์ง ๊ฒฐ์ ํ ๋ ์ด๋ค. ์ฌ๊ธฐ์ inline-block์ block์ ๋ชจ์์ ์ ์ง๋๋ฉด์ ์์ผ๋ก ๋์ดํ๊ณ ์ถ์ ๊ฒฝ์ฐ ์ฌ์ฉํ๋ค. border-radius๋ ํ ๋๋ฆฌ ๊ตด๊ณก์ผ๋ก 50%๋ก ์ค์ ํ์ฌ ์ํ์ผ๋ก ๋ง๋ค์ด์ค๋ค. 100%๋ก ํ๋ฉด width์ height์ ๋น์จ์ด ๋ค๋ฅธ ๊ฒฝ์ฐ ํ์ํ์ด ๋ ์ ์๋ค. ํ์ง๋ง 50%๋ ๋น์จ์ด ๋ฌ๋ผ๋ ์จ์ ํ ์ํ์ผ๋ก ๋ณด์ฌ์ง๋ค.
์ฌ๊ธฐ์ background-color๋ง ๋ค๋ฅด๊ฒ ํ๋ฉด ์ด 6๊ฐ์ ์ํ์ ๋ง๋ค ์ ์๋ค.
โก ๋ง๋ ์ํ์ lottoList์ ์๋ ์ธ๋ฑ์ค ์ซ์ ๋ฃ๊ธฐ.
button1.html
<div class="circle-red">
<h1 th:text="${Number1}"> RandomNumber </h1>
</div>
๋ณ์ Number1์ ๋์ ์ธ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ์ํ๋ th๋ฅผ ์ ์ธํ๋ค. ์๊น Random1.java์ ์๋ lottoList์ 0๋ฒ์งธ ์ธ๋ฑ์ค์ ์ ๊ทผํ์ฌ Number1์ ๊ฐ์ ๋ณด๋ด์ค ๊ฒ์ด๋ค. ๊ทธ๋ ๊ฒ ๋ง๋ ๋ค๋ฅธ ์์ ์ํ์ class๋ก ์ ์ํ๊ณ ๋ณ์๋ฅผ ์ ๋ ฅํ๋ฉด ๋๋จธ์ง ์ธ๋ฑ์ค๋ ๋ํ๋ ๊ฒ์ด๋ค.
4. ์ํ๊ตฌ์กฐ ๋ง๋ค๊ธฐ.
์ ์๋ ๋๋ค ๋ฒํธ๋ฅผ ๋ฑ ํ ๋ฒ ๋ฐ์ ์ ์์๋ค. ํ์ง๋ง ์ด๋ฒ์๋ ๋ฒํผ์ ๋๋ฅด๋ฉด ๊ณ์ํด์ ๋๋ค ์ซ์๋ฅผ ๋ฐ์ ์ ์๋๋ก ๋ง๋ค๊ณ ์ ํ๋ค.
์๊ณ ์๋ ๊ฐ๋ ์์ ์ํ๋ ๋ชฉํ๋ฅผ ์ํํ๊ธฐ ์ํด, ์ซ์๊ฐ ๋ณด์ฌ์ง ํ๋ฉด 3๊ฐ์ Controller 3๊ฐ๋ฅผ ๋ง๋ค์ด ์ํํ๋ ๋ฐฉ์์ผ๋ก ๋ง๋ค๊ธฐ๋ก ํ๋ค. Button1์์ ๋ฒํผ์ด ๋๋ฆฌ๋ฉด ์ปจํธ๋กค๋ฌ์ธ Random1๋ก ๋์ฐฉํ๋ค. ๊ทธ ํ ์คํ๋ ๋ฉ์๋์ ๊ฐ์ Button2๋ก ๋ณด๋ธ๋ค. Button2์์ ๋ฒํผ์ด ๋๋ฆฌ๋ฉด Random2 ์ปจํธ๋กค๋ฌ๋ก ํฅํ๊ณ ๋ฉ์๋์ ๊ฒฐ๊ณผ๋ Button3์ผ๋ก ๊ฐ๊ฒ๋๋ค. Button3์์ ๋ฒํผ์ด ๋๋ฆฌ๋ฉด Random1๋ก ๋ค์ ๋์์ค๊ฒ ๋ง๋ค์๋ค. ๊ทธ ํ Random1์์ ์ฒ๋ฆฌ๋ ๊ฒฐ๊ณผ๋ Button1์์ ์ถ๋ ฅ๋๋๋ก ๋ง๋ค์๋ค.
<form th:action="@{/Random1}" method = "get">
<button class="btn" type="submit" > ๋ฒํผ </button>
</form>
utton1.html์์ ๋ฒํผ์ด ๋๋ฆฌ๋ฉด Random1 ๊ฒฝ๋ก๋ฅผ ๊ฐ์ง Controller๋ก ์ ์ก๋๋ค.
@GetMapping("/Random1")
public String randomPage1(Model model)
๊ทธ๋ผ Random1.java์ ์๋ GetMapping("/Random1")์ผ๋ก ๋ฐ๊ฒ๋๋ค. ๊ทธ๋ฌ๋ฉด randomPage1 ๋ฉ์๋๊ฐ ์คํ๋๋ค.
Set<Integer> lottoSet = new TreeSet<>();
while(true) {
int ranNum = rd.nextInt(45)+1;
lottoSet.add(ranNum);
if(lottoSet.size() == 6) {
break;
}
}
List<Integer> lottoList = new ArrayList<>(lottoSet);
model.addAttribute("Number1",lottoList.get(0));
model.addAttribute("Number2",lottoList.get(1));
model.addAttribute("Number3",lottoList.get(2));
model.addAttribute("Number4",lottoList.get(3));
model.addAttribute("Number5",lottoList.get(4));
model.addAttribute("Number6",lottoList.get(5));
return "button2";
๋๋ค์ผ๋ก ์ซ์ 6๊ฐ๋ฅผ TreeSet์ผ๋ก ๋ฐ๊ณ ArrayList๋ก ๋ณํ ํ, ๊ฐ ์ธ๋ฑ์ค์ ์ ๊ทผํ์ฌ ๋ณ์์ ๋ฃ์ด button2๋ก ์ ๋ฌํ๊ฒ ๋๋ค.
<div class="circle-red">
<h1 th:text="${Number1}"> RandomNumber </h1>
</div>
<div class="circle-orange">
<h1 th:text="${Number2}"> RandomNumber </h1>
</div>
<div class="circle-yellow">
<h1 th:text="${Number3}"> RandomNumber </h1>
</div>
<div class="circle-green">
<h1 th:text="${Number4}"> RandomNumber </h1>
</div>
<div class="circle-blue">
<h1 th:text="${Number5}"> RandomNumber </h1>
</div>
<div class="circle-darkblue">
<h1 th:text="${Number6}"> RandomNumber </h1>
</div>
์ด์ ๋ฐ์๋ ๋ณ์๊ฐ button2.html๋ก ์ ๋ฌ๋์ด ์ถ๋ ฅ๋๋ค.
<form th:action="@{/Random2}" method = "get">
<button class="btn" type="submit" > ๋ฒํผ </button>
</form>
๊ทธ ํ ๋ฒํผ์ ๋๋ฅด๋ฉด Random2 ๊ฒฝ๋ก๋ฅผ ๊ฐ์ง Controller๋ฅผ ์ฐพ๊ฒ ๋๋ค. ์ด๋ฐ์์ผ๋ก ๊ณ์ ๋ฐ๋ณต๋๋ ๊ตฌ์กฐ๋ค. ๋ง์ง๋ง Random3๋ button1์ผ๋ก ์ถ๋ ฅ๋๋ฉฐ button1์ ๋ฒํผ์ด ๋๋ฆฌ๋ฉด Random1์ ๋ฉ์๋๊ฐ ์คํ๋์ด button2์ ๊ฒฐ๊ณผ๊ฐ์ด ์ถ๋ ฅ๋๊ฒ ๋๋ค.
[ ๋ค์ํด๋ก๋ฒ ์ด๋ฏธ์ง ๋ฃ๋ ๋ฐฉ๋ฒ๊ณผ ๊ธ์จ์ฒด ์ ์ฉ ]
Spring - [HTML,CSS,Thymeleaf] ์ด๋ฏธ์ง ๋ฃ๊ธฐ, ๋๋ ๊ธ์จ์ฒด ์ฌ์ฉํ๊ธฐ
[ ๋ก๋, ๋ฒํผ ๋๋ฌ ๋๋คํ ์ซ์ 6๊ฐ ์ถ๋ ฅํ๊ธฐ ] Spring - [intelliJ,Thymeleaf] ๋ก๋, ๋ฒํผ ๋๋ฌ ๋๋ค ์ซ์ 6๊ฐ ์ถ๋ ฅํ๊ธฐ(2)[ ๋ก๋, ๋ฒํผ ๋๋ฌ ๋๋คํ ์ซ์ 6๊ฐ ์ถ๋ ฅํ๊ธฐ ] Spring - [intelliJ,Thymeleaf] ๋ก๋, ๋ฒํผ
post-this.tistory.com
๐ชฝ
"ํ๋ฆฐ ๋ด์ฉ์ด ์์ ์ ์์ต๋๋ค."
[ ๋ธ๋ก๊ทธ์ ์ด ๋ด์ฉ๋ค์ ์ถ์ฒ๋ ์๋์ ์ ์ด๋ํ ๋
๋ค์ด๊ฐ์ ์ฝ์ด๋ณด์๋ฉด ๋์ฑ ๋์์ด ๋์ค ๋ฏ ํฉ๋๋ค ]
List, Set ์ด๋ค ๊ฒ์ ์ฐ๋ ๊ฒ์ด ์ ๋ฆฌํ๊ฐ
๋ฐฐ๊ฒฝ ์๊ณ ๋ฆฌ์ฆ ๋ฌธ์ (์ฌ๊ธฐ์ ์ ๋ฆฌ)๋ฅผ ํ๋ค๊ฐ LinkedList ์ HashSet ์ contains() ์๋ ์ฐจ์ด๊ฐ ํฌ๋ค๋ ๊ฒ์ ์๊ฒ ๋์๋ค. ์ง์ ํ ์คํธ ํด๋ณด๊ณ ์ด๋ฅผ ์ ๋ฆฌํ๋ ค๊ณ ํ๋ค. ์๋ ๋น๊ต 10000000์ ์ซ์๋ฅผ ArrayList, Lin
hanul-dev.netlify.app
- Set์ ArrayList๋ก ๋ณํ ์ถ์ฒ
[Java] HashSet์ ArrayList๋ก ๋ณํํ๊ธฐ
[Java] HashSet์ ArrayList๋ก ๋ณํํ๊ธฐ HashSet set = new HashSet(); for (int i = 0; i < T; i++) { set.add(br.readLine()); } ArrayList list = new ArrayList(set); ์ค๋ณต๋๋ ๊ฐ์ ์ ์ธํ๊ณ ์ ์ฅํ๊ณ ์ถ์ ๊ฒฝ์ฐ๊ฐ ์กด์ฌํ๋ค. ์ด๋ HashSe
kim6394.tistory.com
์๋ฐ[JAVA] : Set - HashSet / TreeSet / LinkedHashSet ์์๋ณด๊ธฐ.
- Set - ์์๋ฅผ ์ ์งํ์ง ์๋ ๋ฐ์ดํฐ์ ์งํฉ. ๋ฐ์ดํฐ์ ์ค๋ณต์ ํ์ฉํ์ง ์๋๋ค. - ์ธ๋ฑ์ค๋ก ์์๋ค์ ๊ด๋ฆฌํ์ง ์๋๋ค. ์๋ฅผ ๋ค์ด ๋์ ํ๋งค์ฌ์ดํธ์ ํ๋ฃจ ๋ฐฉ๋ฌธ์ ์(์ค๋ณต ์ ์์ ์ ์ธํ)๋ฅผ ๊ตฌํ
doompok.tistory.com
๐งฑ ์๋ฐ ArrayList ๊ตฌ์กฐ & ์ฌ์ฉ๋ฒ ์ ๋ฆฌ
ArrayList ์ปฌ๋ ์ ์๋ฐ์ ์ปฌ๋ ์ ํ๋ ์์ํฌ๋ฅผ ์ ํ๋ค๋ฉด ๊ฐ์ฅ ๋จผ์ ๋ฐฐ์ฐ๋ ์ปฌ๋ ์ ์ด ArrayList ์ผ ๊ฒ์ด๋ค. ์๋ฃ๊ตฌ์กฐ(Data Structure) ์ด๋ผ๊ณ ํด์ ๋ฌด์ธ๊ฐ ๋ฐฉ๋ํ๊ฒ ๋๊ปด์ ธ ์ ๊ทผ์ด ์ด๋ ค์ธ ๊ฒ ์ฒ๋ผ ๋๋ผ๊ฒ ์ง
inpa.tistory.com
[html/css] display ์์ฑ (inline, block, none, inline-block ์ฐจ์ด), visibility ์์ฑ(visible, hidden, collapse ์ฐจ์ด)
display ์์ฑ (inline, block, none ์ฐจ์ด), visibility ์์ฑ(visible, hidden, collapse ์ฐจ์ด) ์ค๋ ์์ ๋ณผ ์์ฑ์, ์ด๋ค ์์๋ฅผ ํ๋ฉด์ ๋ณด์ด๊ฑฐ๋ ์จ๊ธธ ๋ ์ฌ์ฉํ๋ display์ visibilty ์์ฑ์ ๋๋ค. *display์ visibilty ์ฐจ์ด
aboooks.tistory.com
border-radius 50% vs 100%
1. border-radius 50% vs 100% ์ฐ๋ฆฌ๋ border-radius: 50%๋ฅผ ์ง์ ํ์ฌ ์์ ๋ง๋ค ์ ์๋ค. ๊ทธ๋ฐ๋ฐ ํ์ธ์ ์ฝ๋๋ฅผ ๋ณด๋ฉด 50%, 100% ๋ฑ 2๊ฐ์ง๋ฅผ ๋ค์ํ๊ฒ ์ฐ๊ณ ์๋ค. ๊ทธ๋ ๋ค๋ฉด border-radius: 50%, 100%์ ์ฐจ์ด๋ ๋ฌด์์ผ๊น? (
mong-blog.tistory.com