22.08.29 - MyBatis, 대형 어플리케이션 구조, Maven 사용, Mapper 생성, Lombok

MyBatis → DAO 대체
https://mybatis.org/mybatis-3/ko/index.html
대형 어플리케이션 구조
Presentation Layer (표현 계층) : 사용자가 보게되는 디자인 영역
business Layer: 로직이 숨어있는 부분
DataBase Layer(영구 계층) : 데이터를 관리하는 영역→mybatis가 담당하는 영역
Maven
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>web0812</groupId>
<artifactId>web0812</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
</dependencies>
</project>
xml 생성
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.mybatis.example.BlogMapper">
<!--
앞으로 쿼리문은 java 클래스 안에 두지 말고, mybatis의 xml에 작성하자
지금까지 DAO에 작성했던 상투적이고 거창했던 JDBC 코드를 사용하는 것이 아니라
개발자가 쿼리문에 집중할 수 있고 유지보수성을 올리기 위한 SQL Mapper중 하나인
Mybatis 프레임웤을 이용한다...(Hibernate와 mybatis와는 약간의 차이_
-->
<insert id="">
insert into board(title, writer, content) values(#{},#{},#{})
</insert>
</mapper>
lombok→ DTO를 간단하게 해줌
실행 jar
powershell 에서 java -jar .\lombok.jar
코드
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.16</version> <scope>provided</scope> </dependency>

하면 이렇게 됨
'Program > JSP' 카테고리의 다른 글
| Mybatis JOIN 사용, MVC, Forward 데이터 전송, DispatcherServlet (0) | 2022.12.27 |
|---|---|
| Mybatis 사용 예제, Tomcat(HttpServletRequest, HttpSession, Application) (0) | 2022.12.27 |
| 대댓글 만들기 (0) | 2022.12.27 |
| 게시판 댓글 생성, 댓글 수 표시 (0) | 2022.12.25 |
| Connection Manager, DBManager, PoolManager (0) | 2022.12.25 |