본문 바로가기
Spring

Spring으로 Mybatis 이용하기

by 바른롱매 2020. 5. 26.

어제 마이바티스를 다이나믹웹프로젝트로 사용을 해봤는데 오늘은 스프링에 얹어 보겠습니다.

위의 프로젝트 골격에 따라 중요한코드만 올렸는데 스프링의 모델2의 형식에 따라 프로그램이 실행되는것입니다.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Sample02</groupId>
  <artifactId>Sample02</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
        </configuration>
      </plugin>
    </plugins>
  </build>
  
  <dependencies>
  
  	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-webmvc</artifactId>
	    <version>5.1.5.RELEASE</version>
	  </dependency>
	  
	  <dependency>
	    <groupId>log4j</groupId>
	    <artifactId>log4j</artifactId>
	    <version>1.2.17</version>
	  </dependency>
	  
	  <dependency>
	    <groupId>org.slf4j</groupId>
	    <artifactId>slf4j-simple</artifactId>
	    <version>1.7.25</version>
      </dependency>
      
      
      <!-- 런타임에 동적으로 자바 클래스의 프록시(대리(인))를 생성해주는 기능을 제공한다 -->
      <dependency>
	    <groupId>cglib</groupId>		
	    <artifactId>cglib</artifactId>
	    <version>3.2.4</version>
	</dependency>
	<dependency>
	    <groupId>commons-digester</groupId>
	    <artifactId>commons-digester</artifactId>
	    <version>2.1</version>
	</dependency>
	
	<dependency>
  		<groupId>commons-logging</groupId>
  		<artifactId>commons-logging</artifactId>
  		<version>1.2</version>
  	</dependency>
  	
	<!-- Ajax 사용 설정[jackson] -->
  	<dependency>
  		<groupId>org.codehaus.jackson</groupId>	
  		<artifactId>jackson-core-asl</artifactId>
  		<version>1.9.13</version>
  	</dependency>
  	<dependency>
  		<groupId>org.codehaus.jackson</groupId>
  		<artifactId>jackson-mapper-asl</artifactId>
  		<version>1.9.13</version>
  	</dependency>

	<!-- 의존성을 추가 --> 
  	<dependency>
  		<groupId>javax.inject</groupId>
  		<artifactId>javax.inject</artifactId>
  		<version>1</version>
  	</dependency>

	<!-- JCL(자카르타 커먼스 로깅)을 사용 --> 	
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>jcl-over-slf4j</artifactId>
  		<version>1.7.21</version>
  	</dependency>

	<!-- XML 파싱 -->
  	<dependency>
  		<groupId>jdom</groupId>
  		<artifactId>jdom</artifactId>
  		<version>1.1</version>
  	</dependency>

	<!-- JSTL -->
  	<dependency>
  		<groupId>jstl</groupId>
  		<artifactId>jstl</artifactId>
  		<version>1.2</version>
  	</dependency>
  	
	<!-- 마이 바티스 스프링 사용시 -->
  	<dependency>
  		<groupId>org.mybatis</groupId>
  		<artifactId>mybatis-spring</artifactId>
  		<version>1.3.1</version>
  	</dependency>  	
  	<dependency>
  		<groupId>org.mybatis</groupId>
  		<artifactId>mybatis</artifactId>
  		<version>3.4.0</version>
  	</dependency>
	<!-- 마이 SQL 사용시 -->	
  	<dependency>
  		<groupId>mysql</groupId>
  		<artifactId>mysql-connector-java</artifactId>
  		<version>6.0.2</version>
  	</dependency>

	<!-- XML 파싱 -->
  	<dependency>
  		<groupId>org.jdom</groupId>
  		<artifactId>jdom</artifactId>
  		<version>2.0.2</version>
  	</dependency>

	<!-- SLF4J API를 사용하도록 -->
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-api</artifactId>
  		<version>1.7.21</version>
  	</dependency>
  	
	<!-- log4j -->
  	<dependency>
  		<groupId>ant</groupId>
  		<artifactId>ant-apache-log4j</artifactId>
  		<version>1.6.5</version>
  	</dependency>

	<!-- Map을 Bean객체로 바꾸어주는 클래스 -->
  	<dependency>
  		<groupId>commons-beanutils</groupId>
  		<artifactId>commons-beanutils-core</artifactId>
  		<version>1.8.3</version>
  	</dependency>

	<!-- DBCP : DB Connection Poll 사용 --> 
  	<dependency>
  		<groupId>com.kenai.nbpwr</groupId>
  		<artifactId>org-apache-commons-dbcp</artifactId>
  		<version>1.2.2-201002241055</version>
  		<type>nbm</type>
  	</dependency>

	<!-- IO 기능 개발을 지원하는 유틸리티 라이브러리 -->
  	<dependency>
  		<groupId>org.apache.commons</groupId>
  		<artifactId>commons-io</artifactId>
  		<version>1.3.2</version>
  	</dependency>
  	<dependency>
  		<groupId>org.apache.commons</groupId>
  		<artifactId>commons-lang3</artifactId>
  		<version>3.4</version>
  	</dependency>
  	<dependency>
  		<groupId>org.apache.commons</groupId>
  		<artifactId>commons-pool2</artifactId>
  		<version>2.4.2</version>
  	</dependency>
  	<dependency>
  		<groupId>org.slf4j</groupId>
  		<artifactId>slf4j-log4j12</artifactId>
  		<version>1.7.21</version>
  	</dependency>
    
    <!-- spring -->
	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-aop</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-beans</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-context-support</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-core</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-expression</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-jdbc</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-orm</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-test</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-tx</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	<dependency>
  		<groupId>org.springframework</groupId>
  		<artifactId>spring-web</artifactId>
  		<version>5.1.5.RELEASE</version>
  	</dependency>
  	
	<!-- 자바용 json 라이브러리(XML/YAML/CSV) data-processing 툴 --> 
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-core</artifactId>
	    <version>2.9.8</version>
	</dependency>
	<dependency>
	    <groupId>com.fasterxml.jackson.core</groupId>
	    <artifactId>jackson-databind</artifactId>
	    <version>2.9.8</version>
	</dependency>
	
	<!-- ojdbc6 -->
	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc6</artifactId>
		<version>12.1.0.1</version>
	</dependency>	
  
  </dependencies>
  
  <repositories>
  	<repository>
		<id>codelds</id>		<!-- ojdbc6 와 함께 추가 -->
		<url>https://code.lds.org/nexus/content/groups/main-repo</url>
	</repository>
  </repositories>    
  
  
  
</project>

 

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
  <display-name>Sample01</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
   <!-- 스프링에서 쓸 xml 을 맵핑시켜준다. -->
  <servlet>
  	<servlet-name>dispatcherServlet</servlet-name>
  	<servlet-class>
  		org.springframework.web.servlet.DispatcherServlet
  	</servlet-class>
  	
  	<init-param>
  		<param-name>contextConfigLocation</param-name>
  		<param-value>
  			/WEB-INF/spring/servlet-context.xml
  			/WEB-INF/spring/aop-context.xml
  		</param-value>
  	</init-param>
  	
  	<load-on-startup>1</load-on-startup>
  
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>dispatcherServlet</servlet-name>
  	<!-- <url-pattern>/</url-pattern> -->
  	<url-pattern>*.do</url-pattern>
  </servlet-mapping>
  
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
  </context-param>
  
  <!-- Listener -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <!-- 한글설정  -->
  <filter>
  	<filter-name>encodingFilter</filter-name>
  	<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  	
  	<init-param>
  		<param-name>encoding</param-name>
  		<param-value>UTF-8</param-value>
  	</init-param>
  	
  	<init-param>
  		<param-name>forceEncoding</param-name>
  		<param-value>true</param-value>
  	</init-param>
  </filter>
  
  <filter-mapping>
  	<filter-name>encodingFilter</filter-name>
  	<url-pattern>/*</url-pattern>
  </filter-mapping>
    
</web-app>

 

servlet-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:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
		
	<!-- spring MVC annotation(주석문)을 활성화 하기 위한 설정 -->	
	<context:annotation-config/>
	
	<!-- viewResolver 설정(사용자 view의 위치, 확장자명 설정) -->
	<!-- InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); -->
	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"/> <!-- 경로 -->
		<property name="suffix" value=".jsp"/><!-- 확장자명 -->
	</bean>
	
	<!-- 자바 공통 패키지 등록 -->
	<context:component-scan base-package="bit.com.a"/>


</beans>

 

applicationContext.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:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">


	<!-- DataBase 설정 -->
	
	<!-- db 설정 파일 위치 -->
	<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:properties/jdbc.properties</value>
			</list>
		</property>
	</bean>
	
	<!-- DBMS jdbc.properties에 있는 설정들을 가져온다. -->
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driverClassName}"/>
		<property name="url" value="${jdbc.url}"/>
		<property name="username" value="${jdbc.username}"/>
		<property name="password" value="${jdbc.password}"/>
		<property name="initialSize" value="${jdbc.initialSize}"/>
		<property name="maxActive" value="${jdbc.maxActive}"/>
		<property name="minIdle" value="${jdbc.initialSize}"/>
		<property name="maxWait" value="3000"/>
		<property name="poolPreparedStatements" value="true"/>
		<property name="maxOpenPreparedStatements" value="50"/>
	</bean>
	
	<!-- mybatis setting -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<property name="dataSource" ref="dataSource"/>
		<!-- src 폴더에 sqls 폴더안에 있는 모든 xml에 파일들을 맵퍼로 취급해라 라는 표현 -->
		<property name="mapperLocations" value="classpath:sqls/*.xml"/>
	</bean>
	
	<!-- sqlSession 취득 -->
	<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
		<constructor-arg index="0" ref="sqlSessionFactory"/>
		<constructor-arg index="1" value="SIMPLE"/> <!-- SIMPLE/BATCH 2가지 모드가 있다.-->
	</bean>
	
	<!-- jdbc 연결 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"/>
	</bean>
	

</beans>

 

aop-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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="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-4.3.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">


	<!-- service로 끝나는 모든 bean을 기본 트랜잭션 설정을 활성화 -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
	
	<!-- AOP 어스택트 오브젝트 프로그래밍(관점지향프로그래밍)-->
	
</beans>

 

log4j.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

	<!-- Appenders -->
	<appender name="console" class="org.apache.log4j.ConsoleAppender">
		<param name="Target" value="System.out" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%-5p: %c - %m%n" />
		</layout>
	</appender>
	
	<!-- Application Loggers -->
	<logger name="bit.com.a">
		<level value="info" />
	</logger>
	
	<!-- 3rdparty Loggers -->
	<logger name="org.springframework.core">
		<level value="info" />
	</logger>
	
	<logger name="org.springframework.beans">
		<level value="info" />
	</logger>
	
	<logger name="org.springframework.context">
		<level value="info" />
	</logger>

	<logger name="org.springframework.web">
		<level value="info" />
	</logger>

	<!-- Root Logger -->
	<root>
		<priority value="warn" />
		<appender-ref ref="console" />
	</root>
	
</log4j:configuration>

 

jdbc.properties

# Local DB
jdbc.driverClassName = oracle.jdbc.driver.OracleDriver
jdbc.url = jdbc:oracle:thin:@localhost:1521:xe
jdbc.username = hr
jdbc.password = hr
jdbc.initialSize = 5
jdbc.maxActive = 20

 

 

BitMember.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">

<!-- Query -->
<insert id="addmember" parameterType="bit.com.a.model.MemberDto">
	INSERT INTO MEMBER(ID, PWD, NAME, EMAIL, AUTH)
	VALUES(#{id}, #{pwd}, #{name}, #{email}, 3)
</insert>

</mapper>

 

BitMemberController.java

package bit.com.a.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import bit.com.a.model.MemberDto;
import bit.com.a.service.BitMemberService;


@Controller
public class BitMemberController {
	
	private static final Logger logger = LoggerFactory.getLogger(BitMemberController.class);

	
	@Autowired
	private BitMemberService bitMemberService;
	
	@RequestMapping(value="login.do", method=RequestMethod.GET)
	public String login(Model model) {
		//모델을 잡는건 짐을 싸기 위해 해놓는거다 파라메타로 하는게 짐싸는 준비!!
		
		logger.info("BitMemberController login " + new Date());
		
		return "login";
	}
	
	@RequestMapping(value="account.do", method=RequestMethod.GET)
	public String account(Model model) {
		//모델을 잡는건 짐을 싸기 위해 해놓는거다 파라메타로 하는게 짐싸는 준비!!
		
		logger.info("BitMemberController account " + new Date());
		
		return "account";
	}
	
	@RequestMapping(value="accountAf.do", method=RequestMethod.POST)
	public String accountAf(MemberDto dto, Model model, HttpServletRequest req) throws Exception{
		// req는 세션에 접근하는 용도다
		logger.info(dto.toString());
		
		boolean b = bitMemberService.addmember(dto);
		if(b) {
			logger.info("회원가입되었습니다 " + new Date());
			return "login";
		}
		
		return "account";
	}
}

 

BitMemberDao.java

package bit.com.a.dao;

import bit.com.a.model.MemberDto;

public interface BitMemberDao {
	
	public boolean addmember(MemberDto dto) throws Exception ;

}

 

BitMemberDaoImpl.java

package bit.com.a.dao.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import bit.com.a.dao.BitMemberDao;
import bit.com.a.model.MemberDto;

@Repository
public class BitMemberDaoImpl implements BitMemberDao {
	
	@Autowired
	SqlSession sqlSession; 
	
	String namespace = "Member.";

	@Override
	public boolean addmember(MemberDto dto) throws Exception{
		
		int n = sqlSession.insert(namespace+"addmember", dto);

		return n>0?true:false;
		
	}

}

BitMemberService.java

package bit.com.a.dao.impl;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import bit.com.a.dao.BitMemberDao;
import bit.com.a.model.MemberDto;

@Repository
public class BitMemberDaoImpl implements BitMemberDao {
	
	@Autowired
	SqlSession sqlSession; 
	
	String namespace = "Member.";

	@Override
	public boolean addmember(MemberDto dto) throws Exception{
		
		int n = sqlSession.insert(namespace+"addmember", dto);

		return n>0?true:false;
		
	}

}

 

BitMemberServiceImpl.java

package bit.com.a.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import bit.com.a.dao.BitMemberDao;
import bit.com.a.service.BitMemberService;

@Service
public class BitMemberServiceImpl implements BitMemberService {
	
	/* 자동으로 스프링프레임워크가 자동으로 생성해준다. 상속받은게 누군지 자동으로 넣어준다. DI(디펜더신 인젝션)의존성...개념.. 라고 한다.*/
	@Autowired
	private BitMemberDao bitMemberDao;
	//private BitMemberDao bitMemberDao = new BitMemberDaoImpl(); 동일한 코드지만 스프링에서는 이렇게 사용하지 않는다 잘 동작하지 않음.

    @Override
	public boolean addmember(MemberDto dto) throws Exception {
		
		return bitMemberDao.addmember(dto);
	}

}

 

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<div id="divid">
<br><br>
<form action="" id="frm">
	<input type="hidden" name="command" value="login">
	<table>
	<tr>
		<td colspan="2">
			<input type="text" placeholder="id 입력" id="id" name="id">
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<span style="opacity: 0">공간 맞추기</span>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="password" placeholder="비밀번호 입력" id="pwd" name="pwd">
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="checkbox" name="idcheck" id="chk_save_id"><span style="font-weight: bold;">Remember ME</span>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="button" value="로그인" class="btn btn-default" id="loginbtn">
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<span style="opacity: 0">공간 맞추기</span>
		</td>
	</tr>
	<tr>
		<td>
			<a href="#" class="login_a"><input type="button" value="비밀번호 찾기" class="btn btn-dark" id="pwdfindbtn"></a>
		</td>
		<td>
			 <a href="account.do" class="login_a"><button type="button" id="accountbtn">회원가입</button></a>
		</td>
	</tr>
	</table>
</form>
</div>

</body>
</html>

 

account.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div id="divid">
	<form action="accountAf.do" id="frm" method="post">
		<input type="hidden" name="command" value="custaccount">
		<table>
			<tr>
				<td colspan="2">
					<h1 class="allfont">회원가입</h1>
				</td>
			</tr>
			<tr>
				<td><input type="text" placeholder="id 입력" id="id" name="id">
					<button type="button" class="btn btn-default" id="idcheckbtn">id체크</button>
					<input type="hidden" id="idsave" value=""></td>
			</tr>
			<tr>
				<td><font color="red" id="idfont">7 ~ 20글자의 영문+숫자로
						등록해주십시오</font></td>
			</tr>
			<tr>
				<td><input type="password" placeholder="비밀번호 입력" id="pwd"
					name="pwd"></td>
			</tr>
			<tr>
				<td><font color="red" id="pwdfont">8~15자리의 특수,영문+숫자로
						등록해주십시오( ~!@\#$%&lt;&gt;^&amp;* 만 지원합니다. )</font></td>
			</tr>
			<tr>
				<td><input type="text" placeholder="이름 입력" id="name"
					name="name"></td>
			</tr>
			<tr>
				<td><span style="opacity: 0">공간지정</span></td>
			</tr>
			<tr>
				<td><input type="text" placeholder="주소입력" id="address"
					name="address" maxlength="20">
					<button type="button" id="addressbtn">우편번호찾기</button></td>
			</tr>
			<tr>
				<td><span style="opacity: 0">공간지정</span></td>
			</tr>
			<tr>
				<td><input type="text" placeholder="생년월일(예 : 19920305)"
					id="birthday" name="birthday" maxlength="8"></td>
			</tr>
			<tr>
				<td><span style="opacity: 0">공간지정</span></td>
			</tr>
			<tr>
				<td><input type="text" placeholder="전화번호(예 : 01012345678)"
					id="phone" name="phone" maxlength="11"></td>
			</tr>
			<tr>
				<td><span style="opacity: 0">공간지정</span></td>
			</tr>
			<tr>
				<td><input type="text" placeholder="이메일(예 : abc@naver.com)"
					id="email" name="email"></td>
			</tr>
			<tr>
				<td><span style="opacity: 0">공간지정</span></td>
			</tr>
			<tr>
				<td><input type="submit" value="회원가입하기"
					class="btn btn-default" id="accountbtn"></td>
			</tr>
		</table>
	</form>
</div>

</body>
</html>

 

로그인폼부터 회원가입버튼을 눌러서 정보를 입력한다음에 DB에 저장까지 잘 돼서 다시 로그인폼으로 나오는걸 확인 할 수 있다.

 

'Spring' 카테고리의 다른 글

MyBatis 프레임워크 이용하기  (0) 2020.05.18
Spring 설치 로그출력  (0) 2020.04.27

댓글