JAVA를 잡아라!...
JAVA_MVC_#3_자판기.ver2 (DAO,DTO 2개) 본문
자판기.ver1 제품 + 회원
한글코딩
MemberDTO
회원이라면 data를 가져야함
- 멤버변수 : (모두 private) 아이디(PK), 비밀번호, 이름
+ String setSearchCondition (JAVA로직에서만 사용하는 변수, 검색조건 확인용)
- getter & setter : private 멤버변수이니까 생성해주기
- @toString
------------------------------------------------------
PK란? 시스템이 부여하는 값으로 유일한 값이어야 함
ID의 경우, 사용자가 생성하며 중복이 불가하므로 PK로 사용됨 ★
PK가 int 자료형인 제품DTO와 달리,
회원DTO에서는 id가 String 자료형임... id니까..!
그래서 id 비교할땐 equals() 사용
DAO에서 "ID 중복검사"필수!
MemberView
Member와 관련된 view를 관리
--> 높은 응집도 : 관련있는 코드끼리 묶어서 관리하는 것
< 회원가입 때 필요한 view 만들기 >
- ID 입력 받기
- 중복되는 ID사용시 안내 문구 출력
- PW 입력 받기
- Name 입력 받기
- 회원가입 성공 출력
- 로그인 성공 출력
- 로그인 실패 출력
- 로그아웃 성공 출력
- 회원탈퇴 성공 출력
- 비밀번호 변경 실패 출력
MemberDAO
C : 회원가입 [로그아웃상태] --> PK사용자지정 (ID)
R : ID중복검사 [로그아웃상태]
: 로그인 [로그아웃상태]
: 로그아웃 [로그인상태] --> user==null 되면되서 Ctrl에서 ㄱㄱ
U : 비밀번호변경 [로그인상태]
D : 회원탈퇴 [로그인상태]
-----------------------------
R1 - selectAll
R2 - selectOne : ID중복검사, 로그인, 로그아웃
▶ID중복검사
인자로 받아온 객체의 searchCondition이 "ID중복검사"라면
이 객체의 ID와 일치하는 ID를 갖는 배열의 객체가 있니?
있으면 --> new객체에 id, pw, 이름 저장 (원본손실방지를 위해 객체를 new함)
call by reference때문에 여러번 selectOne이 사용될 경우 원본배열의 객체가 손실됨
그래서 새로운 객체를 new해서 데이터 저장..!
null이 아닌 new 객체가 반환 --> 이미 사용중인 id이므로 회원가입 불가
없으면 --> null 반환 (ID사용 가능!)
▶로그인
인자로 받아온 객체의 searchCondition이 "로그인"이라면
이 객체의 ID, PW가 일치하는 ID, PW를 갖는 배열의 객체가 있니?
ID중복검사와 동일한 로직
▶중복검사, 로그인이 아니면 null 반환
C - insert (회원가입)
U - update (비밀번호변경)
D - delete (회원탈퇴)
Code
Client
package client;
import controller.Ctrl;
public class Test {
Ctrl app = new Ctrl();
app.start();
}
ProductDTO
package model;
public class ProductDTO {
private int pkNum;
private String name;
private int price;
private int cnt;
private String searchCondition;
private int addCnt;
public int getPkNum() {
return pkNum;
}
public void setPkNum(int pkNum) {
this.pkNum = pkNum;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getCnt() {
return cnt;
}
public void setCnt(int cnt) {
this.cnt = cnt;
}
public String getSearchCondition() {
return searchCondition;
}
public void setSearchCondition(String searchCondition) {
this.searchCondition = searchCondition;
}
public int getAddCnt() {
return addCnt;
}
public void setAddCnt(int addCnt) {
this.addCnt = addCnt;
}
@Override
public String toString() {
return "[" + this.pkNum + "]" + this.name + "가격: " + this.price + ", 재고: " + this.cnt;
}
}
ProductDAO
package model;
import java.util.ArrayList;
public class ProductDAO {
// 상품 배열 선언
private ArrayList<ProductDTO> datas;
public ProductDAO() {
this.datas = new ArrayList<ProductDTO>();
// sample
ProductDTO sample01 = new ProductDTO();
sample01.setPkNum(1001);
sample01.setName("콜라");
sample01.setPrice(1200);
sample01.setCnt(3);
datas.add(sample01);
ProductDTO sample02 = new ProductDTO();
sample02.setPkNum(1002);
sample02.setName("사이다");
sample02.setPrice(1100);
sample02.setCnt(0);
datas.add(sample02);
}
// R - 전체출력
public ArrayList<ProductDTO> selectAll(ProductDTO productDTO) {
// 전체검색
if (productDTO.getSearchCondition() == null) {
return this.datas;
}
// 이름검색
else if (productDTO.getSearchCondition().equals("이름검색")) {
ArrayList<ProductDTO> searchDatas = new ArrayList<ProductDTO>();
for (int i = 0; i < this.datas.size(); i++) {
if (datas.get(i).getPkNum() == productDTO.getPkNum()) {
searchDatas.add(datas.get(i));
}
}
return searchDatas;
}
// 아무것도 해당 안되면 null 반환
return null;
}
// R - 하나출력
public ProductDTO selectOne(ProductDTO productDTO) {
boolean flag = false;
int i;
for (i = 0; i < this.datas.size(); i++) {
if (this.datas.get(i).getPkNum() == productDTO.getPkNum()) {
flag = true;
break;
}
}
if (!flag) {
return null;
}
return this.datas.get(i);
}
// C - 제품추가
public boolean insert(ProductDTO productDTO) {
try {
ProductDTO data = new ProductDTO();
data.setPkNum(productDTO.getPkNum());
data.setName(productDTO.getName());
data.setPrice(productDTO.getPrice());
data.setCnt(productDTO.getCnt());
this.datas.add(data);
} catch (Exception e) {
System.out.println("[로--그] 알수없는오류 발생!");
return false;
}
return true;
}
// U
// Spring에서는 반드시 DAO를 통해서만 값을 변경해야 함
// 컨트롤러에서 값을 저장하지만 DAO를 통해 한번 더 값변경 실행
public boolean update(ProductDTO productDTO) {
// 구매 - 재고 1개 차감
if (productDTO.getSearchCondition().equals("구매")) {
// 인자로 받아온 객체의 재고에서 -1을 해준 값을 이 객체의 재고에 저장
productDTO.setCnt(productDTO.getCnt() - 1);
}
// 가격변경 - 인자로 받아온 객체의 가격으로 변경
else if (productDTO.getSearchCondition().equals("가격변경")) {
// 인자로 받아온 객체의 가격을 이 객체의 가격에 저장
productDTO.setPrice(productDTO.getPrice());
}
// 재고변경 - 인자로 받아온 객체의 재고로 변경
else if (productDTO.getSearchCondition().equals("재고변경")) {
// 인자로 받아온 객체의 재고를 이 객체의 재고에 저장
productDTO.setCnt(productDTO.getCnt());
}
// 재고추가 - 인자로 받아온 객체의 재고를 추가
else if (productDTO.getSearchCondition().equals("재고추가")) {
// 인자로 받아온 객체의 기존재고 + add재고를 이 객체의 재고에 저장
productDTO.setCnt(productDTO.getCnt() + productDTO.getAddCnt());
} else {
return false;
}
return true;
}
// D - 제품삭제
public boolean delete(ProductDTO productDTO) {
try {
int i;
for (i = 0; i < this.datas.size(); i++) {
if (productDTO.getPkNum() == this.datas.get(i).getPkNum()) {
break;
}
}
this.datas.remove(i);
} catch (Exception e) {
System.out.println("[로--그] 알수없는오류 발생!");
return false;
}
return true;
}
}
ProductView
package view;
import java.util.ArrayList;
import java.util.Scanner;
import model.ProductDTO;
public class ProductView {
private Scanner sc;
public ProductView() {
this.sc = new Scanner(System.in);
}
// 로그아웃 상태 view
public void printLogoutMenu() {
System.out.println("=== 자 판 기 ===");
System.out.println("1. 상품목록출력");
System.out.println("2. 상품선택");
System.out.println("3. 이름으로검색");
System.out.println("4. 회원가입"); // 회원일때도 가능하고, 비회원일때도 가능
System.out.println("5. 로그인");
System.out.println("0. 종료");
}
// 4,5를 누를 수 없게 view & controller에서 유효성 검사 ★
// 다른기능이기 때문에 번호를 다르게 배치
// 로그인 상태 view
public void printLoginMenu() {
System.out.println("=== 자 판 기 ===");
System.out.println("1. 상품목록출력");
System.out.println("2. 상품선택");
System.out.println("3. 이름으로검색");
System.out.println("6. 로그아웃");
System.out.println("7. 비밀번호변경");
System.out.println("8. 회원탈퇴");
System.out.println("0. 종료");
}
// 관리자 view
public void printAdminMenu() {
System.out.println("=== 관 리 자 ===");
System.out.println("1. 상품추가");
System.out.println("2. 상품가격변경");
System.out.println("3. 상품재고변경");
System.out.println("4. 상품재고추가");
System.out.println("5. 상품삭제");
System.out.println("0. 관리자모드 종료");
}
public void adminInfo() {
System.out.println("관리자 모드는 7777로 진입하실수있습니다.");
}
public int inputInteger() {
System.out.print("번호입력 >> ");
int integer = sc.nextInt();
return integer;
}
public int inputpkNum() {
System.out.print("상품번호입력 >> ");
int pkNum = sc.nextInt();
return pkNum;
}
public String inputName() {
System.out.print("상품이름입력 >> ");
String name = sc.next();
return name;
}
public int inputPrice() {
System.out.print("상품가격입력 >> ");
int price = sc.nextInt();
return price;
}
public int inputCnt() {
System.out.print("상품재고입력 >> ");
int cnt = sc.nextInt();
return cnt;
}
public void printTrue() {
System.out.println("성공!");
}
public void printFalse() {
System.out.println("실패!");
}
public void printInsertData(ProductDTO productDTO) {
System.out.println(productDTO.getPkNum() + "데이터 추가");
}
public void printDatas(ArrayList<ProductDTO> datas) {
// 상품 등록이 안되어 있는 경우
if (datas.size() == 0) {
System.out.println("데이터 없음...");
}
for (ProductDTO data : datas) {
// 상품의 재고가 없는 경우
if (data.getCnt() == 0) {
System.out.println("[" + data.getPkNum() + "] 재고 없음.");
continue;
}
System.out.println(data);
}
}
public void printData(ProductDTO productDTO) {
if (productDTO == null) {
System.out.println("일치하는 데이터가 없습니다.");
return; // 메소드 종료
}
if (productDTO.getCnt() == 0) {
System.out.println("재고가 없습니다.");
return; // 메소드 종료
}
System.out.println(productDTO);
System.out.println("구매완료");
}
public void printNoData() {
System.out.println("데이터 없음....");
}
}
MemberDTO
package model;
public class MemberDTO {
private String mid;
private String mpw;
private String name;
private String searchCondition;
public String getMid() {
return mid;
}
public void setMid(String mid) {
this.mid = mid;
}
public String getMpw() {
return mpw;
}
public void setMpw(String mpw) {
this.mpw = mpw;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSearchCondition() {
return searchCondition;
}
public void setSearchCondition(String searchCondition) {
this.searchCondition = searchCondition;
}
@Override
public String toString() {
return "MemberDTO [ID: " + mid + ", PW: " + mpw + ", name: " + name + "]";
}
}
MemberDAO
package model;
import java.util.ArrayList;
public class MemberDAO {
// 회원 배열 선언
private ArrayList<MemberDTO> datas;
public MemberDAO() {
this.datas = new ArrayList<MemberDTO>();
// sample
MemberDTO admin = new MemberDTO();
admin.setMid("admin");
admin.setMpw("7777");
admin.setName("관리자");
datas.add(admin);
}
// R - 전체회원 출력
public ArrayList<MemberDTO> selectAll(MemberDTO memberDTO) {
return datas;
}
// R - 회원1명 출력
public MemberDTO selectOne(MemberDTO memberDTO) {
// ID중복검사 후 출력
if (memberDTO.getSearchCondition().equals("ID중복검사")) {
// 배열에서 중복되는 ID있는지 찾기
boolean flag = false;
int i;
for (i = 0; i < this.datas.size(); i++) {
if (this.datas.get(i).getMid().equals(memberDTO.getMid())) {
flag = true;
break;
}
}
// 일치하는 ID 없으면 없다고 null 반환 --> 중복되는 ID 없음 --> 회원가입 가능
if (!flag) {
return null;
}
MemberDTO data = new MemberDTO();
data.setMid(this.datas.get(i).getMid());
datas.setMpw(this.datas.get(i).getMpw());
datas.setName(this.datas.get(i).getName());
// 일치하는 ID 있으면 이 객체 반환 --> 중복되는 ID 있음 --> 회원가입 불가
return data;
// 원본 객체의 주소값을 반환하면 다시 id를 입력받을때 원본의 id가 손실됨
// return this.datas.get(i); 원본을 반환하지 말자
}
// 로그인
else if (memberDTO.getSearchCondition().equals("로그인")) {
boolean flag = false;
int i;
for (i = 0; i < this.datas.size(); i++) {
// 객체의 ID,PW가 둘다 일치하는 배열객체가 있으면 회원임! true반환, break;
if (this.datas.get(i).getMid().equals(memberDTO.getMid())
&& this.datas.get(i).getMpw().equals(memberDTO.getMpw())) {
flag = true;
break;
}
}
// 배열에 일치하는 객체가 없으면 없는 회원이므로 null반환
if (!flag) {
return null;
}
MemberDTO data = new MemberDTO();
data.setMid(this.datas.get(i).getMid());
datas.setMpw(this.datas.get(i).getMpw());
datas.setName(this.datas.get(i).getName());
// 일치하는 ID 있으면 이 객체 반환 --> 중복되는 ID 있음 --> 회원가입 불가
return data;
// 원본 객체의 주소값을 반환하면 다시 id를 입력받을때 원본의 id가 손실됨
// return this.datas.get(i); 원본을 반환하지 말자
}
// 둘다 해당 안되면
return null;
}
// C - 회원가입
public boolean insert(MemberDTO memberDTO) {
// 인자로 받아온 객체의 속성들을 new 객체의 속성에 저장 후 배열에 추가
try {
MemberDTO data = new MemberDTO();
data.setMid(memberDTO.getMid());
data.setMpw(memberDTO.getMpw());
data.setName(memberDTO.getName());
this.datas.add(data);
} catch (Exception e) {
System.out.println("[로--그] 알수없는오류 발생!");
return false;
}
return true;
}
// U - 비밀번호 변경
public boolean update(MemberDTO memberDTO) {
// 인자로 받아온 객체의 ID가 배열에 일치하는 객체가 있는지 확인 후 해당 배열의 PW 변경
boolean flag = false;
int i;
for (i = 0; i < this.datas.size(); i++) {
// ID는 String type이니까 equals()사용해서 비교
if (this.datas.get(i).getMid().equals(memberDTO.getMid())) {
flag = true;
break;
}
}
if (!flag) {
return false;
}
this.datas.get(i).setMpw(memberDTO.getMpw());
return true;
}
// D - 회원탈퇴
public boolean delete(MemberDTO memberDTO) {
boolean flag = false;
int i;
for (i = 0; i < datas.size(); i++) {
// ID는 String type이니까 equals()사용해서 비교
if (datas.get(i).getMid().equals(memberDTO.getMid())) {
flag = true;
break;
}
}
if (!flag) {
return false;
}
datas.remove(i);
return true;
}
}
MemberView
package view;
import java.util.Scanner;
public class MemberView {
private Scanner sc;
public MemberView() {
this.sc = new Scanner(System.in);
}
// < 회원가입할 때 필요한 view 만들기 >
// ID 입력
public String inputMemberID() {
System.out.println("ID 입력 >> ");
String mid = sc.next();
return mid;
}
// 비밀번호 입력
public String inputMemberPW() {
System.out.println("PW 입력 >> ");
String mpw = sc.next();
return mpw;
}
// 이름 입력
public String inputMemberName() {
System.out.println("회원 이름 입력 >> ");
String name = sc.next();
return name;
}
// 중복되는 ID사용시 안내 문구
public void signUpFalse() {
System.out.println("중복되는 ID라서 사용불가능합니다.");
}
// 회원가입 성공
public void signUpTrue() {
System.out.println("회원가입 성공!");
}
// 로그인 성공
public void loginTrue() {
System.out.println("로그인 성공!");
}
// 로그인 실패
public void loginFalse() {
System.out.println("로그인 실패!");
}
// 로그아웃 성공
// Thread : try-catch 필수
public void logoutTrue() {
System.out.println("로그아웃 중");
for (int i = 0; i < 5; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(".");
}
System.out.println();
System.out.println("로그아웃 완료!");
}
// 비밀번호 변경 성공
public void printPwUpdateTrue() {
System.out.println("비밀번호 변경 성공!");
}
// 비밀번호 변경 실패
public void printPwUpdateFalse() {
System.out.println("정보가 일치하지 않습니다.");
}
// 회원탈퇴 성공!
public void printDeleteTrue() {
System.out.println("회원탈퇴가 완료되었습니다.");
System.out.println("이용해주셔서 감사합니다.");
}
}
Controller
package controller;
import java.util.ArrayList;
import model.MemberDAO;
import model.MemberDTO;
import model.ProductDAO;
import model.ProductDTO;
import view.MemberView;
import view.ProductView;
public class Ctrl {
private ProductDAO productDAO;
private MemberDAO memberDAO;
private ProductView productView;
private MemberView memberView;
private MemberDTO user; // 현재 로그인한 사람의 정보
private int PK;
public Ctrl() {
this.productDAO = new ProductDAO();
this.memberDAO = new MemberDAO();
this.productView = new ProductView();
this.memberView = new MemberView();
this.user = null; // 아무도 로그인하지 않은 상태
this.PK = 1003;
}
public void start() {
while (true) {
// 로그아웃 상태
if (user == null) {
// 로그아웃 상태 view
productView.printLogoutMenu();
}
// 로그인 상태
else {
// 로그인 상태 view
productView.printLoginMenu();
// 관리자가 로그인하면 관리자번호 입력하라는 안내 view
if (user.getMid().equals("admin")) {
productView.adminInfo();
}
}
// 사용자에게 메뉴 선택 번호 받기 view
int action = productView.inputInteger();
// [0. 종료]
if (action == 0) {
break;
}
// [7777. 관리자 모드]
else if (action == 7777) {
while (true) {
productView.printAdminMenu();
action = productView.inputInteger();
// [0. 관리자모드 종료]
if (action == 0) {
break;
}
// [1. 상품추가]
else if (action == 1) {
String name = productView.inputName();
int price = productView.inputPrice();
int cnt = productView.inputCnt();
ProductDTO productDTO = new ProductDTO();
productDTO.setPkNum(PK++);
productDTO.setName(name);
productDTO.setPrice(price);
productDTO.setCnt(cnt);
boolean flag = productDAO.insert(productDTO);
if (flag) {
productView.printInsertData(productDTO);
} else {
productView.printFalse();
}
}
// [2. 상품가격변경]
else if (action == 2) {
int pkNum = productView.inputpkNum();
ProductDTO productDTO = new ProductDTO();
productDTO.setPkNum(pkNum);
productDTO = productDAO.selectOne(productDTO);
if (productDTO == null) {
productView.printNoData();
continue;
}
int price = productView.inputPrice();
productDTO.setPrice(price);
productDTO.setSearchCondition("가격변경");
boolean flag = productDAO.update(productDTO);
if (flag) {
productView.printTrue();
} else {
productView.printFalse();
}
}
// [3. 상품재고변경]
else if (action == 3) {
int pkNum = productView.inputpkNum();
ProductDTO productDTO = new ProductDTO();
productDTO.setPkNum(pkNum);
productDTO = productDAO.selectOne(productDTO);
if (productDTO == null) {
productView.printNoData();
continue;
}
int cnt = productView.inputCnt();
productDTO.setCnt(cnt);
productDTO.setSearchCondition("재고변경");
boolean flag = productDAO.update(productDTO);
if (flag) {
productView.printTrue();
} else {
productView.printFalse();
}
}
// [4. 상품재고추가]
else if (action == 4) {
int pkNum = productView.inputpkNum();
ProductDTO productDTO = new ProductDTO();
productDTO.setPkNum(pkNum);
productDTO = productDAO.selectOne(productDTO);
if (productDTO == null) {
productView.printNoData();
continue;
}
int addCnt = productView.inputCnt();
productDTO.setPrice(addCnt);
productDTO.setSearchCondition("재고추가");
boolean flag = productDAO.update(productDTO);
if (flag) {
productView.printTrue();
} else {
productView.printFalse();
}
}
// [5. 상품삭제]
else if (action == 5) {
int pkNum = productView.inputpkNum();
ProductDTO productDTO = new ProductDTO();
productDTO.setPkNum(pkNum);
productDTO = productDAO.selectOne(productDTO);
if (productDTO == null) {
productView.printNoData();
continue;
}
boolean flag = productDAO.delete(productDTO);
if (flag) {
productView.printTrue();
} else {
productView.printFalse();
}
}
}
}
// [1. 상품목록출력]
else if (action == 1) {
ProductDTO productDTO = new ProductDTO();
ArrayList<ProductDTO> datas = productDAO.selectAll(productDTO);
productView.printDatas(datas);
}
// [2. 상품선택]
else if (action == 2) {
int pkNum = productView.inputpkNum();
ProductDTO productDTO = new ProductDTO();
productDTO.setPkNum(pkNum);
ProductDTO data = productDAO.selectOne(productDTO);
productView.printData(productDTO);
if (data != null && data.getCnt() > 0) {
data.setSearchCondition("구매");
productDAO.update(data);
}
}
// [3. 이름으로검색]
else if (action == 3) {
String name = productView.inputName();
ProductDTO productDTO = new ProductDTO();
productDTO.setName(name);
productDTO.setSearchCondition("이름검색");
ArrayList<ProductDTO> datas = productDAO.selectAll(productDTO);
productView.printDatas(datas);
}
// [4. 회원가입] - 로그아웃 상태
else if (action == 4) {
// 로그인 상태면 되돌아가기
// 유효성 검사 ☆
if (user != null) {
continue;
}
// new 객체에 ID 저장해 ID중복검사 ㄱㄱ
// ID가 몇번만에 찾아질지 모르니 while()
MemberDTO memberDTO = new MemberDTO();
String mid;
while (true) {
mid = memberView.inputMemberID();
memberDTO.setMid(mid);
memberDTO.setSearchCondition("ID중복검사");
memberDTO = memberDAO.selectOne(memberDTO);
// 중복된 ID가 없으면 while문 탈출!
if (memberDTO == null) {
break;
}
// 중복된 ID가 있으면 다시 while문 실행
memberView.signUpFalse();
}
// new 객체에 ID, PW, 이름 저장
// selectOne()에서 반환된게 null이니까 새롭게 객체를 생성
memberDTO = new MemberDTO();
String mpw = memberView.inputMemberPW();
String name = memberView.inputMemberName();
memberDTO.setMid(mid);
memberDTO.setMpw(mpw);
memberDTO.setName(name);
memberDAO.insert(memberDTO);
memberView.signUpTrue();
}
// [5. 로그인] - 로그아웃 상태
else if (action == 5) {
// 로그인 상태면 되돌아가기
// 유효성 검사 ☆
if (user != null) {
continue;
}
// 사용자에게 ID, PW 받아오기
String mid = memberView.inputMemberID();
String mpw = memberView.inputMemberPW();
// new 객체에 ID, PW, "로그인" 저장
MemberDTO memberDTO = new MemberDTO();
memberDTO.setMid(mid);
memberDTO.setMpw(mpw);
memberDTO.setSearchCondition("로그인");
// selectOne()으로 일치하는 회원 찾아오고 저장
memberDTO = memberDAO.selectOne(memberDTO);
// 일치하는 객체가 없으면 실패 출력 view, 되돌아가기
if (memberDTO == null) {
memberView.loginFalse();
continue;
}
// 일치하는 객체가 있으면 user에 저장
user = memberDTO;
memberView.loginTrue();
}
// [6. 로그아웃] - 로그인 상태
else if (action == 6) {
user = null;
memberView.logoutTrue();
}
// [7. 비밀번호변경] - 로그인 상태
else if (action == 7) {
// 로그아웃 상태면 되돌아가기
// 유효성 검사 ☆
if (user == null) {
continue;
}
// 현재 비밀번호 받기
String mpw = memberView.inputMemberPW();
// 현재 로그인한 정보의 PW와 같은지 확인
MemberDTO memberDTO = new MemberDTO();
memberDTO.setMid(user.getMid());
memberDTO.setMpw(mpw);
memberDTO.setSearchCondition("로그인");
memberDTO = memberDAO.selectOne(memberDTO);
if (memberDTO == null) {
memberView.printPwUpdateFalse();
}
// 바꿀 비밀번호 받기
mpw = memberView.inputMemberPW();
memberDTO = new MemberDTO();
memberDTO.setMid(user.getMid()); // 현재 로그인한 사람을
memberDTO.setMpw(mpw); // 바꿀 PW로 설정
memberDAO.update(memberDTO);
// 로그아웃 시켜주기
user = null;
memberView.logoutTrue();
}
// [8. 회원탈퇴] - 로그인 상태
else if (action == 8) {
// 로그아웃 상태면 되돌아가기
// 유효성 검사 ☆
if (user == null) {
continue;
}
MemberDTO memberDTO = new MemberDTO();
memberDTO.setMid(user.getMid());
memberDAO.delete(memberDTO);
user = null; // 로그아웃 시켜주기!
memberView.printDeleteTrue();
}
}
}
}
'JAVA > JAVA_복습문제' 카테고리의 다른 글
JAVA_MVC_#3_자판기.ver3 (DAO,DTO 2개 / VIEW 多 / 장바구니)_수정중........................... (0) | 2023.12.18 |
---|---|
JAVA_MVC_#3_자판기.ver1 (DAO,DTO 1개) (0) | 2023.12.14 |
JAVA_MVC_#2_학생부.ver2 (0) | 2023.12.12 |
JAVA_MVC_#2_학생부.ver1 (1) | 2023.12.11 |
JAVA_MVC_#1_계산기 (0) | 2023.12.11 |