관리 메뉴

거니의 velog

231216_SPRING CRUD 보강 2 본문

대덕인재개발원/대덕인재개발원_웹기반 애플리케이션

231216_SPRING CRUD 보강 2

Unlimited00 2023. 12. 15. 17:02

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div class="page-header min-vh-100">
	<div class="container">
		<div class="row">
			<div class="col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 start-0 text-center justify-content-center flex-column">
				<div class="position-relative bg-gradient-info h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center"
					style="background-image: url('${pageContext.request.contextPath}/resources/assets/img/illustrations/illustration-lock.jpg'); background-size: cover;">
				</div>
			</div>
			<div
				class="col-xl-4 col-lg-5 col-md-7 d-flex flex-column ms-auto me-auto ms-lg-auto me-lg-5">
				<div class="card card-plain">
					<div class="card-header">
						<h4 class="font-weight-bolder">회원가입</h4>
						<p class="mb-0">회원등록 후, 저희 서비스와 함께해요!</p>
					</div>
					<div class="card-body">
						<form role="form" method="post" action="/signup.do" id="signupForm">
							<font class="font-weight-bold text-xs mt-1 mb-0 error"><!-- 아이디 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memId" name="memId" placeholder="아이디">
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 비밀번호 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memPw" name="memPw" placeholder="비밀번호">
							</div>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memPwRe" placeholder="비밀번호 재입력">
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 이름 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memName" name="memName" placeholder="이름">
							</div>
							<font class="font-weight-bold text-xs mt-1 mb-0 error"><!-- 닉네임 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memNickname" name="memNickname" placeholder="닉네임">
								<input type="button" class="form-control" id="nickChkBtn" value="중복확인"/>
							</div>
							<div class="form-check form-switch">
								<input class="form-check-input" type="checkbox" id="agree" value="Y"> 
								<label class="form-check-label" for="agree">개인정보 동의</label>
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"></font>
							<div class="text-center">
								<button type="button" class="btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0" id="signupBtn">가입하기</button>
							</div>
						</form>
					</div>
					<div class="card-footer text-center pt-0 px-lg-2 px-1">
						<p class="mb-2 text-sm mx-auto">
							우리 서비스 회원이세요? 
							<a href="/signin.do" class="text-primary text-gradient font-weight-bold">로그인</a>
						</p>
						<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 가입하기 에러처리 --></font>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(function(){
		var memId = $("#memId");
		var idFlag = false; // 아이디 중복체크 여부 flag
		
		// 아이디를 입력하기 위한 element에 아이디를 입력할 때마다 해당 이벤트가 동작한다.
		memId.keyup(function(){
			var id = $(this).val();
			
			if(id.length < 4) {
				errPrint(0, "아이디는 4자리부터 시작합니다!", "red");
				return false;
			}
			
			var data = {
				memId : id
			};
			
			$.ajax({
				type: "post",
				url: "/idCheck.do",
				data: JSON.stringify(data),
				dataType: "text",
				contentType: "application/json;charset=utf-8",
				success: function(res) {
					if(res === "NOTEXIST") {
						errPrint(0, "사용 가능한 아이디입니다!", "green");
						idFlag = true;
					}else{
						errPrint(0, "아이디가 중복됩니다!", "red");
						idFlag = false;
					}
				}
			});
		});
	});
	
	function errPrint(cnt, comp, color){
		$(".error:eq("+cnt+")").text(comp).attr("color", color);
	}
</script>

package kr.or.ddit.controller.conn;

import java.util.Map;

import javax.inject.Inject;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.service.ILoginService;

@Controller
public class LoginController {
	
	@Inject
	private ILoginService loginService;
	
	@RequestMapping(value="/signin.do", method = RequestMethod.GET)
	public String signIn() {
		return "conn/signin";
	}
	
	@RequestMapping(value="/signup.do", method = RequestMethod.GET)
	public String signUpForm() {
		return "conn/signup";
	}
	
	@RequestMapping(value = "/idCheck.do", method = RequestMethod.POST, produces = "text/plain; charset=utf-8")
	public ResponseEntity<String> idCheck(@RequestBody Map<String, String> map){
		ServiceResult result = loginService.idCheck(map.get("memId"));
		return new ResponseEntity<String>(result.toString(), HttpStatus.OK);
	}
}
package kr.or.ddit.service;

import kr.or.ddit.ServiceResult;

public interface ILoginService {

	public ServiceResult idCheck(String memId);

}
package kr.or.ddit.service.impl;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.mapper.ILoginMapper;
import kr.or.ddit.service.ILoginService;
import kr.or.ddit.vo.MemberVO;

@Service
public class LoginServiceImpl implements ILoginService {

	@Inject
	private ILoginMapper loginMapper;
	
	@Override
	public ServiceResult idCheck(String memId) {
		ServiceResult result = null;
		
		MemberVO memberVO = loginMapper.idCheck(memId);
		if(memberVO != null) {
			result = ServiceResult.EXIST;
		}else {
			result = ServiceResult.NOTEXIST;
		}
		
		return result;
	}

}
package kr.or.ddit.mapper;

import kr.or.ddit.vo.MemberVO;

public interface ILoginMapper {

	public MemberVO idCheck(String memId);

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.or.ddit.mapper.ILoginMapper">

	<select id="idCheck" parameterType="string" resultType="memberVO">
		select 
			mem_no, mem_id, mem_pw, mem_name, mem_nickname, mem_regdate 
		from member 
		where mem_id = #{memId}
	</select>

</mapper>

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
  PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>

	<settings>
		<setting name="mapUnderscoreToCamelCase" value="true"/>
	</settings>
	
	<typeAliases>
		<typeAlias type="kr.or.ddit.vo.MemberVO" alias="memberVO"/>
	</typeAliases>

</configuration>


<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div class="page-header min-vh-100">
	<div class="container">
		<div class="row">
			<div class="col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 start-0 text-center justify-content-center flex-column">
				<div class="position-relative bg-gradient-info h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center"
					style="background-image: url('${pageContext.request.contextPath}/resources/assets/img/illustrations/illustration-lock.jpg'); background-size: cover;">
				</div>
			</div>
			<div
				class="col-xl-4 col-lg-5 col-md-7 d-flex flex-column ms-auto me-auto ms-lg-auto me-lg-5">
				<div class="card card-plain">
					<div class="card-header">
						<h4 class="font-weight-bolder">회원가입</h4>
						<p class="mb-0">회원등록 후, 저희 서비스와 함께해요!</p>
					</div>
					<div class="card-body">
						<form role="form" method="post" action="/signup.do" id="signupForm">
							<font class="font-weight-bold text-xs mt-1 mb-0 error"><!-- 아이디 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memId" name="memId" placeholder="아이디">
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 비밀번호 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memPw" name="memPw" placeholder="비밀번호">
							</div>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memPwRe" placeholder="비밀번호 재입력">
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 이름 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memName" name="memName" placeholder="이름">
							</div>
							<font class="font-weight-bold text-xs mt-1 mb-0 error"><!-- 닉네임 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memNickname" name="memNickname" placeholder="닉네임">
								<input type="button" class="form-control" id="nickChkBtn" value="중복확인"/>
							</div>
							<div class="form-check form-switch">
								<input class="form-check-input" type="checkbox" id="agree" value="Y"> 
								<label class="form-check-label" for="agree">개인정보 동의</label>
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"></font>
							<div class="text-center">
								<button type="button" class="btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0" id="signupBtn">가입하기</button>
							</div>
						</form>
					</div>
					<div class="card-footer text-center pt-0 px-lg-2 px-1">
						<p class="mb-2 text-sm mx-auto">
							우리 서비스 회원이세요? 
							<a href="/signin.do" class="text-primary text-gradient font-weight-bold">로그인</a>
						</p>
						<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 가입하기 에러처리 --></font>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(function(){
		var memId = $("#memId");
		var nickChkBtn = $("#nickChkBtn");
		var idFlag = false; // 아이디 중복체크 여부 flag
		var nickFlag = false; // 닉네임 중복체크 여부 flag
		
		// 아이디를 입력하기 위한 element에 아이디를 입력할 때마다 해당 이벤트가 동작한다.
		memId.keyup(function(){
			var id = $(this).val();
			
			if(id.length < 4) {
				errPrint(0, "아이디는 4자리부터 시작합니다!", "red");
				return false;
			}
			
			var data = {
				memId : id
			};
			
			$.ajax({
				type: "post",
				url: "/idCheck.do",
				data: JSON.stringify(data),
				dataType: "text",
				contentType: "application/json;charset=utf-8",
				success: function(res) {
					if(res === "NOTEXIST") {
						errPrint(0, "사용 가능한 아이디입니다!", "green");
						idFlag = true;
					}else{
						errPrint(0, "아이디가 중복됩니다!", "red");
						idFlag = false;
					}
				}
			});
		});
		
		nickChkBtn.on("click", function(){
			var nickname = $("#memNickname").val();
			
			if(!nickname) {
				errPrint(3, "닉네임을 입력해주세요!", "red");
				return false;
			}
			
			var data = {
				memNickname : nickname
			};
			
			$.ajax({
				type: "post",
				url: "/nickNameCheck.do",
				data: JSON.stringify(data),
				dataType: "text",
				contentType: "application/json;charset=utf-8",
				success: function(res) {
					if(res === "NOTEXIST") {
						errPrint(3, "사용 가능한 닉네임입니다!", "green");
						nickFlag = true;
					}else{
						errPrint(3, "닉네임이 중복됩니다!", "red");
						nickFlag = false;
					}
				}
			});
		});
	});
	
	function errPrint(cnt, comp, color){
		$(".error:eq("+cnt+")").text(comp).attr("color", color);
	}
</script>
package kr.or.ddit.controller.conn;

import java.util.Map;

import javax.inject.Inject;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.service.ILoginService;

@Controller
public class LoginController {
	
	@Inject
	private ILoginService loginService;
	
	@RequestMapping(value="/signin.do", method = RequestMethod.GET)
	public String signIn() {
		return "conn/signin";
	}
	
	@RequestMapping(value="/signup.do", method = RequestMethod.GET)
	public String signUpForm() {
		return "conn/signup";
	}
	
	@RequestMapping(value = "/idCheck.do", method = RequestMethod.POST, produces = "text/plain; charset=utf-8")
	public ResponseEntity<String> idCheck(@RequestBody Map<String, String> map){
		ServiceResult result = loginService.idCheck(map.get("memId"));
		return new ResponseEntity<String>(result.toString(), HttpStatus.OK);
	}
	
	@RequestMapping(value = "/nickNameCheck.do", method = RequestMethod.POST, produces = "text/plain; charset=utf-8")
	public ResponseEntity<String> nickNameCheck(@RequestBody Map<String, String> map){
		ServiceResult result = loginService.nickNameCheck(map.get("memNickname"));
		return new ResponseEntity<String>(result.toString(), HttpStatus.OK);
	}
	
}
package kr.or.ddit.service;

import kr.or.ddit.ServiceResult;

public interface ILoginService {

	public ServiceResult idCheck(String memId);
	public ServiceResult nickNameCheck(String memNickname);

}
package kr.or.ddit.service.impl;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.mapper.ILoginMapper;
import kr.or.ddit.service.ILoginService;
import kr.or.ddit.vo.MemberVO;

@Service
public class LoginServiceImpl implements ILoginService {

	@Inject
	private ILoginMapper loginMapper;
	
	@Override
	public ServiceResult idCheck(String memId) {
		ServiceResult result = null;
		
		MemberVO memberVO = loginMapper.idCheck(memId);
		if(memberVO != null) {
			result = ServiceResult.EXIST;
		}else {
			result = ServiceResult.NOTEXIST;
		}
		
		return result;
	}

	@Override
	public ServiceResult nickNameCheck(String memNickname) {
		ServiceResult result = null;
		
		MemberVO memberVO = loginMapper.nickNameCheck(memNickname);
		if(memberVO != null) {
			result = ServiceResult.EXIST;
		}else {
			result = ServiceResult.NOTEXIST;
		}
		
		return result;
	}

}
package kr.or.ddit.mapper;

import kr.or.ddit.vo.MemberVO;

public interface ILoginMapper {

	public MemberVO idCheck(String memId);
	public MemberVO nickNameCheck(String memNickname);

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.or.ddit.mapper.ILoginMapper">

	<select id="idCheck" parameterType="string" resultType="memberVO">
		select 
			mem_no, mem_id, mem_pw, mem_name, mem_nickname, mem_regdate 
		from member 
		where mem_id = #{memId}
	</select>
	
	<select id="nickNameCheck" parameterType="string" resultType="memberVO">
		select 
			mem_no, mem_id, mem_pw, mem_name, mem_nickname, mem_regdate 
		from member 
		where mem_nickname = #{memNickname}
	</select>

</mapper>


<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div class="page-header min-vh-100">
	<div class="container">
		<div class="row">
			<div class="col-6 d-lg-flex d-none h-100 my-auto pe-0 position-absolute top-0 start-0 text-center justify-content-center flex-column">
				<div class="position-relative bg-gradient-info h-100 m-3 px-7 border-radius-lg d-flex flex-column justify-content-center"
					style="background-image: url('${pageContext.request.contextPath}/resources/assets/img/illustrations/illustration-lock.jpg'); background-size: cover;">
				</div>
			</div>
			<div
				class="col-xl-4 col-lg-5 col-md-7 d-flex flex-column ms-auto me-auto ms-lg-auto me-lg-5">
				<div class="card card-plain">
					<div class="card-header">
						<h4 class="font-weight-bolder">회원가입</h4>
						<p class="mb-0">회원등록 후, 저희 서비스와 함께해요!</p>
					</div>
					<div class="card-body">
						<form role="form" method="post" action="/signup.do" id="signupForm">
							<font class="font-weight-bold text-xs mt-1 mb-0 error"><!-- 아이디 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memId" name="memId" placeholder="아이디">
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 비밀번호 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memPw" name="memPw" placeholder="비밀번호">
							</div>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memPwRe" placeholder="비밀번호 재입력">
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 이름 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memName" name="memName" placeholder="이름">
							</div>
							<font class="font-weight-bold text-xs mt-1 mb-0 error"><!-- 닉네임 에러처리 --></font>
							<div class="input-group input-group-outline mb-3">
								<input type="text" class="form-control" id="memNickname" name="memNickname" placeholder="닉네임">
								<input type="button" class="form-control" id="nickChkBtn" value="중복확인"/>
							</div>
							<div class="form-check form-switch">
								<input class="form-check-input" type="checkbox" id="agree" value="Y"> 
								<label class="form-check-label" for="agree">개인정보 동의</label>
							</div>
							<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"></font>
							<div class="text-center">
								<button type="button" class="btn btn-lg bg-gradient-primary btn-lg w-100 mt-4 mb-0" id="signupBtn">가입하기</button>
							</div>
						</form>
					</div>
					<div class="card-footer text-center pt-0 px-lg-2 px-1">
						<p class="mb-2 text-sm mx-auto">
							우리 서비스 회원이세요? 
							<a href="/signin.do" class="text-primary text-gradient font-weight-bold">로그인</a>
						</p>
						<font class="text-primary font-weight-bold text-xs mt-1 mb-0 error"><!-- 가입하기 에러처리 --></font>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	$(function(){
		var memId = $("#memId");
		var nickChkBtn = $("#nickChkBtn");
		var signupBtn = $("#signupBtn");
		var signupForm = $("#signupForm");
		var idFlag = false; // 아이디 중복체크 여부 flag
		var nickFlag = false; // 닉네임 중복체크 여부 flag
		
		// 아이디를 입력하기 위한 element에 아이디를 입력할 때마다 해당 이벤트가 동작한다.
		memId.keyup(function(){
			var id = $(this).val();
			
			if(id.length < 4) {
				errPrint(0, "아이디는 4자리부터 시작합니다!", "red");
				return false;
			}
			
			var data = {
				memId : id
			};
			
			$.ajax({
				type: "post",
				url: "/idCheck.do",
				data: JSON.stringify(data),
				dataType: "text",
				contentType: "application/json;charset=utf-8",
				success: function(res) {
					if(res === "NOTEXIST") {
						errPrint(0, "사용 가능한 아이디입니다!", "green");
						idFlag = true;
					}else{
						errPrint(0, "아이디가 중복됩니다!", "red");
						idFlag = false;
					}
				}
			});
		});
		
		nickChkBtn.on("click", function(){
			var nickname = $("#memNickname").val();
			
			if(!nickname) {
				errPrint(3, "닉네임을 입력해주세요!", "red");
				return false;
			}
			
			var data = {
				memNickname : nickname
			};
			
			$.ajax({
				type: "post",
				url: "/nickNameCheck.do",
				data: JSON.stringify(data),
				dataType: "text",
				contentType: "application/json;charset=utf-8",
				success: function(res) {
					if(res === "NOTEXIST") {
						errPrint(3, "사용 가능한 닉네임입니다!", "green");
						nickFlag = true;
					}else{
						errPrint(3, "닉네임이 중복됩니다!", "red");
						nickFlag = false;
					}
				}
			});
		});
		
		signupBtn.on("click", function(){
			var color = "red";
			var id = $("#memId").val();
			var pw = $("#memPw").val();
			var pwre = $("#memPwRe").val();
			var name = $("#memName").val();
			var nickname = $("#memNickname").val();
			var agree = $("#agree:checked").val();
			var pwFlag = true; // 비밀번호 일치 여부(비밀번호 = 재입력 비밀번호)
			var agreeFlag = false;
			
			errInit();
			
			if(!id) {
				errPrint(0, "아이디를 입력해 주세요.", color);
				return false;
			}
			
			if(!pw) {
				errPrint(1, "비밀번호를 입력해 주세요.", color);
				return false;
			}
			if(!pwre) {
				errPrint(1, "비밀번호 재입력을 입력해 주세요.", color);
				return false;
			}
			if(pw != pwre) {
				errPrint(1, "비밀번호가 일치하지 않습니다.", color);
				pwFlag = false; // 비밀번호 불일치
				return false;
			}
			
			if(!name) {
				errPrint(2, "이름을 입력해 주세요.", color);
				return false;
			}
			
			if(!nickname) {
				errPrint(3, "닉네임을 입력해 주세요.", color);
				return false;
			}
			
			if(agree != 'Y') {
				errPrint(4, "개인정보 동의에 체크해주세요.", color);
				return false;
			}else {
				agreeFlag = true;
			}
			
			if(pwFlag && idFlag && nickFlag && agreeFlag) {
				signupForm.submit();
			}else {
				if(!pwFlag) {
					errPrint(5, "비밀번호가 일치하지 않아 진행할 수 없습니다.", color);
				}
				if(!idFlag) {
					errPrint(5, "아이디 중복체크 해주세요.", color);
				}
				if(!nickFlag) {
					errPrint(5, "닉네임 중복체크 해주세요.", color);
				}
				if(!agreeFlag) {
					errPrint(5, "개인정보 동의에 체크되어 있지 않습니다.", color);
				}
			}
			
			
		});
	});
	
	function errPrint(cnt, comp, color){
		$(".error:eq("+cnt+")").text(comp).attr("color", color);
	}
	
	function errInit(){
		$(".error").text("");
	}
</script>
package kr.or.ddit.controller.conn;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.service.ILoginService;
import kr.or.ddit.vo.MemberVO;

@Controller
public class LoginController {
	
	@Inject
	private ILoginService loginService;
	
	@RequestMapping(value="/signin.do", method = RequestMethod.GET)
	public String signIn() {
		return "conn/signin";
	}
	
	@RequestMapping(value="/signup.do", method = RequestMethod.GET)
	public String signUpForm() {
		return "conn/signup";
	}
	
	@RequestMapping(value = "/signup.do", method = RequestMethod.POST)
	public String signup(MemberVO member, Model model, RedirectAttributes ra) {
		String goPage = "";
		
		Map<String, String> errors = new HashMap<String, String>();
		if(StringUtils.isBlank(member.getMemId())) {
			errors.put("memId", "아이디를 입력해주세요");
		}
		if(StringUtils.isBlank(member.getMemPw())) {
			errors.put("memPw", "비밀번호를 입력해주세요");
		}
		if(StringUtils.isBlank(member.getMemName())) {
			errors.put("memName", "이름을 입력해주세요");
		}
		if(StringUtils.isBlank(member.getMemNickname())) {
			errors.put("memNickname", "닉네임을 입력해주세요");
		}
		
		if(errors.size() > 0) { // 에러가 있음
			model.addAttribute("errors", errors);
			model.addAttribute("MemberVO", member);
			goPage = "conn/signup"; // tiles의 definition으로 설정되어 있는 name 속성의 값과 매핑된다.
		}else {
			ServiceResult result = loginService.signup(member);
			if(result.equals(ServiceResult.OK)) { // 등록 성공
				ra.addFlashAttribute("message", "회원가입이 완료되었습니다.");
				goPage = "redirect:/signin.do";
			}else { // 등록 실패
				model.addAttribute("message", "서버에러, 다시 시도해 주세요.");
				model.addAttribute("MemberVO", member);
				goPage = "conn/signup";
			}
		}
		
		return goPage;
	}
	
	@RequestMapping(value = "/idCheck.do", method = RequestMethod.POST, produces = "text/plain; charset=utf-8")
	public ResponseEntity<String> idCheck(@RequestBody Map<String, String> map){
		ServiceResult result = loginService.idCheck(map.get("memId"));
		return new ResponseEntity<String>(result.toString(), HttpStatus.OK);
	}
	
	@RequestMapping(value = "/nickNameCheck.do", method = RequestMethod.POST, produces = "text/plain; charset=utf-8")
	public ResponseEntity<String> nickNameCheck(@RequestBody Map<String, String> map){
		ServiceResult result = loginService.nickNameCheck(map.get("memNickname"));
		return new ResponseEntity<String>(result.toString(), HttpStatus.OK);
	}
	
}
package kr.or.ddit.service;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.vo.MemberVO;

public interface ILoginService {

	public ServiceResult idCheck(String memId);
	public ServiceResult nickNameCheck(String memNickname);
	public ServiceResult signup(MemberVO member);

}
package kr.or.ddit.service.impl;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import kr.or.ddit.ServiceResult;
import kr.or.ddit.mapper.ILoginMapper;
import kr.or.ddit.service.ILoginService;
import kr.or.ddit.vo.MemberVO;

@Service
public class LoginServiceImpl implements ILoginService {

	@Inject
	private ILoginMapper loginMapper;
	
	@Override
	public ServiceResult idCheck(String memId) {
		ServiceResult result = null;
		
		MemberVO memberVO = loginMapper.idCheck(memId);
		if(memberVO != null) {
			result = ServiceResult.EXIST;
		}else {
			result = ServiceResult.NOTEXIST;
		}
		
		return result;
	}

	@Override
	public ServiceResult nickNameCheck(String memNickname) {
		ServiceResult result = null;
		
		MemberVO memberVO = loginMapper.nickNameCheck(memNickname);
		if(memberVO != null) {
			result = ServiceResult.EXIST;
		}else {
			result = ServiceResult.NOTEXIST;
		}
		
		return result;
	}

	@Override
	public ServiceResult signup(MemberVO member) {
		ServiceResult result = null;
		
		int status = loginMapper.signup(member);
		if(status > 0) {
			result = ServiceResult.OK;
		}else {
			result = ServiceResult.FAILED;
		}
		
		return result;
	}

}
package kr.or.ddit.mapper;

import kr.or.ddit.vo.MemberVO;

public interface ILoginMapper {

	public MemberVO idCheck(String memId);
	public MemberVO nickNameCheck(String memNickname);
	public int signup(MemberVO member);

}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="kr.or.ddit.mapper.ILoginMapper">

	<select id="idCheck" parameterType="string" resultType="memberVO">
		select 
			mem_no, mem_id, mem_pw, mem_name, mem_nickname, mem_regdate 
		from member 
		where mem_id = #{memId}
	</select>
	
	<select id="nickNameCheck" parameterType="string" resultType="memberVO">
		select 
			mem_no, mem_id, mem_pw, mem_name, mem_nickname, mem_regdate 
		from member 
		where mem_nickname = #{memNickname}
	</select>
	
	<insert id="signup" parameterType="memberVO">
		insert into member (
			mem_no, mem_id, mem_pw, mem_name, mem_nickname, mem_regdate 
		) values (
			seq_member.nextval, #{memId}, #{memPw}, #{memName}, #{memNickname}, sysdate
		)
	</insert>

</mapper>