SHARE
TWEET

Untitled

a guest Oct 14th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ★ 1. MemberController.java
  2.  
  3. package com.shoppingmall.member.controller;
  4.  
  5. import java.util.List;
  6.  
  7. import javax.servlet.http.HttpServletResponse;
  8. import javax.servlet.http.HttpSession;
  9.  
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.beans.factory.annotation.Qualifier;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.ExceptionHandler;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.servlet.ModelAndView;
  16.  
  17. import com.shoppingmall.member.model.Member;
  18. import com.shoppingmall.member.service.MemberService;
  19.  
  20. import common.exception.DidNotCheckLoginException;
  21.  
  22. @Controller
  23. @RequestMapping("/shopJSP")
  24. public class MemberController {
  25.     String tag = this.getClass().getName();
  26.     @Autowired
  27.     @Qualifier("memberServiceImpl")
  28.     private MemberService memberService;
  29.  
  30.     @RequestMapping("/registForm.do")
  31.     public String regist(Member member) {
  32.         System.out.println(tag + "해해해" + member.getName());
  33.         memberService.insert(member);
  34.  
  35.         return "shopJSP/loginForm";
  36.     }
  37.  
  38.     @RequestMapping("/checkId.do")
  39.     public ModelAndView checkId(Member member, HttpServletResponse httpServletResponse) {
  40.         System.out.println("어이디는" + member.getId());
  41.         List list = memberService.selectId(member);
  42.         ModelAndView mav = new ModelAndView("shopJSP/checkLoginResult");
  43.         mav.addObject("msg", "사용가능한 아이디입니다");
  44.         mav.addObject("result", "true");
  45.  
  46.         return mav;
  47.     }
  48.  
  49.     // 로그인 아이디 비밀번호 체크
  50.     @RequestMapping("/loginCheck.do")
  51.     public ModelAndView checkLogin(HttpSession session, Member member) {
  52.         System.out.println(member.getId());
  53.         memberService.checkLogin(member);
  54.         ModelAndView mav = new ModelAndView("shopJSP/checkLoginResult");
  55.         session.setAttribute("id", member.getId());
  56.         mav.addObject("msg", "로그인 성공");
  57.         mav.addObject("result", "true");
  58.  
  59.         return mav;
  60.     }
  61.  
  62.     // 로그인 아이디 비밀번호가 틀렸을때
  63.     @ExceptionHandler(DidNotCheckLoginException.class)
  64.     public ModelAndView handle(DidNotCheckLoginException e) {
  65.         ModelAndView mav = new ModelAndView("shopJSP/checkLoginResult");
  66.         mav.addObject("msg", e.getMessage());
  67.         mav.addObject("result", "false");
  68.  
  69.         return mav;
  70.     }
  71.  
  72.     // 로그아웃됬을떄
  73.     @RequestMapping("/loginOut.do")
  74.     public String loginOut(HttpSession session) {
  75.         session.setAttribute("id", null);
  76.         return "shopJSP/index";
  77.     }
  78.  
  79.     // 마이페이지 정보 가져오기
  80.     @RequestMapping("/myPage.do")
  81.     public ModelAndView selectOne(HttpSession session) {
  82.         String id = (String) session.getAttribute("id");
  83.  
  84.         ModelAndView mav = new ModelAndView("shopJSP/myPage");
  85.         Member member = memberService.selectOne(id);
  86.  
  87.         mav.addObject("member", member);
  88.  
  89.         return mav;
  90.     }
  91. }
  92.  
  93. ★ 2. MemberService.java
  94.  
  95. package com.shoppingmall.member.service;
  96.  
  97. import java.util.List;
  98.  
  99. import com.shoppingmall.member.model.Member;
  100.  
  101. public interface MemberService {
  102.     public void insert(Member member);
  103.     public List selectId(Member member);
  104.     public int checkLogin(Member member);
  105.     public Member selectOne(String id);
  106. }
  107.  
  108.  
  109.  
  110. ★ 3. MemberServiceImpl.java
  111.  
  112. package com.shoppingmall.member.service;
  113.  
  114. import java.util.List;
  115.  
  116. import org.springframework.beans.factory.annotation.Autowired;
  117. import org.springframework.beans.factory.annotation.Qualifier;
  118. import org.springframework.stereotype.Service;
  119.  
  120. import com.shoppingmall.member.model.Member;
  121. import com.shoppingmall.member.model.MemberDAO;
  122.  
  123. import common.exception.DidNotCheckLoginException;
  124.  
  125. @Service
  126. public class MemberServiceImpl implements MemberService {
  127.     String tag = this.getClass().getName();
  128.  
  129.     @Autowired
  130.     @Qualifier("mybatisMemberDAO")
  131.     private MemberDAO memberDAO;
  132.  
  133.     @Override
  134.     public void insert(Member member) {
  135.         // TODO Auto-generated method stub
  136.         System.out.println(tag + "dd");
  137.         memberDAO.insert(member);
  138.     }
  139.  
  140.     @Override
  141.     public List selectId(Member member) throws DidNotCheckLoginException{
  142.         // TODO Auto-generated method stub
  143.         List list = memberDAO.selectId(member);
  144.  
  145.         return list;
  146.     }
  147.  
  148.     @Override
  149.     public int checkLogin(Member member) throws DidNotCheckLoginException {
  150.         int result = memberDAO.checkLogin(member);
  151.         return result;
  152.     }
  153.    
  154.     //내정보가져오기
  155.     @Override
  156.     public Member selectOne(String id) {
  157.         Member member=memberDAO.selectOne(id);
  158.         return member;
  159.     }
  160.  
  161. }
  162.  
  163.  
  164. ★ 4. MemberDAO.java
  165.  
  166. package com.shoppingmall.member.model;
  167.  
  168. import java.util.List;
  169.  
  170. public interface MemberDAO {
  171.     public void insert(Member member);
  172.  
  173.     public List selectId(Member member);
  174.  
  175.     public int checkLogin(Member member);
  176.  
  177.     public Member selectOne(String id);
  178.    
  179.     public List selectAll();
  180.  
  181. }
  182.  
  183.  
  184. ★ 5. MybatisMemberDAO.java
  185.  
  186.   package com.shoppingmall.member.model;
  187.  
  188. import java.util.List;
  189.  
  190. import org.mybatis.spring.SqlSessionTemplate;
  191. import org.springframework.beans.factory.annotation.Autowired;
  192. import org.springframework.stereotype.Repository;
  193.  
  194. import common.exception.DidNotCheckLoginException;
  195.  
  196. @Repository
  197. public class MybatisMemberDAO implements MemberDAO {
  198.     String tag = this.getClass().getName();
  199.  
  200.     @Autowired
  201.     SqlSessionTemplate sqlSessionTemplate;
  202.  
  203.     @Override
  204.     public void insert(Member member) {
  205.         // TODO Auto-generated method stub
  206.  
  207.         int result = sqlSessionTemplate.insert("Member.insert", member);
  208.         System.out.println(tag + "마이바티스" + result);
  209.  
  210.     }
  211.  
  212.     @Override
  213.     public List selectId(Member member) {
  214.  
  215.         List list = sqlSessionTemplate.selectList("Member.selectId", member);
  216.  
  217.         if (list.size() != 0) {
  218.             throw new DidNotCheckLoginException("이미 아이디가 있습니다!");
  219.         }
  220.         return list;
  221.     }
  222.  
  223.     @Override
  224.     public int checkLogin(Member member) throws DidNotCheckLoginException {
  225.  
  226.         List list = sqlSessionTemplate.selectList("Member.checkLogin", member);
  227.         System.out.println(tag + list.size());
  228.         if (list.size() == 0) {
  229.             throw new DidNotCheckLoginException("로그인 아이디 비밀번호를 확인하세요");
  230.         }else{
  231.             Member getMember=(Member)list.get(0);
  232.             member.setId(getMember.getId());
  233.         }
  234.  
  235.         return 0;
  236.     }
  237.  
  238.     //내정보가져오기
  239.     @Override
  240.     public Member selectOne(String id) {
  241.         System.out.println("id="+id);
  242.         /*Member member=(Member)sqlSessionTemplate.selectMap("Member.selectOne", member1);*/
  243.         Member member=sqlSessionTemplate.selectOne("Member.selectOne", id);
  244.         return member;
  245.     }
  246.  
  247.     @Override
  248.     public List selectAll() {
  249.        
  250.         List list = sqlSessionTemplate.selectList("Member.selectAll");
  251.        
  252.         return list;
  253.     }
  254.  
  255. }
  256.  
  257.  
  258. ★ 6. Member.java
  259.  
  260. package com.shoppingmall.member.model;
  261.  
  262. public class Member {
  263.     private int member_id;
  264.     private String id;
  265.     private String pwd;
  266.     private String email;
  267.     private String zipcode;
  268.     private String addr;
  269.     private String name;
  270.     private String birthday;
  271.     private String phone;
  272.     private int point;
  273.     private int level_id;
  274.     private String regdate;
  275.     private String recently;
  276.     private String telephone;
  277.     private int memberletter_id;
  278.     private String gender;
  279.  
  280.     public String getGender() {
  281.         return gender;
  282.     }
  283.  
  284.     public void setGender(String gender) {
  285.         this.gender = gender;
  286.     }
  287.  
  288.     public int getMember_id() {
  289.         return member_id;
  290.     }
  291.  
  292.     public void setMember_id(int member_id) {
  293.         this.member_id = member_id;
  294.     }
  295.  
  296.     public String getId() {
  297.         return id;
  298.     }
  299.  
  300.     public void setId(String id) {
  301.         this.id = id;
  302.     }
  303.  
  304.     public String getPwd() {
  305.         return pwd;
  306.     }
  307.  
  308.     public void setPwd(String pwd) {
  309.         this.pwd = pwd;
  310.     }
  311.  
  312.     public String getEmail() {
  313.         return email;
  314.     }
  315.  
  316.     public void setEmail(String email) {
  317.         this.email = email;
  318.     }
  319.  
  320.     public String getZipcode() {
  321.         return zipcode;
  322.     }
  323.  
  324.     public void setZipcode(String zipcode) {
  325.         this.zipcode = zipcode;
  326.     }
  327.  
  328.     public String getAddr() {
  329.         return addr;
  330.     }
  331.  
  332.     public void setAddr(String addr) {
  333.         this.addr = addr;
  334.     }
  335.  
  336.     public String getName() {
  337.         return name;
  338.     }
  339.  
  340.     public void setName(String name) {
  341.         this.name = name;
  342.     }
  343.  
  344.     public String getBirthday() {
  345.         return birthday;
  346.     }
  347.  
  348.     public void setBirthday(String birthday) {
  349.         this.birthday = birthday;
  350.     }
  351.  
  352.     public String getPhone() {
  353.         return phone;
  354.     }
  355.  
  356.     public void setPhone(String phone) {
  357.         this.phone = phone;
  358.     }
  359.  
  360.     public int getPoint() {
  361.         return point;
  362.     }
  363.  
  364.     public void setPoint(int point) {
  365.         this.point = point;
  366.     }
  367.  
  368.     public int getLevel_id() {
  369.         return level_id;
  370.     }
  371.  
  372.     public void setLevel_id(int level_id) {
  373.         this.level_id = level_id;
  374.     }
  375.  
  376.     public String getRegdate() {
  377.         return regdate;
  378.     }
  379.  
  380.     public void setRegdate(String regdate) {
  381.         this.regdate = regdate;
  382.     }
  383.  
  384.     public String getRecently() {
  385.         return recently;
  386.     }
  387.  
  388.     public void setRecently(String recently) {
  389.         this.recently = recently;
  390.     }
  391.  
  392.     public String getTelephone() {
  393.         return telephone;
  394.     }
  395.  
  396.     public void setTelephone(String telephone) {
  397.         this.telephone = telephone;
  398.     }
  399.  
  400.     public int getMemberletter_id() {
  401.         return memberletter_id;
  402.     }
  403.  
  404.     public void setMemberletter_id(int memberletter_id) {
  405.         this.memberletter_id = memberletter_id;
  406.     }
  407.  
  408. }
  409.  
  410.  
  411.  
  412. ★ 7. DidNotCheckLoginException.java
  413.  
  414. package common.exception;
  415.  
  416. public class DidNotCheckLoginException extends RuntimeException {
  417.  
  418.     public DidNotCheckLoginException(String msg) {
  419.         super(msg);
  420.     }
  421.  
  422. }
  423.  
  424.  
  425.  
  426. ★ 8. AdminFailException.java
  427.  
  428.  
  429. package common.exception;
  430.  
  431. public class AdminFailException extends RuntimeException{
  432.    
  433.     public AdminFailException(String msg) {
  434.         super(msg);
  435.     }
  436.    
  437. }
  438.  
  439.  
  440. ★ 9. DoNotLoginException.java
  441.  
  442. package common.exception;
  443.  
  444. public class DoNotLoginException extends RuntimeException{
  445.    
  446.     public DoNotLoginException(String msg) {
  447.         super(msg);
  448.     }
  449. }
  450.  
  451.  
  452. ★ 10. LoginException.java
  453.  
  454.  
  455. package common.exception;
  456.  
  457. public class LoginException extends RuntimeException{
  458.    
  459.     public LoginException(String msg) {
  460.         super(msg);
  461.     }
  462. }
  463.  
  464.  
  465. ★ 11. LoginCheckInterceptor.java
  466.  
  467.  
  468. package common.intercepter;
  469.  
  470. import javax.servlet.http.HttpServletRequest;
  471. import javax.servlet.http.HttpServletResponse;
  472. import javax.servlet.http.HttpSession;
  473.  
  474. import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
  475.  
  476.  
  477. /* 로그인 안한거 체크하기 */
  478. public class LoginCheckInterceptor extends HandlerInterceptorAdapter{
  479.    
  480.     // 메서드 실행전에 검사하기
  481.     @Override
  482.     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)  throws Exception {
  483.        
  484.         HttpSession session = request.getSession();
  485.        
  486.         if(session != null){
  487.             Object admin = session.getAttribute("admin");
  488.             if(admin != null){  // 세션에 넣은 값이 존재하면,
  489.                 return true;    // 리턴값이 true이면 메서드 실행.
  490.             }
  491.         }
  492.         response.sendRedirect(request.getContextPath()+"/admin/index.jsp"); // 서버에 등록된 Context 경로/admin/index.jsp로 이동.
  493.        
  494.         return false; // 리턴값이 false이면 메서드 실행 안함.
  495.     }
  496. }
  497.  
  498.  
  499. ★ 12. MemberMapper.xml
  500.  
  501. <?xml version="1.0" encoding="UTF-8" ?>
  502. <!DOCTYPE mapper
  503.   PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  504.   "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  505. <mapper namespace="Member">
  506.     <insert id="insert" parameterType="Member">
  507.         insert into
  508.         member(member_id, id, pwd, email, zipcode, addr, name,birthday,phone,point,level_id,telephone,memberletter_id,gender)
  509.         values(
  510.         seq_member.nextval,
  511.         #{id,jdbcType=INTEGER},
  512.         #{pwd,jdbcType=VARCHAR},
  513.         #{email,jdbcType=VARCHAR},
  514.         #{zipcode,jdbcType=VARCHAR},
  515.         #{addr,jdbcType=VARCHAR},
  516.         #{name,jdbcType=VARCHAR},
  517.         #{birthday,jdbcType=VARCHAR},
  518.         #{phone,jdbcType=VARCHAR},
  519.         #{point,jdbcType=INTEGER },
  520.         #{level_id,jdbcType=INTEGER },
  521.         #{telephone,jdbcType=VARCHAR},
  522.         #{memberletter_id,jdbcType=INTEGER},
  523.         #{gender,jdbcType=VARCHAR})
  524.     </insert>
  525.    
  526.     <select id="selectId" resultType="Member">
  527.         select id from member where
  528.         id=#{id}
  529.     </select>
  530.    
  531.     <select id="checkLogin" resultType="Member" parameterType="Member">
  532.         select id from member where id=#{id} and pwd=#{pwd}
  533.     </select>
  534.    
  535.     <select id="selectOne" resultType="Member" parameterType="string">
  536.         select * from member where id=#{id}
  537.     </select>
  538.    
  539.     <select id="selectAll" resultType="Member">
  540.         select * from member order by member_id desc
  541.     </select>
  542.    
  543. </mapper>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top