Hello

회원정보 수정하기

by 볼빵빵오춘기

Cotroller

누구의 정보를 수정할꺼냐를 알아야하기때문에 로그인했을 때 session에 넣어뒀던 정보를 이용한다.

@GetMapping("/update")
public String updateForm(HttpSession session, Model model){
    String loginEmail = (String) session.getAttribute("loginEmail");
    MemberDTO memberDTO = memberService.findByMemberEmail(loginEmail);
    model.addAttribute("member",memberDTO);
    return "update";
}

 

Service

public MemberDTO findByMemberEmail(String loginEmail) {
    return memberRepository.findByMemberEmail(loginEmail);
}

 

Repository

public MemberDTO findByMemberEmail(String loginEmail) {
    return sql.selectOne("Member.findByMemberEmail",loginEmail);
}

 

Mapper.xml

<select id="findByMemberEmail" parameterType="String" resultType="member">
    select * from member_table where memberEmail=#{loginEmail}
</select>

 

Controller

@PostMapping("/update")
public String update(@ModelAttribute MemberDTO memberDTO){
    boolean result = memberService.update(memberDTO);
    if(result){
        return "redirect:/member?id="+memberDTO.getId();
    }else{
        return "index";
    }
}

 

Service

public boolean update(MemberDTO memberDTO) {
    int result = memberRepository.update(memberDTO);
    if(result > 0){
        return true;
    }else{
        return false;
    }
}

 

Repository

public int update(MemberDTO memberDTO) {
    return sql.update("Member.update",memberDTO);
}

 

Mapper.xml

<update id="update" parameterType="member">
    update member_table set memberAge=#{memberAge}, memberMobile=#{memberMobile} where id=#{id}
</update>

'강의 따라하기 > springframework_setting' 카테고리의 다른 글

회원삭제하기  (0) 2024.10.22
회원정보 상세조회하기  (0) 2024.10.22
회원목록 출력하기  (0) 2024.10.22
로그인 구현하기  (0) 2024.10.22
회원가입 완성하기  (0) 2024.10.22

블로그의 정보

Hello 춘기's world

볼빵빵오춘기

활동하기