1.MemberController
@RequestMapping("usr/member/doJoin")
@ResponseBody
public Member doJoin(String loginId, String loginPw, String name, String nickname, String cellphoneNum,
String email) {
int id = memberService.doJoin(loginId, loginPw, name, nickname, cellphoneNum, email);
Member member = memberService.getMemberById(id);
return member;
}
2.MemberService
public int doJoin(String loginId, String loginPw, String name, String nickname, String cellphoneNum, String email) {
memberRepository.doJoin(loginId, loginPw, name, nickname, cellphoneNum, email);
int id = memberRepository.getLastInsertId();
return id;
}
3.MemberRepository.xml
<select id="getLastInsertId" resultType ="int">
SELECT LAST_INSERT_ID()
</select>
<select id="getMemberById" resultType ="com.kjh.exam.demo.vo.Member">
SELECT * FROM `member`
WHERE id = #{id}
</select>
1.MemberService
public int doJoin(String loginId, String loginPw, String name, String nickname, String cellphoneNum, String email) {
Member existsMember= getMemberByLoginId(loginId);
if(existsMember !=null) {
return -1;
}
memberRepository.doJoin(loginId, loginPw, name, nickname, cellphoneNum, email);
int id = memberRepository.getLastInsertId();
return id;
}
private Member getMemberByLoginId(String loginId) {
Member member = memberRepository.getMemberByLoginId(loginId);
return member;
}
2.MemberController
public Object doJoin(String loginId, String loginPw, String name, String nickname, String cellphoneNum,
String email) {
int id = memberService.doJoin(loginId, loginPw, name, nickname, cellphoneNum, email);
if(id == -1) {
return "중복 되는 아이디가 있습니다.";
}
Member member = memberService.getMemberById(id);
return member;
}
3.MemberRepostiory.xml
<select id="getMemberByLoginId" resultType ="com.kjh.exam.demo.vo.Member">
SELECT * FROM `member`
WHERE loginId = #{loginId}
</select>
MemberController
if (loginId == null || loginId.trim().length() == 0) {
return "아이디를 입력 해주세요.";
}
if (loginPw == null || loginPw.trim().length() == 0) {
return "비밀번호를 입력 해주세요.";
}
if (name == null || name.trim().length() == 0) {
return "이름을 입력 해주세요.";
}
if (nickname == null || nickname.trim().length() == 0) {
return "닉네임을 입력 해주세요.";
}
if (cellphoneNum == null || cellphoneNum.trim().length() == 0) {
return "전화번호를 입력 해주세요.";
}
if (email == null || email.trim().length() == 0) {
return "이메일을 입력 해주세요.";
}
1. UsrMemberController
if (Ut.empty(loginId)) {
return "아이디를 입력 해주세요.";
}
if (Ut.empty(loginPw)) {
return "비밀번호를 입력 해주세요.";
}
2.Ut.class
public class Ut {
public static boolean empty(Object obj) {
if (obj == null) {
return true;
}
if (obj instanceof String == false) {
return true;
}
String str = (String) obj;
return str.trim().length() == 0;
}
1. MemberService
public int doJoin(String loginId, String loginPw, String name, String nickname, String cellphoneNum, String email) {
// 로그인아이디 중복체크
Member existsMember = getMemberByLoginId(loginId);
if (existsMember != null) {
return -1;
}
// 이름과 이메일 중복체크
existsMember = getMemberByNameAndEmail(name, email);
if(existsMember !=null) {
return -2;
}
memberRepository.doJoin(loginId, loginPw, name, nickname, cellphoneNum, email);
int id = memberRepository.getLastInsertId();
return id;
}
2. MemberController
int id = memberService.doJoin(loginId, loginPw, name, nickname, cellphoneNum, email);
if (id == -1) {
return "중복 되는 아이디가 있습니다.";
}
if (id == -2) {
return "이미 사용중인 이름과 이메일입니다.";
}
3. MemberRepository.xml
<select id="getMemberByNameAndEmail" resultType ="com.kjh.exam.demo.vo.Member">
SELECT * FROM `member`
WHERE `name` = #{name}
AND email = #{email}
</select>
1. MemberController
if (id == -1) {
return Ut.f("이미 사용중인 아이디(%s)입니다", loginId);
}
if (id == -2) {
return Ut.f("이미 사용중인 이름(%s)과 이메일(%s)입니다.",name,email);
}
2. Ut.f()
public static String f(String format, Object... args) {
return String.format(format, args);
}