Spring Framework

Spring) 회원 관리 예제 - 홈 화면 추가 / 회원 웹 기능 - 등록

na_o 2022. 2. 1. 05:26
728x90

회원 관리 예제 - 홈 화면 추가

 

https://github.com/NayoungBae/springIntroduction/commit/99e55219977abed2f38412adb0644fb77a9f41b9

 

회원 웹 - 홈 화면 추가 · NayoungBae/springIntroduction@99e5521

Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files 회원 웹 - 홈 화면 추가 Loading branch information Showing 1 changed file with 13 additions and 0 deletions. +13

github.com

https://github.com/NayoungBae/springIntroduction/commit/8bfb331ca2eb3b361d9f45f52c675ba548deba17

 

home.html 추가 · NayoungBae/springIntroduction@8bfb331

Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files home.html 추가 Loading branch information Showing 1 changed file with 15 additions and 0 deletions. +15 −0 src/main

github.com

 

 

 

* 컨드롤러가 정적 파일보다 우선순위가 높다

컨트롤러에서 먼저 html 파일과 맵핑되어있는지 찾아보고, 존재하면 맵핑된 html을 불러온다.

만약 없으면 static 폴더를 뒤져본다.

 


회원 웹 기능 - 등록

https://github.com/NayoungBae/springIntroduction/commit/7e1619040976d5aa093a603f206e763fd749f5d6

 

회원 웹 - 등록 · NayoungBae/springIntroduction@7e16190

Permalink This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. Browse files 회원 웹 - 등록 Loading branch information Showing 3 changed files with 46 additions and 0 deletions. +18 −0 src/

github.com

 

//resources/templates/members/createMemberForm.html

...
 <form action="/members/new" method="post">
 	<div class="form-group">
 		<label for="name">이름</label>
 		<input type="text" id="name" name="name" placeholder="이름을 입력하세요">
 	</div>
 	<button type="submit">등록</button>
 </form>
 ...

name="name" 이 부분으로 인해 input 태그에 입력한 값이

 

package hello.hellospring.controller;

...
@PostMapping(value = "/members/new")
public String create(MemberForm form) {
	Member member = new Member();
     member.setName(form.getName());
     memberService.join(member);
     return "redirect:/";
}
...

create 함수의 매개변수 MemberForm 클래스에 있는 필드 name에 자동으로 들어감!

 

package hello.hellospring.controller;

public class MemberForm {
	 private String name;
	 
	 public String getName() {
	 	 return name;
	 }
	 
	 public void setName(String name) {
	 	 this.name = name;
	 }
}