본문 바로가기
CLASS/DATABASE

#4-4 / Oracle + Mybatis 로그인

by hingu 2024. 9. 4.

 

  👀 타이틀  

- login.jsp

<body>
	<form id="frm" method="post" action="./loginok.do">
		아이디 : <input type="text" name="mid"><br>
		패스워드 : <input type="password" name="mpass"><br>
		<button type="submit">로그인</button>
	</form>
</body>

 

- member_repo.java  (interface)

@Mapper
public interface member_repo {
	//회원가입
	public int join(member_dto mdto);
	
	//로그인
	//member_dto mdto = void logins(member_dto mdto); => 둘다 써도됨
	public List<member_dto> logins(member_dto mdto); 
}

 

 

- mapper.xml

<select id="logins" resultType="kr.co.sen.member_dto">
select * from member where mid='#{mid}';
</select>

 

- member_service.java   (interface)

package kr.co.sen;

import java.util.List;

public interface member_service {
	public int join_member(member_dto mdto);
	public List<member_dto> logins(member_dto mdto);
}

 

- memberServiceImpl.class 

package kr.co.sen;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class memberServiceImpl implements member_service{
	@Autowired
	private member_repo member_repo;
	
	@Override
	public int join_member(member_dto mdto) {
		int result = member_repo.join(mdto);
		return result;
	}
	
	@Override
	public List<member_dto> logins(member_dto mdto) {
		List<member_dto> one = member_repo.logins(mdto);
		
		return one;
	}
}

 

- controller

PrintWriter pw = null;

@Resource(name="member_dto")
member_dto mdto;

@Autowired
private member_service member_service;

@PostMapping("/loginok.do")
public String loginok(@ModelAttribute member_dto mdto, ServletResponse res) {
    res.setContentType("text/html;charset=utf-8");
    List<member_dto> one = member_service.logins(mdto);
    try {
        this.pw = res.getWriter();
        if(one==null) {
            this.pw.write("<script>"
                    + "alert('아이디 및 패스워드를 확인하세요.');"
                    + "location.href='/login.do';"
                    + "</script>");
        }else {
            if(mdto.getMpass().equals(one.get(0).getMpass())) {
                this.pw.write("<script>"
                        + "alert('로그인 성공.');"
                        + "location.href='/login.do';"
                        + "</script>");
            }
        }
    }catch(Exception e) {
        System.out.println("DDL 쿼리 오류 발생!!");
    }finally {
        this.pw.close();
    }

    return null;
}

 

에러났는데 몰겠따..