Skip to content

Latest commit

Β 

History

History
41 lines (27 loc) Β· 1.26 KB

AccountController.md

File metadata and controls

41 lines (27 loc) Β· 1.26 KB

νšŒμ›κ°€μž… 컨트둀러 λ§Œλ“€κΈ°

  • GET "/sign-up" μš”μ²­μ„ λ°›μ•„μ„œ account/sign-up.html을 보여쀀닀.
  • νšŒμ›κ°€μž… νΌμ—μ„œ μž…λ ₯받을 수 μžˆλŠ” 정보λ₯Ό λ‹‰λ„€μž„, 이메일, νŒ¨μŠ€μ›Œλ“œ 폼 객체둜 μ œκ³΅ν•œλ‹€.
@Controller
public class AccountController {

    @GetMapping("/sign-up")
    public String signUpForm(Model model) {
        return "account/sign-up";
    }
}

Model 객체

  • μ„œλ²„ ν…œν”Œλ¦Ώ μ—”μ§„(Thymeleaf...)μ—μ„œ μ‚¬μš©ν•  수 μžˆλŠ” 객체λ₯Ό μ €μž₯ν•  수 μžˆλ‹€.

  • model.addAttribute(key, value)

    key - value μŒμ„ ν†΅ν•΄μ„œ view에 전달할 데이터 객체λ₯Ό μ§€μ •ν•œλ‹€.

Annotation

@Controller

  • @Controller μ–΄λ…Έν…Œμ΄μ…˜μ„ λͺ…μ‹œν•˜λ©΄, Spring MVC Containerκ°€ Client의 μš”μ²­μœΌλ‘œλΆ€ν„° Viewλ₯Ό λ°˜ν™˜ν•œλ‹€. ν•΄λ‹Ή ν΄λž˜μŠ€κ°€ μ»¨νŠΈλ‘€λŸ¬μž„μ„ μŠ€ν”„λ§ μ»¨ν…Œμ΄λ„ˆμ—κ²Œ μ•Œλ €μ€€λ‹€.

@GetMapping(url)

  • GET λ°©μ‹μœΌλ‘œ url으둜 λ“€μ–΄μ˜¨ μš”μ²­μ„ μ²˜λ¦¬ν•˜λŠ” λ©”μ„œλ“œλ₯Ό λ§€ν•‘ν•œλ‹€.

Thymeleaf

  • <html xmlns:th="http://www.thymeleaf.org"> λ₯Ό 적으면 ν•΄λ‹Ή html 파일이 νƒ€μž„λ¦¬ν”„μž„μ„ λͺ…μ‹œν•œλ‹€.

  • url μš”μ²­ 보낼 λ•Œ : @{/url}

    ex) th:href="@{/}" , th:actoin="@{/sign-up}"

  • th:field="*{valueName}"

  • th:object="${objectName}"