컨트롤러
- Bio, Link, Occupation, Location 정보만 입력받아서 Account 정보를 수정한다.
SettingsController 추가
package me.weekbelt.studyolle.settings;
@Controller
public class SettingsController {
@GetMapping("/settings/profile")
public String profileUpdateForm(@CurrentUser Account account, Model model) {
model.addAttribute(account);
model.addAttribute(new Profile(account));
return "settings/profile";
}
}
화면에 보여줄 정보를 담은 Profile DTO 추가
package me.weekbelt.studyolle.settings;
@NoArgsConstructor
@Data
public class Profile {
@Length(max = 35)
private String bio;
@Length(max = 50)
private String url;
@Length(max = 50)
private String occupation;
@Length(max = 50)
private String location;
public Profile(Account account) {
this.bio = account.getBio();
this.url = account.getUrl();
this.occupation = account.getOccupation();
this.location = account.getLocation();
}
}
/settins/profile.html 작성
<!DOCTYPE html>
<html lang="en"
xmlns:th="http://www.thymeleaf.org">
<!--head-->
<head th:replace="fragments.html::head"></head>
<body class="bg-light">
<!--네비게이션 바-->
<div th:replace="fragments.html::main-nav"></div>
<div class="container">
<div class="row mt-5 justify-content-center">
<div class="col-2">
<div th:replace="fragments.html :: settings-menu(currentMenu='profile')"></div>
</div>
<div class="col-8">
<div th:if="${message}" class="alert alert-info alert-dismissible fade show mt-3" role="alert">
<span th:text="${message}">메시지</span>
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">x</span>
</button>
</div>
<div class="row">
<h2 class="col-sm-12" th:text="${account.nickname}">weekbelt</h2>
</div>
<div class="row mt-3">
<form action="#" class="col-sm-6"
th:action="@{/settings/profile}" th:object="${profile}" method="post" novalidate>
<div class="form-group">
<label for="bio">한 줄 소개</label>
<input id="bio" type="text" th:field="*{bio}" class="form-control"
placeholder="간략한 소개를 부탁합니다." aria-describedby="bioHelp" required>
<small id="bioHelp" class="form-text text-muted">
길지 않게 35자 이내로 입력하세요.
</small>
<small class="form-text text-danger" th:if="${#fields.hasErrors('bio')}" th:errors="*{bio}">
조금 길어요.
</small>
</div>
<div class="form-group">
<label for="url">링크</label>
<input id="url" type="text" th:field="*{url}" class="form-control"
placeholder="http://studyolle.com" aria-describedby="urlHelp" required>
<small id="urlHelp" class="form-text text-muted">
블로그, 유튜브 또는 포트폴리오나 좋아하는 웹 사이트 등 본인을 표현할 수 있는 링크를 추가하세요.
</small>
<small class="form-text text-danger" th:if="${#fields.hasErrors('url')}" th:errors="*{url}">
올바른 URL이 아닙니다. 예시처럼 입력해 주세요.
</small>
</div>
<div class="form-group">
<label for="occupation">직업</label>
<input id="occupation" type="text" th:field="*{occupation}" class="form-control"
placeholder="어떤 일을 하고 계신가요?" aria-describedby="occupationHelp" required>
<small id="occupationHelp" class="form-text text-muted">
개발자? 매니저? 취준생? 대표님?
</small>
</div>
<div class="form-group">
<label for="location">활동 지역</label>
<input id="location" type="text" th:field="*{location}" class="form-control"
placeholder="Redmond, WA USA" aria-describedby="locationHelp" required>
<small id="locationHelp" class="form-text text-muted">
주요 활동(사는 곳이나 직장을 다니는 곳 또는 놀러 다니는 곳) 지역의 도시 이름을 알려주세요.
</small>
</div>
<div class="form-group">
<button class="btn btn-primary btn-block" type="submit" aria-describedby="submitHelp">수정하기</button>
</div>
</form>
</div>
</div>
</div>
<!-- footer -->
<div th:replace="fragments.html::footer"></div>
</div>
</body>
</html>
참고: https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-JPA-%EC%9B%B9%EC%95%B1#
'스프링과 JPA 기반 웹 어플리케이션 개발 > 1부 (개발환경, 회원가입, 로그인, 계정설정)' 카테고리의 다른 글
24. 프로필 수정 테스트 (0) | 2020.04.21 |
---|---|
23. 프로필 수정 처리 (0) | 2020.04.21 |
21. Open EntityManager (또는 Session) In View 필터 (0) | 2020.04.21 |
20. 프로필 뷰 (0) | 2020.04.21 |
19. 로그인 기억하기(RememberMe) (0) | 2020.04.21 |