๐ป
์คํ๋ง ํ๋ ์์ํฌ - [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);
}
}
๋ฐ์ํ
'KITRI > SPRING' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Comments