회원가입 완성하기
by 볼빵빵오춘기mybatis-config.xml
resouces 하위에 생성
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<typeAliases>
<typeAlias type="com.codingrecipe.member.dto.MemberDTO" alias="member"></typeAlias>
</typeAliases>
</configuration>
memberMapper.xml
resouces > mapper 디렉토리 생성 후 memberMapper.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="Member">
<insert id="save" parameterType="member">
insert into member_table(memberEmail, memberPassword, memberName, memberAge, memberMobile)
values (#{memberEmail}, #{memberPassword}, #{memberName}, #{memberAge}, #{memberMobile})
</insert>
</mapper>
root-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!-- 데이터베이스 이름 및 계정 확인 -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/db_springframework?useSSL=false&serverTimezone=Asia/Seoul" />
<property name="username" value="user_jinny"/>
<property name="password" value="1234"/>
</bean>
<!-- 파일 모두 생성했는지 확인 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value ="classpath:/mybatis-config.xml" />
<property name="mapperLocations" value="classpath:/mapper/*.xml" />
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8" />
<property name="maxUploadSize" value="10000000" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
MemberRepository
@Repository
@RequiredArgsConstructor
public class MemberRepository {
private final SqlSessionTemplate sql;
public int save(MemberDTO memberDTO){
System.out.println("memberDTo="+memberDTO);
return sql.insert("Member.save",memberDTO);
}
}
'강의 따라하기 > springframework_setting' 카테고리의 다른 글
회원목록 출력하기 (0) | 2024.10.22 |
---|---|
로그인 구현하기 (0) | 2024.10.22 |
회원가입 시작하기 (0) | 2024.10.22 |
프레임워크 프로젝트 만들기 & Tomcat 세팅 (0) | 2024.10.16 |
스프링프레임워크 - 회원프로젝트 (1) | 2024.10.16 |
블로그의 정보
Hello 춘기's world
볼빵빵오춘기