728x90
controller
@Controller
public class MemberController {
@Autowired private MemberService memberService;
@PostMapping("/addMember")
public String addMember(Member member) {
System.out.println(member.toString());
memberService.addMember(member);
return "index";
}
}
service
package ksmart35.springboot_mybatis.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ksmart35.springboot_mybatis.domain.Member;
import ksmart35.springboot_mybatis.mapper.MemberMapper;
@Service
@Transactional
public class MemberService {
@Autowired private MemberMapper memberMapper;
public int addMember(Member member) {
return memberMapper.addMember(member);
}
}
mapper
interface
package ksmart35.springboot_mybatis.mapper;
import org.apache.ibatis.annotations.Mapper;
import ksmart35.springboot_mybatis.domain.Member;
@Mapper
public interface MemberMapper {
//회원가입에 관련된 메서드
public int addMember(Member member);
}
xml
<?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="ksmart35.springboot_mybatis.mapper.MemberMapper">
<insert id="addMember" parameterType="Member">
INSERT INTO tb_member
(m_id, m_pw, m_level, m_name, m_email)
VALUES (#{memberId}, #{memberPw}, #{memberLevel}, #{memberName}, #{memberEmail})
</insert>
</mapper>
jdbc
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/dev35db?serverTimezone=UTC&charactersEncoding=utf8
spring.datasource.username=root
spring.datasource.password=java0000
mybatis.mapper-locations=classpath:/mapper/**/*.xml
mybatis.type-aliases-package=ksmart35.springboot_mybatis.domain
반응형
'Backend > SpringBoot' 카테고리의 다른 글
Get방식 parameter 넘기기 (0) | 2020.05.26 |
---|---|
Baeldung (0) | 2020.05.26 |
thymeleaf utility objects (0) | 2020.05.19 |
Spring Boot - tool.jar 에러 (0) | 2020.05.19 |
Spring Boot - Thymeleaf 자동완성기능 API 다운로드 (0) | 2020.05.18 |
댓글