๐Ÿ’ป

์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ - [Spring] MVC ํ”„๋กœ์ ํŠธ(3) : ์šฐํŽธ๋ฒˆํ˜ธ ๊ฒ€์ƒ‰ ๋ณธ๋ฌธ

KITRI/SPRING

์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ - [Spring] MVC ํ”„๋กœ์ ํŠธ(3) : ์šฐํŽธ๋ฒˆํ˜ธ ๊ฒ€์ƒ‰

๋˜ํšจ๋‹ˆ 2020. 7. 29. 14:03

์šฐํŽธ๋ฒˆํ˜ธ ๊ฒ€์ƒ‰ ๊ธฐ๋Šฅ

register.js

function searchZipcode(root){
	var url = root + "/member/zipcode.do";
	//alert(url);
	window.open(url, "", "width=400, height=200, scrollbars=yes");
}

function sendAddress(zipcode, sido, gugun, dong, ri, bunji){
	var address = sido + gugun + dong + ri + bunji;
	//alert(zipcode + address);
	
	//window.close();
	
	
	//opener.joinform.zipcode.value = zipcode;
	//opener.joinform.address.value = address;
	$(opener.document).find("input[name='zipcode']").val(zipcode);
	$(opener.document).find("input[name='address']").val(address);
	
	self.close();
}

 

SpringController-service.xml

zipcode ํ•จ์ˆ˜ ์ถ”๊ฐ€

	<bean id="propertiesMethodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver">
		<property name="mappings">
			<props>
				<prop key="/member/test.do">testing</prop>
				<prop key="/member/register.do">memberRegister</prop>
				<prop key="/member/registerOk.do">memberRegisterOk</prop>
				<prop key="/member/idCheck.do">memberIdCheck</prop>
			    <prop key="/member/zipcode.do">memberZipcode</prop>
			</props>
		</property>
	</bean>

 

MemberController

memberZipcodeํ•จ์ˆ˜ ์ถ”๊ฐ€

public void memberZipcode(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mav = new ModelAndView();

		mav.addObject("request", request);

		memberService.memberZipcode(mav);
	}

 

[interface] memberService 

package com.java.member.service;

import org.springframework.web.servlet.ModelAndView;

public interface MemberService {
	public void memberRegisterOk(ModelAndView mav);
	
	public void memberIdCheck(ModelAndView mav);
	
	public void memberZipcode(ModelAndView mav);
}

 

MemberServiceImp.java

	@Override
	public void memberZipcode(ModelAndView mav) {
		Map<String, Object> map = mav.getModelMap();
		HttpServletRequest request = (HttpServletRequest) map.get("request");
		
		String dong = request.getParameter("dong");
		
		if(dong!=null) {
			
		}
		mav.setViewName("member/zipcode");
	}

 

memberMapper.xml

member_zipcode

<?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="dto.memberDto">

	<resultMap type="com.java.member.dto.MemberDto" id="member_dto">
		<result column="num" property="num"/>
		<result column="id" property="id"/>
		<result column="password" property="password"/>
		<result column="name" property="name"/>
		<result column="jumin1" property="jumin1"/>
		<result column="jumin2" property="jumin2"/>
		<result column="email" property="email"/>
		
		<result column="zipcode" property="zipcode"/>
		<result column="address" property="address"/>
		<result column="job" property="job"/>
		<result column="mailing" property="mailing"/>
		<result column="interest" property="interest"/>
		<result column="member_level" property="memberLevel"/>
		<result column="register_date" property="registerDate"/>
	</resultMap>

<!-- ๋“ค์–ด์˜ค๋Š” ๊ฒƒ์€ parameterType ๋‚˜๊ฐ€๋Š” ๊ฒƒ์€ resultType id๋Š” ์‹๋ณ„์ž, insert๋Š” resultType ์ƒ๋žต -->
	<insert id="member_insert" parameterType="com.java.member.dto.MemberDto">
		insert into member values(
				member_num_seq.nextval,
				#{id},
				#{password},
				#{name},
				#{jumin1},
				#{jumin2},
				#{email},
				#{zipcode},
				#{address},
				#{job},
				#{mailing},
				#{interest},
				#{memberLevel},
				sysdate
		)
	</insert>
	
	<select id="id_check" parameterType="java.lang.String" resultType="java.lang.String">
		select id from member 
				  where id = #{id}
	</select>
	
	<select id="member_zipcode" parameterType="String" resultType="com.java.member.dto.ZipcodeDto">
		select * from zipcode 
				 where dong = #{dong}		
	</select>
	
	<select id="member_login" parameterType="java.util.Map" resultType="String">
		select member_level from member 
							where id = #{id}
							and password = #{password}
	</select>
	
	<select id="member_select" parameterType="String" resultMap="member_dto">
		select * from member 
				 where id = #{id}
	</select>
</mapper>

 

MemberDao.java

zipcode ํ•จ์ˆ˜ 

package com.java.member.dao;

import java.util.HashMap;
import java.util.List;

import org.springframework.web.servlet.ModelAndView;

import com.java.member.dto.MemberDto;
import com.java.member.dto.ZipcodeDto;

public interface MemberDao {
	public int memberInsert(MemberDto memberDto);
	
	public int memberIdCheck(String id);
	
	public List<ZipcodeDto> zipcode(String dong);
}

 

MemberDaoImp.java

package com.java.member.dao;

import java.util.HashMap;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import com.java.member.dto.MemberDto;
import com.java.member.dto.ZipcodeDto;

public class MemberDaoImp implements MemberDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	public MemberDaoImp() {}
	
	public MemberDaoImp(SqlSessionTemplate sqlSessionTemplate) {
		super();
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	
	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	
	@Override
	public int memberInsert(MemberDto memberDto) {
		return sqlSessionTemplate.insert("member_insert", memberDto); //dto.memberDto:member_insert
	}
	
	@Override
	public int memberIdCheck(String id) {
		String value = sqlSessionTemplate.selectOne("id_check", id);
		
		int check = 0;
		if(value!=null) check=1;
		
		return check;
	}
	
	@Override
	public List<ZipcodeDto> zipcode(String dong) {
		return sqlSessionTemplate.selectList("dto.memberDto.member_zipcode", dong);
	}
}
๋ฐ˜์‘ํ˜•
Comments