[오픈소스컨설팅]MyBatis BasicJi-Woong ChoiThe MyBatis data mapper framework makes it easier to use a relational database with object-oriented applications. This document explain about MyBatis basic concept.
overview of spring4Arawn Park제 14회 한국 자바 개발자 컨퍼런스의 커뮤니티 세션에서 공유한 `overview of spring4` 의 발표 자료
스프링 프레임워크는 2004년에 출시된 이후 지금까지 많은 변화를 겪어왔습니다. 기억에 남아 있는 굴직한 변화를 더듬어 보면 버전 2.0은 XML 네임스페이스와 AspectJ 지원, 버전 2.5부터 애노테이션을 활용한 프로그래밍 기능이 추가되었습니다. 그리고 버전 3.0으로 올라가며 Java 5+ 기반으로 코드 구조가 바뀌고 자바 코드 기반 설정 기능이 추가되었습니다. 2013년 12월 13일에 버전 4.0 발표이 발표되었습니다. 주목할 변화는 바로 Java 8 지원과 제거 대상(@Deprecated)으로 선언되었던 많은 클래스와 메소드들이 삭제되었다는 것입니다. 이 외에도 많은 변화가 있습니다. 이번 시간에는 조금 높은 곳에서 내려다보는 느낌으로 무엇이 추가되었고, 어떤게 바뀌었는지 살펴보려고 합니다.
예제코드 : https://github.com/arawn/overview-of-spring4
[자바학원/스프링교육학원/마이바티스학원추천/구로IT학원_탑크리에듀]#7.스프링프레임워크 & 마이바티스 (Spring Framework, M...탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀(www.topcredu.co.kr)제공
#7.스프링프레임워크 & 마이바티스(Spring Framework, MyBatis)자료는 SpEL을 이용한 Value Injection(XML방식),
SpEL을 이용한 Value Injection(어노테이션 방식),ref 태그를 이용한 Value Injection(ref local, ref bean, id, name의 차이) 등을 담은 자료입니다. 많은 도움되셨길 바랍니다.^^
교육/수강문의, 재직자/실업자 환급교육문의는 교육센터홈페이지(www.topcredu.co.kr)를 통해하여 하실 수 있습니다.
(스프링교육/마이바티스교육학원추천_탑크리에듀)#10.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀교육센터(www.topcredu.co.kr)제공
스프링프레임워크 & 마이바티스에 대해 설명한 자료입니다.
많은 참고 바랍니다.
스프링프레임워크 & 마이바티스 ☆ 무.료 강의자료 제공 中탑크리에듀(구로디지털단지역3번출구 2분거리)[스프링프레임워크 & 마이바티스 ☆ 무.료 강의자료 제공 中★
♡ 좋아요! 하고 더많은 자료 받아보세요 :) :) :) :) !!!!
[ 제 4장 ] _ Spring jdbc
[ 목 차 ]
4.3 Spring JDBC에서 DB 접근하는 방법
4.3.2 Spring JDBC에서 DB 접근하는 방법 – NamedParameterJdbcTemplate
4.3.3 Spring JDBC에서 DB 접근하는 방법 - SimpleJdbcTemplate
4.3.4 Spring JDBC에서 DB 접근하는 방법 – SimpleJdbcCall
4.3.5 Spring JDBC에서 DB 접근하는 방법 – SqlUpdate
4.3.6 Spring JDBC에서 DB 접근하는 방법 – StoredProcedure
4.3.7 오라클 시퀀스를 위한 DataFieldMaxValueIncrementer
[#더많은자료, #꿀강의, #꿀강좌, #구로오라클학원 #탑크리에듀 #재직자양성과정 #구직자양성과정 #홍보마케팅부서 #규찡]
http://www.topcredu.co.kr/
#구로자바학원 #구로오라클학원 #구로디지털단지역 #탑크리에듀
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀교육센터(www.topcredu.co.kr)제공
15번째 스프링프레임워크 & 마이바티스(Spring Framework, MyBatis)자료입니다.
Spring JDBC에서 DB 접근하는 방법, Spring JDBC에서 DB 접근하는 방법 – jdbcTemplate, Maven, Gradle에서 오라클 설정에 대해 설명한 자료이니 많은 참고 바랍니다.
스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다.
군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다.
This presentation is about Spring framework.
I want to talk about the way to setting the spring framework as tidy in this presentation.
#33.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀교육센터(www.topcredu.co.kr)제공
스프링프레임워크 & 마이바티스에 대한 자료이니 참고하시어 많은 도움되시길 바랍니다.
교육/수강문의는 탑크리에듀홈페이지(http://www.topcredu.co.kr)를 통하여 하실 수 있습니다.
overview of spring4Arawn Park제 14회 한국 자바 개발자 컨퍼런스의 커뮤니티 세션에서 공유한 `overview of spring4` 의 발표 자료
스프링 프레임워크는 2004년에 출시된 이후 지금까지 많은 변화를 겪어왔습니다. 기억에 남아 있는 굴직한 변화를 더듬어 보면 버전 2.0은 XML 네임스페이스와 AspectJ 지원, 버전 2.5부터 애노테이션을 활용한 프로그래밍 기능이 추가되었습니다. 그리고 버전 3.0으로 올라가며 Java 5+ 기반으로 코드 구조가 바뀌고 자바 코드 기반 설정 기능이 추가되었습니다. 2013년 12월 13일에 버전 4.0 발표이 발표되었습니다. 주목할 변화는 바로 Java 8 지원과 제거 대상(@Deprecated)으로 선언되었던 많은 클래스와 메소드들이 삭제되었다는 것입니다. 이 외에도 많은 변화가 있습니다. 이번 시간에는 조금 높은 곳에서 내려다보는 느낌으로 무엇이 추가되었고, 어떤게 바뀌었는지 살펴보려고 합니다.
예제코드 : https://github.com/arawn/overview-of-spring4
[자바학원/스프링교육학원/마이바티스학원추천/구로IT학원_탑크리에듀]#7.스프링프레임워크 & 마이바티스 (Spring Framework, M...탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀(www.topcredu.co.kr)제공
#7.스프링프레임워크 & 마이바티스(Spring Framework, MyBatis)자료는 SpEL을 이용한 Value Injection(XML방식),
SpEL을 이용한 Value Injection(어노테이션 방식),ref 태그를 이용한 Value Injection(ref local, ref bean, id, name의 차이) 등을 담은 자료입니다. 많은 도움되셨길 바랍니다.^^
교육/수강문의, 재직자/실업자 환급교육문의는 교육센터홈페이지(www.topcredu.co.kr)를 통해하여 하실 수 있습니다.
(스프링교육/마이바티스교육학원추천_탑크리에듀)#10.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀교육센터(www.topcredu.co.kr)제공
스프링프레임워크 & 마이바티스에 대해 설명한 자료입니다.
많은 참고 바랍니다.
스프링프레임워크 & 마이바티스 ☆ 무.료 강의자료 제공 中탑크리에듀(구로디지털단지역3번출구 2분거리)[스프링프레임워크 & 마이바티스 ☆ 무.료 강의자료 제공 中★
♡ 좋아요! 하고 더많은 자료 받아보세요 :) :) :) :) !!!!
[ 제 4장 ] _ Spring jdbc
[ 목 차 ]
4.3 Spring JDBC에서 DB 접근하는 방법
4.3.2 Spring JDBC에서 DB 접근하는 방법 – NamedParameterJdbcTemplate
4.3.3 Spring JDBC에서 DB 접근하는 방법 - SimpleJdbcTemplate
4.3.4 Spring JDBC에서 DB 접근하는 방법 – SimpleJdbcCall
4.3.5 Spring JDBC에서 DB 접근하는 방법 – SqlUpdate
4.3.6 Spring JDBC에서 DB 접근하는 방법 – StoredProcedure
4.3.7 오라클 시퀀스를 위한 DataFieldMaxValueIncrementer
[#더많은자료, #꿀강의, #꿀강좌, #구로오라클학원 #탑크리에듀 #재직자양성과정 #구직자양성과정 #홍보마케팅부서 #규찡]
http://www.topcredu.co.kr/
#구로자바학원 #구로오라클학원 #구로디지털단지역 #탑크리에듀
(IT실무교육/국비지원교육/자바/스프링교육추천)#15.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀교육센터(www.topcredu.co.kr)제공
15번째 스프링프레임워크 & 마이바티스(Spring Framework, MyBatis)자료입니다.
Spring JDBC에서 DB 접근하는 방법, Spring JDBC에서 DB 접근하는 방법 – jdbcTemplate, Maven, Gradle에서 오라클 설정에 대해 설명한 자료이니 많은 참고 바랍니다.
스프링군살없이세팅하기(The way to setting the Spring framework for web.)EunChul Shin깔끔하게 스프링 프레임워크 세팅하는 것에 대한 이야기 입니다.
군살없이 프레임워크를 세팅한다는 의미와 이유, 그리고 스프링 기본 설정 및 설정들의 역할에 대해서 정리해 보았습니다.
This presentation is about Spring framework.
I want to talk about the way to setting the spring framework as tidy in this presentation.
#33.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...탑크리에듀(구로디지털단지역3번출구 2분거리)탑크리에듀교육센터(www.topcredu.co.kr)제공
스프링프레임워크 & 마이바티스에 대한 자료이니 참고하시어 많은 도움되시길 바랍니다.
교육/수강문의는 탑크리에듀홈페이지(http://www.topcredu.co.kr)를 통하여 하실 수 있습니다.
3. http://blog.naver.com/amelia670
왜 MyBatis인가?
발표 주제를 MyBatis로 선정한 이유
- 실무 기반 프레임워크
2016년 롯데정보통신 프로그래머 채용 시험에서 가산점
Spring, Mybatis, AgularJS, Express
목적
실무에서 활발히 사용되고 있으나 우리는 잘 몰랐던 것들 이번 기회에 알고 가자
Q. 발표를 들으며 드는 궁금한 점과 무엇을 더 할 수 있을지 생각하기
3
5. http://blog.naver.com/amelia670
왜 MyBatis인가?
MyBatis가 왜 좋은가?
MyBatis eliminates almost all of the JDBC code and manual
setting of parameters and retrieval of results. MyBatis can use
simple XML or Annotations for configuration and map primitives,
Map interfaces and Java POJOs (Plain Old Java Objects) to
database records.
마이바티스는 JDBC로 처리하는 상당부분의 코드와 파라미터 설정및
결과 매핑을 대신해준다. 마이바티스는 데이터베이스 레코드에 원시
타입과 Map 인터페이스 그리고 자바 POJO 를 설정해서 매핑하기
위해 XML과 애노테이션을 사용할 수 있다.
원문 : http://www.mybatis.org/mybatis-3/index.html
번역 : http://www.mybatis.org/mybatis-3/ko/index.html
5
6. http://blog.naver.com/amelia670
원문 : http://www.mybatis.org/mybatis-3/index.html
번역 : http://www.mybatis.org/mybatis-3/ko/index.html
MyBatis가 왜 좋은가?
MyBatis eliminates almost all of the JDBC code and manual
setting of parameters and retrieval of results. MyBatis can use
simple XML or Annotations for configuration and map primitives,
Map interfaces and Java POJOs (Plain Old Java Objects) to
database records.
마이바티스는 JDBC로 처리하는 상당부분의 코드와 파라미터 설정및
결과 매핑을 대신해준다. 마이바티스는 데이터베이스 레코드에 원시
타입과 Map 인터페이스 그리고 자바 POJO 를 설정해서 매핑하기
위해 XML과 애노테이션을 사용할 수 있다.
왜 MyBatis인가?
소스 코드를 줄인다.
6
7. http://blog.naver.com/amelia670
왜 MyBatis인가?
MyBatis가 왜 좋은가? 소스코드를 줄인다.
- JDBC를 이용한 Java와 DB 연결하는 코드
public Student findStudentById(int studId)
{
Student student = null;
Connection conn = null;
try{
//obtain connection
conn = getDatabaseConnection();
String sql = "SELECT * FROM STUDENTS WHERE STUD_ID=?";
//create PreparedStatement
PreparedStatement pstmt = conn.prepareStatement(sql);
//set input parameters
pstmt.setInt(1, studId);
ResultSet rs = pstmt.executeQuery();
//fetch results from database and populate into Java objects
if(rs.next()) {
student = new Student();
student.setStudId(rs.getInt("stud_id"));
student.setName(rs.getString("name"));
student.setEmail(rs.getString("email"));
student.setDob(rs.getDate("dob"));
}
} catch (SQLException e){
throw new RuntimeException(e);
}finally{
//close connection
if(conn!= null){
try {
conn.close();
} catch (SQLException e){ }
}
}
return student;
}
public void createStudent(Student student)
{
Connection conn = null;
try{
//obtain connection
conn = getDatabaseConnection();
String sql = "INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL,DOB)
VALUES(?,?,?,?)";
//create a PreparedStatement
PreparedStatement pstmt = conn.prepareStatement(sql);
//set input parameters
pstmt.setInt(1, student.getStudId());
pstmt.setString(2, student.getName());
pstmt.setString(3, student.getEmail());
pstmt.setDate(4, new
java.sql.Date(student.getDob().getTime()));
pstmt.executeUpdate();
} catch (SQLException e){
throw new RuntimeException(e);
}finally{
//close connection
if(conn!= null){
try {
conn.close();
} catch (SQLException e){ }
}
}
}
package com.mybatis3.domain;
import java.util.Date;
public class Student
{
private Integer studId;
private String name;
private String email;
private Date dob;
// setters and getters
}
Student 클래스
findStudentById() - 학생 selectcreateStudent() - 학생 insert
protected Connection getDatabaseConnection() throws SQLException
{
try{
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection
("jdbc:mysql://localhost:3306/test", "root", "admin");
} catch (SQLException e){
throw e;
} catch (Exception e){
throw new RuntimeException(e);
}
}
getDatabaseConnection() -DB연결
Student 클래스
7
8. http://blog.naver.com/amelia670
왜 MyBatis인가?
MyBatis가 왜 좋은가? 소스코드를 줄인다.
- JDBC를 이용한 Java와 DB 연결하는 코드
public Student findStudentById(int studId)
{
Student student = null;
Connection conn = null;
try{
//obtain connection
conn = getDatabaseConnection();
String sql = "SELECT * FROM STUDENTS WHERE STUD_ID=?";
//create PreparedStatement
PreparedStatement pstmt = conn.prepareStatement(sql);
//set input parameters
pstmt.setInt(1, studId);
ResultSet rs = pstmt.executeQuery();
//fetch results from database and populate into Java objects
if(rs.next()) {
student = new Student();
student.setStudId(rs.getInt("stud_id"));
student.setName(rs.getString("name"));
student.setEmail(rs.getString("email"));
student.setDob(rs.getDate("dob"));
}
} catch (SQLException e){
throw new RuntimeException(e);
}finally{
//close connection
if(conn!= null){
try {
conn.close();
} catch (SQLException e){ }
}
}
return student;
}
public void createStudent(Student student)
{
Connection conn = null;
try{
//obtain connection
conn = getDatabaseConnection();
String sql = "INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL,DOB)
VALUES(?,?,?,?)";
//create a PreparedStatement
PreparedStatement pstmt = conn.prepareStatement(sql);
//set input parameters
pstmt.setInt(1, student.getStudId());
pstmt.setString(2, student.getName());
pstmt.setString(3, student.getEmail());
pstmt.setDate(4, new
java.sql.Date(student.getDob().getTime()));
pstmt.executeUpdate();
} catch (SQLException e){
throw new RuntimeException(e);
}finally{
//close connection
if(conn!= null){
try {
conn.close();
} catch (SQLException e){ }
}
}
}
package com.mybatis3.domain;
import java.util.Date;
public class Student
{
private Integer studId;
private String name;
private String email;
private Date dob;
// setters and getters
}
Student 클래스
findStudentById() - 학생 selectcreateStudent() - 학생 insert
인풋 파라미터 세팅하고
직접 연결 생성하고
구문 만들고
protected Connection getDatabaseConnection() throws SQLException
{
try{
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection
("jdbc:mysql://localhost:3306/test", "root", "admin");
} catch (SQLException e){
throw e;
} catch (Exception e){
throw new RuntimeException(e);
}
}
getDatabaseConnection() -DB연결
직접 자원 닫고
인풋 파라미터 세팅하고
직접 연결 생성하고
구문 만들고
직접 자원 닫고
Student 클래스
8
9. http://blog.naver.com/amelia670
왜 MyBatis인가?
MyBatis가 왜 좋은가? 소스코드를 줄인다.
- JDBC를 이용한 Java와 DB 연결하는 코드
public Student findStudentById(int studId)
{
Student student = null;
Connection conn = null;
try{
//obtain connection
conn = getDatabaseConnection();
String sql = "SELECT * FROM STUDENTS WHERE STUD_ID=?";
//create PreparedStatement
PreparedStatement pstmt = conn.prepareStatement(sql);
//set input parameters
pstmt.setInt(1, studId);
ResultSet rs = pstmt.executeQuery();
//fetch results from database and populate into Java objects
if(rs.next()) {
student = new Student();
student.setStudId(rs.getInt("stud_id"));
student.setName(rs.getString("name"));
student.setEmail(rs.getString("email"));
student.setDob(rs.getDate("dob"));
}
} catch (SQLException e){
throw new RuntimeException(e);
}finally{
//close connection
if(conn!= null){
try {
conn.close();
} catch (SQLException e){ }
}
}
return student;
}
public void createStudent(Student student)
{
Connection conn = null;
try{
//obtain connection
conn = getDatabaseConnection();
String sql = "INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL,DOB)
VALUES(?,?,?,?)";
//create a PreparedStatement
PreparedStatement pstmt = conn.prepareStatement(sql);
//set input parameters
pstmt.setInt(1, student.getStudId());
pstmt.setString(2, student.getName());
pstmt.setString(3, student.getEmail());
pstmt.setDate(4, new
java.sql.Date(student.getDob().getTime()));
pstmt.executeUpdate();
} catch (SQLException e){
throw new RuntimeException(e);
}finally{
//close connection
if(conn!= null){
try {
conn.close();
} catch (SQLException e){ }
}
}
}
package com.mybatis3.domain;
import java.util.Date;
public class Student
{
private Integer studId;
private String name;
private String email;
private Date dob;
// setters and getters
}
Student 클래스
findStudentById() - 학생 selectcreateStudent() - 학생 insert
protected Connection getDatabaseConnection() throws SQLException
{
try{
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection
("jdbc:mysql://localhost:3306/test", "root", "admin");
} catch (SQLException e){
throw e;
} catch (Exception e){
throw new RuntimeException(e);
}
}
getDatabaseConnection() -DB연결
Student 클래스
SELET * FROM STUDENTS
conn=getDatabaseConnection();
con.close();
PreparedStatement
9
10. http://blog.naver.com/amelia670
왜 MyBatis인가?
MyBatis가 왜 좋은가? 소스코드를 줄인다.
- MyBatis를 이용한 Java와 DB 연결하는 코드
<select id="findStudentById" parameterType="int" resultType=" Student">
SELECT STUD_ID AS studId, NAME, EMAIL, DOB
FROM STUDENTS WHERE STUD_ID=#{Id}
</select>
<insert id="insertStudent" parameterType="Student">
INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL,DOB)
VALUES(#{studId},#{name},#{email},#{dob})
</insert>
public interface StudentMapper
{
Student findStudentById(Integer id);
void insertStudent(Student student);
}
SqlSession session = getSqlSessionFactory().openSession();
StudentMapper mapper = session.getMapper(StudentMapper.class);
// Select Student by Id
Student student = mapper.selectStudentById(1);
//To insert a Student record
mapper.insertStudent(student);
StudentMapper.xml
java 코드인터페이스 StudentMapper
SQL문을 프로그램에서 분리하여 XML 파일에 별도로 작성
JDBC 코드와 수동으로 셋팅하는 파라미터와 결과 매핑을 제거
10
11. http://blog.naver.com/amelia670
왜 MyBatis인가?
MyBatis가 왜 좋은가? 소스코드를 줄인다.
- MyBatis를 이용한 Java와 DB 연결하는 코드
<select id="findStudentById" parameterType="int" resultType=" Student">
SELECT STUD_ID AS studId, NAME, EMAIL, DOB
FROM STUDENTS WHERE STUD_ID=#{Id}
</select>
<insert id="insertStudent" parameterType="Student">
INSERT INTO STUDENTS(STUD_ID,NAME,EMAIL,DOB)
VALUES(#{studId},#{name},#{email},#{dob})
</insert>
public interface StudentMapper
{
Student findStudentById(Integer id);
void insertStudent(Student student);
}
SqlSession session = getSqlSessionFactory().openSession();
StudentMapper mapper = session.getMapper(StudentMapper.class);
// Select Student by Id
Student student = mapper.selectStudentById(1);
//To insert a Student record
mapper.insertStudent(student);
StudentMapper.xml
java 코드인터페이스 StudentMapper
SQL문을 프로그램에서 분리하여 XML 파일에 별도로 작성
JDBC 코드와 수동으로 셋팅하는 파라미터와 결과 매핑을 제거
11
17. http://blog.naver.com/amelia670
예제 프로젝트
Java - MyBatis - MySQL 예제 프로젝트로 CRUD 작업 해보기
목표
- mybatis를 이용하여 java 애플리케이션과 mysql 데이터베이 연결하기
- configuration과 mapper를 XML 파일로 작성해보기
환경
windows 8, eclipse
17
18. http://blog.naver.com/amelia670
예제 프로젝트
1. 다운로드
mybatis 3.4.1
https://github.com/mybatis/mybatis-3
MySQL Java connector 5.1.39
- MySQL과 Java를 연결하기 위한 드라이버
- http://dev.mysql.com/downloads/connector/j/
소스코드
https://github.com/junjw1/mybatis-java-example.git
18