Spring + mybatis 사용하기
1.pom.xml
2.root-context.xml
-- 비웹관련 설정 : datasource(db) 설정,
<--Connection Pool DataSource config : META-INF - context.xml-->
>value의 정보와 context.xml의 resource의 정보가 같아야한다.
-- <property name="mapperLocations" value="classpath:mapper/*.xml"> : mapper.xml location
>resource/mapper-sub-folder > member.xml , board.xml
>reource> member.xml , board.xml
>classpath: mapper > member.xml
>위 내용을 <property name="typeAliasesPackage" value="com.ssafy.*.model"></property> 가 dtoclass통합 설정
3.META-INF - context.xml
>Connection Pool DataSource 관련 설정 내용 - db변경하려면 이곳에서!!
> url, driver, user, password, jdni name
><Resource name="jdbc/ssafy" username="ssafy" url=""../>
4.resources/Mepper
--member.xml (테이블명,엔티티명으로 하면 좋다)
**자바와 db컬럼명의 규칙이 다름
>namespace 지정 : unique(package 명 + class-name)
type="memberDto" : typeAliasesPackage설정 가능
--board.xml
5.resources - mybatis-config.xml
필요에 따라서 사용or 비사용
6.Dao interface
--MemberMapper, BoardMapper
--interface 만 설계하면 됨 (구현 클래스 구현할 필요 없음)
--root-context.xml
--@Mapper 어노테이션 생략 가능 - root-context.xml에 설정되어있어 자동 인식
--가독성을 위해 @Mapper사용
--interface 매서드 형식(이름, 아규먼트, 반환타입)
>>매서드 이름 : id = "idCheck"
>>아규먼트 : parameterType="String" (단일타입 : string, int, map, dto)
>> 반환타입 : resultType="int"
7.Service
-- MemberService/MemberServiceImpl
-- BoardService/BoardServiceImpl
'Spring' 카테고리의 다른 글
[Spring]Mybatis- SqlSessionFactory (0) | 2022.10.25 |
---|---|
[Spring]Spring JDBC, DataSource (0) | 2022.10.25 |
[Spring]MVC (0) | 2022.10.21 |
[Spring]spring project (0) | 2022.10.21 |
[Spring] spring Framework (0) | 2022.10.19 |