implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
mybatis:
# #resources/mapper/ 에 있는 모든 xml 파일을 내가 매퍼로 쓸거다.
mapper-locations: mapper/*.xml
#alias설정
# type-aliases-package: com.phl.cocolo.dto
package com.phl.cocolo.repository;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Update;
import java.util.Map;
@Mapper
public interface MemberMapperRepository {
//회원 포인트 충전
@Update("update member_table set member_point = member_point + #{member_point} where member_id = #{member_id}")
void pointCharge(Map<String, Object> memberPointUpdate);
//회원목록 출력
List<MemberDetailDTO> memberList();
//회원가입
void save(MemberSaveDTO memberSaveDTO);
//mapper를 호출하지 않고 여기서 쿼리까지 수행하는 방식
@Select("select * from member_table")
List<MemberDetailDTO> memberList2();
@Insert("insert into member_table(member_email,member_password,member_name) values (#{member_email},#{member_password},#{member_name})")
void save2(MemberSaveDTO memberSaveDTO);
}
<?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="com.phl.cocolo.repository.MemberMapperRepository">
<update id="pointCharge" parameterType="java.util.HashMap">
update member_table set member_point = member_point + #{member_point}
where member_id = #{member_id}
</update>
<select id="memberList" resultType="com.phl.cocolo.dto.MemberDetailDTO">
select * from member_table
</select>
<insert id="save" parameterType="com.phl.cocolo.dto.MemberSaveDTO">
insert into member_table(member_email,member_password,member_name)
values (#{member_email},#{member_password},#{member_name})
</insert>
</mapper>
@Override
public void pointCharge(PointSaveDTO pointSaveDTO) {
//포인트 이력 정보 저장
MemberEntity memberEntity = mr.findById(pointSaveDTO.getMemberId()).get();
PointEntity pointEntity = PointEntity.toPointSaveEntity(pointSaveDTO,memberEntity);
pr.save(pointEntity);
//회원 포인트 업데이트
Map<String, Object> memberPointUpdate = new HashMap<>();
memberPointUpdate.put("member_id", pointSaveDTO.getMemberId());
memberPointUpdate.put("member_point", pointSaveDTO.getPointPoint());
mmr.pointCharge(memberPointUpdate);
}
눈으로만 봤을 때는 이해가 잘 가지 않았는데 직접 해보니 어렵지 않았다.(오류가 났을 때 침착히 읽어보면 해결됐다.)