고래씌

[MyBatis] 1-1. MyBaits 시작(lombok) 본문

Server/MyBatis

[MyBatis] 1-1. MyBaits 시작(lombok)

고래씌 2023. 12. 19. 11:51

1. MyBaits란?

: 데이터의 입력, 조회, 수정, 삭제(CRUD)를 보다 편하게 하기 위해 xml로 구조화한 Mapper설정파일을 통해 JDBC를 구현한 영속성 프레임 워크

☞ 기존 JDBC를 통해 구현했던 상당 부분의 코드와 파라미터 설정 및 결과 매핑을 xml설정을 통해 쉽게 구현할 수 있게 함

 

 

▶ 프레임워크

- 개발자가 보다 편리한 환경에서 개발할 수 있도록 제공하는 뼈대, 틀
- 소프트웨어 개발의 입장으로써는 공통으로 사용하는 라이브러리/ 개발도구/ 인터페이스 등을 의미한다.

 

 

▶ 프레임워크 왜 사용하는가?

- 거대하고 복잡도가 높은 프로젝트를 완성시키기 위해서는 많은 사람이 필요한데, 그 많은 개발자들이 "통일성"있고 빠르고, 안정적으로 개발하기 위해서는 프레임워크가 필요하기 때문이다.

 

 

▶ 프레임워크의 특징

- 자유롭게 설계하고 코딩하는게 아니라 프레임워크가 제공하는 가이드대로 설계해야한다.
- 개발범위가 정해져있다.
- 개발자를 위한 다양한 플러그인들이 지원됨

 

 

▶ 프레임워크의 장단점

장점 : 개발시간을 줄일 수 있음
             오류로부터 자유로워질 수 있음
단점 : 의존하다보면 개발능력이 떨어져서 프레임워크 없이 개발하는 것이 어렵다.
             습득까지 시간이 오래걸릴 수 있음

 

 

2. 파일 구성

 

 

▶ index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	 <jsp:forward page="WEB-INF/views/main.jsp"></jsp:forward>
	 <!-- 보안상 좀 더 유리하다! -->

</body>
</html>

 

▶ main.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<jsp:include page="common/menubar.jsp"/>

</body>
</html>

 

▶ menubar.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
	.login-area a{
		text-decoration : none;
		color : black;
		font-size : 12px;
	}
	
	.nav-area{
		background : pink;
		color : white;
		height : 50px;
	}
	
	.menu{
		display : table-cell;
		width : 250px;
		height : 50px;
		vertical-align : middle;
		font-size : 20px;
		font-weight: bold;
	}
	
	.menu:hover{
		background : darkgray;
		cursor : pointer;
	}
	
	.outer{
		width : 900px;
		background : pink;
		color : white;
		margin : auto;
		margin-top : 50px;
	}
</style>
</head>
<body>

	<h1 align="center">Welcome to MyBatis</h1>
	<br>
	
	<div class="login-area" align="right">
		<c:choose>
			
			<c:when test="${empty loginUser}">
				<!-- case 1. 로그인 전 화면 -->
				<form action="login.me" method="post">
					<table>
						<tr>
							<td>아이디</td>
							<td><input type="text" name="userId" required></td>
							<td rowspan="2"><button style="height:50px;">로그인</button></td>
						</tr>
						<tr>
							<td>비밀번호</td>
							<td><input type="password" name="userPwd" required></td>
						</tr>
						<tr>
							<td colspan="3" align="center">
								<a href="insert.me">회원가입</a> |
								<a href="">ID/비밀번호 찾기</a>
							</td>
						</tr>
					</table>
				</form>
			</c:when>
			
			<c:otherwise>
				<!-- case2. 로그인 후 화면 -->
				<div>
					<table>
						<tr>
							<td colspan="2">
								<h3>${loginUser.userName}님 환영합니다 ^^</h3>
							</td>
						</tr>
						<tr>
							<td>마이페이지</td>
							<td>로그아웃</td>
						</tr>
					</table>
				</div>
			</c:otherwise>
		</c:choose>
	</div>
	<br>
	
	<div class="nav-area" align="center">
		<div class="menu">HOME</div>
		<div class="menu">공지사항</div>
		<div class="menu">게시판</div>
		<div class="menu">etc</div>
	</div>
	
</body>
</html>

 

 

 

 

 

3. lombok 다운

=> 메이븐 레파지토리 홈페이지에서 lombok 다운

 

 

 

 

 

① lombok-1.18.30.jar 파일 실행

② 이클립스를 꺼두고 tools 파일 아래에 있는 eclipse.exe 파일 클릭

 

 

③ Install / Update 클릭 => Quit Installer

④ 다시 이클립스 실행

⑤ lib 폴더에 다운로드 했었던 lombok 파일 추가

 

 

'Server > MyBatis' 카테고리의 다른 글

[MyBatis] 3-1. 게시판 설정(페이징 설정)  (0) 2023.12.24
[MyBatis] 2. 암호화 설정  (0) 2023.12.24
[MyBatis] 1-3. 회원가입 만들기  (0) 2023.12.20
[MyBatis] 1-2. 로그인 기능  (0) 2023.12.19
[MyBatis] 0. MyBatis 설정  (0) 2023.12.19