Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 정수형타입
- 컬렉션프레임워크
- 자동차수리시스템
- GRANT VIEW
- 환경설정
- exception
- oracle
- 생성자오버로드
- 한국건설관리시스템
- Java
- 참조형변수
- 예외처리
- 대덕인재개발원
- 추상메서드
- 메소드오버로딩
- EnhancedFor
- 컬렉션 타입
- 예외미루기
- abstract
- 집합_SET
- NestedFor
- cursor문
- 어윈 사용법
- 자바
- 제네릭
- 오라클
- 인터페이스
- 다형성
- 객체 비교
- 사용자예외클래스생성
Archives
- Today
- Total
거니의 velog
231123_SPRING 2 (2-3) 과제 본문
[Member.java]
package kr.or.ddit.vo;
import java.util.Date;
import java.util.List;
import org.springframework.format.annotation.DateTimeFormat;
import lombok.Data;
@Data
public class Member {
private String userId = "a001";
private String userName = "hongkd";
private String password = "1234";
private int coin = 100;
@DateTimeFormat(pattern = "yyyy/MM/dd")
private Date dateOfBirth;
private String email;
private String gender;
private String hobby;
private String[] hobbyArray;
private List<String> hobbyList;
private boolean foreigner;
private String developer;
private String nationality;
private Address address;
private List<Card> cardList;
private String cars;
private String[] carArray;
private List<String> carList;
private String introduction;
private String birthDay;
}
[Card.java]
package kr.or.ddit.vo;
import java.util.Date;
import org.springframework.format.annotation.DateTimeFormat;
import lombok.Data;
@Data
public class Card {
private String no;
@DateTimeFormat(pattern = "yyyy/MM/dd")
private Date validMonth;
}
[registerAllForm.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register ALL Form</title>
</head>
<body>
<h2>Register All Form</h2>
<form action="/registerUser" method="post">
<table border="1">
<tr>
<td>유저 ID</td>
<td><input type="text" name="userId" /></td>
</tr>
<tr>
<td>패스워드</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>이름</td>
<td><input type="text" name="userName" /></td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>생년월일</td>
<td><input type="text" name="dateOfBirth" /></td>
</tr>
<tr>
<td>성별</td>
<td>
<input type="radio" name="gender" value="male" checked="checked" />Male
<input type="radio" name="gender" value="female" />Female
<input type="radio" name="gender" value="other" />Other
</td>
</tr>
<tr>
<td>개발자 여부</td>
<td><input type="checkbox" name="developer" value="Y" /></td>
</tr>
<tr>
<td>외국인 여부</td>
<td><input type="checkbox" name="foreigner" value="true" /></td>
</tr>
<tr>
<td>국적</td>
<td>
<select name="nationality" class="jobs">
<option value="korea">대한민국</option>
<option value="germany">독일</option>
<option value="austrailia">호주</option>
<option value="canada">캐나다</option>
<option value="usa">미국</option>
</select>
</td>
</tr>
<tr>
<td>소유차량</td>
<td>
<select name="carArray" multiple="multiple">
<option value="">선택</option>
<option value="jeep">JEEP</option>
<option value="bmw">BMW</option>
<option value="audi">AUDI</option>
<option value="volvo">VOLVO</option>
</select>
</td>
</tr>
<tr>
<td>취미</td>
<td>
<input type="checkbox" name="hobby" value="sports" />Sports
<input type="checkbox" name="hobby" value="music" />Music
<input type="checkbox" name="hobby" value="movie" />Movie
</td>
</tr>
<tr>
<td>우편번호</td>
<td><input type="text" name="address.postCode" /></td>
</tr>
<tr>
<td>주소</td>
<td><input type="text" name="address.location" /></td>
</tr>
<tr>
<td>카드1 - 번호</td>
<td><input type="text" name="cardList[0].no" /></td>
</tr>
<tr>
<td>카드1 - 유효년월</td>
<td><input type="text" name="cardList[0].validMonth" /></td>
</tr>
<tr>
<td>카드2 - 번호</td>
<td><input type="text" name="cardList[1].no" /></td>
</tr>
<tr>
<td>카드2 - 유효년월</td>
<td><input type="text" name="cardList[1].validMonth" /></td>
</tr>
<tr>
<td>소개</td>
<td>
<textarea rows="30" cols="10" name="introduction" wrap="soft"></textarea>
</td>
</tr>
<tr>
<td>
<input type="submit" value="등록" />
<input type="reset" value="리셋" />
</td>
</tr>
</table>
</form>
</body>
</html>
[registerAllResult.jsp]
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Register All Result</title>
</head>
<body>
<!--
[아래 결과처럼 출력해주세요.]
유저ID a001
패스워드 1234
이름 조현준
E-MAIL ddit@naver.com
생년월일 2023년 11월 23일
성별 남자
개발자여부 개발자
외국인여부 외국인
국적 대한민국
소유차량 소유차량 없음
취미 운동 영화시청
우편번호 45617
주소 대전광역시 서구 오류동
카드1(번호) 1451-1234-1234-1122
카드1(유효년월) 2040년 09월 09일
카드2(번호) 1234-1234-1234-1234
카드2(유효년월) 2040년 09월 09일
소개 반갑습니다
** 조건
- 선택한 성별에 따라 남자/여자/기타로 나타내주세요.
- 개발자 여부 체크에 따라 개발자/일반으로 나타내주세요.
- 외국인 여부 체크에 따라 외국인/내국인으로 나타내주세요.
- 국적에 따라 대한민국/독일/호주/캐나다로 나타내주세요.
- 소유차량 선택에 따라 소유차량 없음/JEEP/VOLVO/BMW/AUDI로 나타내주세요.
선택에 따라 아래처럼 출력해주세요.
> 소유차량을 선택하지 않았을 때, 소유차량 없음
> 1개만 선택했을 때, JEEP
> 1개 이상을 선택했을 때, JEEP VOLVO AUDI
- 취미 선택에 따라 운동/영화시청/음악감상로 나타내주세요.
선택 갯수에 따라 아래처럼 출력해주세요.
> 취미를 선택하지 않았을 때, 취미 없음
> 1개만 선택했을 때, 음악감상
> 1개 이상을 선택했을 때, 운동 영화시청
-->
<table border="1" style="width: 100%;">
<colgroup>
<col width="30%" />
<col width="70%" />
</colgroup>
<tr>
<th>유저ID</th>
<td>${member.userId }</td>
</tr>
<tr>
<th>패스워드</th>
<td>${member.password }</td>
</tr>
<tr>
<th>이름</th>
<td>${member.userName }</td>
</tr>
<tr>
<th>E-MAIL</th>
<td>${member.email }</td>
</tr>
<tr>
<th>생년월일</th>
<td>
<c:choose>
<c:when test="${not empty member.dateOfBirth }">
${member.dateOfBirth }
</c:when>
<c:otherwise>
날짜 데이터 없음
</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<th>성별</th>
<td>${member.gender }</td>
</tr>
<tr>
<th>개발자여부</th>
<td>${member.developer }</td>
</tr>
<tr>
<th>외국인여부</th>
<td>${member.foreigner }</td>
</tr>
<tr>
<th>국적</th>
<td>${member.nationality }</td>
</tr>
<tr>
<th>소유차량</th>
<td>
<c:choose>
<c:when test="${memberArray.carArray[0] ne '소유차량 없음' }">
<c:forEach items="${memberArray.carArray }" var="carArray">
<c:if test="${carArray eq 'jeep' }">
JEEP
</c:if>
<c:if test="${carArray eq 'bmw' }">
BMW
</c:if>
<c:if test="${carArray eq 'audi' }">
AUDI
</c:if>
<c:if test="${carArray eq 'volvo' }">
VOLVO
</c:if>
</c:forEach>
</c:when>
<c:otherwise>
${memberArray.carArray[0] }
</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<th>취미</th>
<td>
<c:choose>
<c:when test="${memberArray.hobbyArray[0] ne '취미 없음' }">
<c:forEach items="${memberArray.hobbyArray }" var="hobbyArray">
<c:if test="${hobbyArray eq 'sports' }">
운동
</c:if>
<c:if test="${hobbyArray eq 'music' }">
음악
</c:if>
<c:if test="${hobbyArray eq 'movie' }">
영화시청
</c:if>
</c:forEach>
</c:when>
<c:otherwise>
${memberArray.hobbyArray[0] }
</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<th>우편번호</th>
<td>${member.postCode }</td>
</tr>
<tr>
<th>주소</th>
<td>${member.location }</td>
</tr>
<c:choose>
<c:when test="${empty cardList }">
<tr>
<td colspan="2">데이터가 존재하지 않습니다.</td>
</tr>
</c:when>
<c:otherwise>
<c:forEach items="${cardList }" var="card" varStatus="i">
<tr>
<th>
카드${i.index + 1}(번호)
</th>
<td>
<c:choose>
<c:when test="${not empty card.no }">
${card.no}
</c:when>
<c:otherwise>데이터 없음</c:otherwise>
</c:choose>
</td>
</tr>
<tr>
<th>
카드${i.index + 1}(유효년월)
</th>
<td>
<c:choose>
<c:when test="${not empty card.validMonth}">
<fmt:formatDate value="${card.validMonth}" pattern="yyyy년 MM월 dd일" type="date"/>
</c:when>
<c:otherwise>데이터 없음</c:otherwise>
</c:choose>
</td>
</tr>
</c:forEach>
</c:otherwise>
</c:choose>
<tr>
<th>소개</th>
<td>
<p style="white-space: pre-wrap;">${member.introduction }</p>
</td>
</tr>
</table>
<%-- <fmt:formatDate value="${member.dateOfBirth }" pattern="yyyy년 MM월 dd일" /> --%>
</body>
</html>
[MemberController.java]
package kr.or.ddit.controller.member;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import kr.or.ddit.vo.Address;
import kr.or.ddit.vo.Card;
import kr.or.ddit.vo.Member;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Controller
public class MemberController {
// 회원가입에 필요한 전체 폼 페이지 (문제)
@RequestMapping(value = "/registerAllForm", method = RequestMethod.GET)
public String registerAllForm() {
log.info("registerAllForm() 실행...!");
return "member/registerAllForm";
}
// 전체 폼 페이지 결과
@RequestMapping(value = "/registerUser", method = RequestMethod.POST)
public String registerUser(
Member member,
boolean foreigner,
Model model
) {
log.info("registerUser() 실행...!");
// 일반 데이터 보내기
//userId
log.info("member.userId : " + member.getUserId());
String userId = null;
if(member.getUserId() != null && member.getUserId() != "") {
userId = member.getUserId();
}else {
userId = "유저 ID 정보 없음";
}
log.info("userId : " + userId);
//password
log.info("member.password : " + member.getPassword());
String password = null;
if(member.getPassword() != null && member.getPassword() != "") {
password = member.getPassword();
}else {
password = "패스워드 정보 없음";
}
log.info("password : " + password);
//userName
log.info("member.userName : " + member.getUserName());
String userName = null;
if(member.getUserName() != null && member.getUserName() != "") {
userName = member.getUserName();
}else {
userName = "이름 정보 없음";
}
log.info("userName : " + userName);
//email
log.info("member.email : " + member.getEmail());
String email = null;
if(member.getEmail() != null && member.getEmail() != "") {
email = member.getEmail();
}else {
email = "E-Mail 정보 없음";
}
log.info("email : " + email);
// dateOfBirth
Date dateOfBirth = member.getDateOfBirth();
String strDateOfBirth = null;
if (dateOfBirth != null) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy년 MM월 dd일");
strDateOfBirth = simpleDateFormat.format(dateOfBirth);
log.info("strDateOfBirth : " + strDateOfBirth); // 이걸로 보내면 됨
}
// gender
String gender = null;
if(member.getGender().equals("male")) {
gender = "남자";
}else if(member.getGender().equals("female")) {
gender = "여자";
}else {
gender = "기타";
}
log.info("gender : " + gender); // 이걸로 보내면 됨
// developer
String developer = null;
if(member.getDeveloper() != null && member.getDeveloper().equals("Y")) {
developer = "개발자";
}else {
developer = "일반";
}
log.info("developer : " + developer); // 이걸로 보내면 됨
// foreigner
String strForeigner = null;
if(member.getDeveloper() != null && foreigner) {
strForeigner = "외국인";
}else {
strForeigner = "내국인";
}
log.info("strForeigner : " + strForeigner); // 이걸로 보내면 됨
// nationality
String nationality = null;
if(member.getNationality().equals("korea")) {
nationality = "대한민국";
}else if(member.getNationality().equals("germany")) {
nationality = "독일";
}else if(member.getNationality().equals("austrailia")) {
nationality = "호주";
}else if(member.getNationality().equals("canada")) {
nationality = "캐나다";
}else if(member.getNationality().equals("usa")) {
nationality = "미국";
}
log.info("nationality : " + nationality); // 이걸로 보내면 됨
// carArray
log.info("member.getCarArray() : " + member.getCarArray());
List<String> carArray = new ArrayList<String>();
if(member.getCarArray() != null) {
for(int i = 0; i < member.getCarArray().length; i++) {
log.info("member.getCarArray()["+i+"] : " + member.getCarArray()[i]);
carArray.add(member.getCarArray()[i]);
}
}else {
log.info("소유차량 없음");
carArray.add("소유차량 없음");
}
log.info("carArray : " + carArray.toString()); // 이걸로 보내면 됨
// hobbyArray
log.info("member.getHobby() : " + member.getHobby());
String[] hobbies;
List<String> hobbyArray = new ArrayList<String>();
if(member.getHobby() != null) {
hobbies = member.getHobby().split(",");
for(int i = 0; i < hobbies.length; i++) {
log.info("hobbies["+i+"] : " + hobbies[i]);
hobbyArray.add(hobbies[i]);
}
}else {
log.info("취미 없음");
hobbyArray.add("취미 없음");
}
log.info("hobbyArray : " + hobbyArray.toString()); // 이걸로 보내면 됨
// address.postCode
// address.location
Address address = member.getAddress();
String postCode = null;
String location = null;
log.info("address : " + address.toString());
log.info("getPostCode : " + address.getPostCode());
log.info("getLocation : " + address.getLocation());
if(address != null) {
log.info("address.postCode : " + address.getPostCode());
postCode = address.getPostCode();
log.info("address.location : " + address.getLocation());
location = address.getLocation();
}
if(address.getPostCode().equals("")) {
postCode = "우편번호 정보 없음";
}
if(address.getLocation().equals("")) {
location = "주소 정보 없음";
}
// cardList
List<Card> cardList = member.getCardList();
// introduction
log.info("member.introduction : " + member.getIntroduction());
String introduction = null;
if(member.getIntroduction() != null && member.getIntroduction() != "") {
introduction = member.getIntroduction();
}else {
introduction = "소개 정보 없음";
}
log.info("introduction : " + introduction);
// 정제된 데이터 보내기
Map<String, String> refineData = new HashMap<String, String>();
refineData.put("userId", userId);
refineData.put("password", password);
refineData.put("userName", userName);
refineData.put("email", email);
refineData.put("dateOfBirth", strDateOfBirth);
refineData.put("gender", gender);
refineData.put("developer", developer);
refineData.put("foreigner", strForeigner);
refineData.put("nationality", nationality);
refineData.put("postCode", postCode);
refineData.put("location", location);
refineData.put("introduction", introduction);
model.addAttribute("member", refineData);
// 정제된 데이터 보내기 - List
Map<String, List<String>> arrayData = new HashMap<String, List<String>>();
arrayData.put("carArray", carArray);
arrayData.put("hobbyArray", hobbyArray);
model.addAttribute("memberArray", arrayData);
// 카드 정보는 객체라서 jsp에서 예외 처리 함.
model.addAttribute("cardList", cardList);
return "member/registerAllResult";
}
}
- http://localhost/registerAllForm
'대덕인재개발원 > 대덕인재개발원_웹기반 애플리케이션' 카테고리의 다른 글
231124_SPRING 2 (3-2) (1) | 2023.11.24 |
---|---|
231124_SPRING 2 (3-1) (2) | 2023.11.24 |
231123_SPRING 2 (2-2) (0) | 2023.11.23 |
231123_SPRING 2 (2-1) (0) | 2023.11.23 |
231122_SPRING 2 (1-2) (0) | 2023.11.22 |