더보기
이 글의 예제들은 팀을 등록, 조회, 수정, 삭제하는 동작을 바탕으로 진행한다.
Create 생성 = 등록 = insert
Read 읽기 = 조회 = select
Update 갱신 = 수정 = update
Delete 삭제 = 삭제 = delete
mybatis에서 xml 작성하는 기본 문법
<[insert/select/selectOne/update/delete] id="" [parameterType/parameterMap/resultType/resultMap]="">
parameterType : 입력되는 데이터의 유형
resultType : 반환되는 데이터의 유형
등록하기
팀 등록하려면 팀에 관한 데이터를 입력할 것이다.
no, leaderemail, title, local, description을 저장한 teamDto를 입력유형으로 설정한다.
#mapper location settings
mybatis.type-aliases-package=com.mit.dto
mybatis.mapper-locations=classpath:mappers/**/*.xml
mapper를 사용하면 parameterType에 com.mit.dto 패키지 안에 있는 java파일명을 작성해주면 된다.
<insert id="select" parameterType="team">
insert into
team(no, leaderemail, title, local, description)
values(#{no}, #{leaderemail}, #{title}, #{local}, #{description})
</insert>
조회하기
팀 목록을 조회할 때 전체를 조회할 수 있고(list) 원하는 조건에 맞는 결과들(list)만 조회할 수도 있다. 하나의 결과(team)만 검색할 때는 selectOne을 사용한다.
반응형
'프로젝트 하면서 > spring' 카테고리의 다른 글
[error] Multiple markers at this line & lombok install/update (0) | 2020.09.04 |
---|---|
용량이 큰 파일 저장하기 (0) | 2020.08.20 |
[git remote 후] spring sts로 프로젝트 가져오기 (0) | 2020.08.05 |
[spring 단축키] (0) | 2020.08.04 |
spring에서 git으로 받은 파일 열기 (0) | 2020.07.21 |
댓글