๐โ๏ธ QNA ์๋น์ค ๊ธฐ๋ฅ ๊ตฌํ (๋ณต์ต) _ 155๊ฐ ~ 154๊ฐ / 180๊ฐ ~ 185๊ฐ
1๏ธโฃ ์์กด๊ด๊ณ๊ฐ ์๋ ํ ์ด๋ธ๋ค์์ ๋ฐ์ดํฐ๋ฅผ ์ญ์ ํ ๋ ์ ์ํ ์
โ ์์กด ๊ด๊ณ ํ์ธ
ํ์ (SiteUser) โก๏ธ ์ง๋ฌธ (Question) โก๏ธ ๋ต๋ณ (Answer)
ํ์์ด ์์ด์ผ ์ง๋ฌธ์ด ์๊ธฐ๊ณ , ์ง๋ฌธ์ด ์์ด์ผ ๋ต๋ณ ๊ฐ๋ฅํ๋ค.
โก ์์กด ๊ด๊ณ์ ๋ฐ๋ฅธ ์ญ์ ์์ ๊ฒฐ์
์์กด ๊ด๊ณ์ ๋ฐ๋๋๋ ์์๋ก ์ญ์ ํด ์ฃผ์ด์ผ ํ๋ค. ๊ทธ๋ ์ง ์์ผ๋ฉด ์ธ๋ํค๋ก ์ธํ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค.
public static void clearData(UserRepository userRepository, AnswerRepository answerRepository, QuestionRepository questionRepository) {
answerRepository.deleteAll(); // ์์ โ Answer
answerRepository.truncateTable();
questionRepository.deleteAll(); // ์์ โก Question
questionRepository.truncateTable();
userRepository.deleteAll(); // ์์ โข User
userRepository.truncateTable();
}
2๏ธโฃ ๋ก๊ทธ์ธ ์ ๋ณด๊ฐ ํ์ํ API ์์์ ์์ธ ์ฒ๋ฆฌ
๋ก๊ทธ์ธํ ์ ์ ์ ์ ๋ณด๊ฐ ํ์ํ ์ํฉ์์ ๋ก๊ทธ์์ํ ์ํ๋ก ์ ๊ทผํ ๊ฒฝ์ฐ Principal ๊ฐ์ฒด๊ฐ null ์ด ๋์ด ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์๋ค. ์ด๋ด ๊ฒฝ์ฐ Controller ์์ @PreAuthorize ์ด๋ ธํ ์ด์ ์ ์ฌ์ฉํ์ฌ ์๋ฌ๋ฅผ ๋ฐฉ์งํ๋ค.
โ @PreAuthorize ์ ์์ฑ ์ข ๋ฅ
@PreAuthorize("isAuthenticated()") // ๋ก๊ทธ์ธ ์ํ
@PreAuthorize("isAnonymous()") // ๋ก๊ทธ์์ ์ํ
@PreAuthorize("isRememberMe()") // ํ ํฐ ํ์ธ (session ๊ณผ cookie ํ์ฉ)
@PreAuthorize("isFullyAuthenticated()") // isisAuthenticated + isRememberMe
โก SecurityConfig ์ค์ : @EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) // ์ถ๊ฐ
public class SecurityConfig {
// (์๋ต)
}
โข Controller ์ ์ฉ
@PreAuthorize("isAuthenticated()") // ์ ์ฉ
@PostMapping("/create/{id}")
public String createAnswer(@PathVariable int id, @Valid AddAnswer addAnswer, BindingResult bindingResult, QuestionDetail questionDetail, Model model, Principal principal) {
// (์๋ต)
}
โฃ (์ฐธ๊ณ ) html ์์ ๋ก๊ทธ์ธ ์ฌ๋ถ์ ๋ฐ๋ผ ํ๊ทธ visibility ๊ฒฐ์
<!-- ๋ก๊ทธ์์ ์ํ์ด๋ฉด field ๋นํ์ฑํ -->
<textarea sec:authorize="isAnonymous()" disabled th:field="*{content}"></textarea>
<!-- ๋ก๊ทธ์ธ ์ํ๋ฉด field ํ์ฑํ -->
<textarea sec:authorize="isAuthenticated()" th:field="*{content}"></textarea>


( 164๊ฐ ~ 179๊ฐ ์์ , ์ญ์ ๋ถ๋ถ์ ์ ์ ๋์ด๊ฐ)
3๏ธโฃ ์ถ์ฒ ๊ธฐ๋ฅ (ManyToMany)

๐ฅ LikeLion_Final_Project [2์ฃผ์ฐจ] : ๊ตฌํ
๋ฐ๋ก ์ ๋ฆฌ : https://like099.tistory.com/55
[2์ฃผ์ฐจ] Mission ํด๊ฒฐ ์ผ์ง (1)
โณ๏ธ ์ฅ๋ฐ๊ตฌ๋ ๊ตฌํ ๐ ํ๋ชฉ ์ถ๊ฐ 1๏ธโฃ ์กฐ๊ฑด ํ์ธ โณ๏ธ API : GET /cart/add/{productId} โณ๏ธ ์๊ตฌ์ฌํญ โ๏ธ ์ํ์ด ๊ณง ๋์์ด๋ค. โ๏ธ ๋์๋ฅผ ์ฅ๋ฐ๊ตฌ๋์ ๋ด์ ์ ์๋ค. 2๏ธโฃ ์ฅ๋ฐ๊ตฌ๋ Entity ์ถ๊ฐ ๋ฐ ์ปฌ
like099.tistory.com
๐ฌ ํ๋ก๊ทธ๋๋จธ์ค MySQL ๋ฌธ์ ํ์ด
๋ฐ๋ก ์ ๋ฆฌ : https://like099.tistory.com/56
(Programmers) SQL ํ์ด (7)
โ๏ธ Programmers MySQL ์ ๋ต๋ฅ 70~72% ์ ์ฒด ํ์ด 1๏ธโฃ ์ง๋ฃ๊ณผ๋ณ ์ด ์์ฝ ํ์ ์ถ๋ ฅํ๊ธฐ (https://school.programmers.co.kr/learn/courses/30/lessons/132202) SELECT MCDP_CD AS "์ง๋ฃ๊ณผ์ฝ๋", COUNT(APNT_NO)..
like099.tistory.com
'TIL ๐' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| TIL 15์ผ์ฐจ (2022.10.25) (0) | 2022.10.27 |
|---|---|
| TIL 14์ผ์ฐจ (2022.10.26) (0) | 2022.10.26 |
| TIL 12์ผ์ฐจ (2022.10.24) (0) | 2022.10.24 |
| TIL 11์ผ์ฐจ (2022.10.21) (0) | 2022.10.21 |
| TIL 10์ผ์ฐจ (2022.10.20) (0) | 2022.10.20 |