728x90
반응형
SMALL
https://developer-joe.tistory.com/235
Java DAO와 MyBatis Mapper xml의 쿼리문과의 매핑 원리
아래와 같은 Mapper xml의 쿼리 문이 있다고 할 경우, insert into tbl_member (userid, userpw, username, email) values (#{userid}, #{userpw}, #{username}, #{email}) VO 객체는 다음과 같고, pub..
developer-joe.tistory.com
즉, dao에서 회원가입 메서드를 구현할 경우
<!-- 회원가입 mapper-->
<insert id="signup">
insert into shop_member(userId, userPass, userName, userPhon)
VALUES (#{userId}, #{userPass} , #{userName}, #{userPhon});
</insert>
//회원가입 dao
@Override
public void signup(MemberVO vo) throws Exception {
sql.insert(namespace + ".signup", vo);
}
-->sqlSession클래스의 insert문의 원리는 다음과 같다.
int insert(String statement, Object parameter)
--> 이때 첫번째 매개인자인 statement는 Mapper.xml의 쿼리문에 해당한다
위의 회원가입 메서드를 예로 들어보자면 statement부분에 namespace + ".signup" 이 들어가있는데,
이는 mapper xml에서 회원가입 쿼리에서 설정한 id값을 쓴 것이다.
즉, id가 signup이라는 쿼리문을 실행한다는 의미
--> 두번째 매개인자인 parameter는 첫번째 매개인자인 statement에서 쿼리문을 실행할 경우 이 쿼리문에서 사용할 변수들에게 #{ } 넘겨줄 값을 담고 있는 것이다.
즉, MemberVO의 객체인 vo를 넣는 것이다.
728x90
반응형
LIST
'Spring > spring 공부' 카테고리의 다른 글
[Spring공부] servlet-context.xml/ root-context.xml/ web.xml 차이 정리하기 (0) | 2022.04.07 |
---|---|
[Springboot] 3. 스프링부트 동작원리 (0) | 2022.03.07 |
[Springboot] 2. JPA 개념 잡기 (0) | 2022.03.07 |
[Springboot] 1. 스프링의 핵심 (0) | 2022.03.07 |
[Spring수업복습] 2022-02-09(수) - 5~7교시 (0) | 2022.02.09 |