• 티스토리 홈
  • 프로필사진
    Song hyun
  • 방명록
  • 공지사항
  • 태그
  • 블로그 관리
  • 글 작성
Song hyun
  • 프로필사진
    Song hyun
    • 분류 전체보기 (780)
      • 백준 (0)
      • 영어 (2)
        • Diary (0)
        • Toast Masters (2)
      • 메모 (13)
      • 설치 메뉴얼 (30)
      • Java (178)
      • MySQL (60)
      • JSP (67)
      • Springboot (46)
      • HTML,CSS, JS (71)
        • HTML (8)
        • CSS (12)
        • JavaScript (37)
        • HTML&CSS 스터디 (13)
      • C++ (7)
      • Linux (7)
      • JPA (34)
      • Kotlin (2)
      • Flutter (42)
      • Error Note (39)
      • 디자인 패턴 (12)
      • 디지털논리회로 (4)
      • 데이터베이스 시스템 (8)
      • 알고리즘 (7)
      • 운영체제 (3)
      • 이산수학 (3)
      • 인공지능 (1)
      • 자료 구조 (14)
        • 기본 개념 (14)
        • 자료구조 스터디 (0)
      • 💡My project (76)
        • 팩맨 : Java Swing 게임 제작 프로젝트 (6)
        • 네이트톡 : Java 소켓 통신 프로젝트 (4)
        • 포켓옥션 : HikariCP&JDBC CRUD 프.. (3)
        • 이지 부산 : BDIA-Devton 2024 프로.. (20)
        • 그린 유니버시티 : JSP를 사용한 학사관리 프로.. (1)
        • 애드 포커 : 웹 소켓과 Spring을 사용한 카.. (1)
        • 셸위 : 게임 친구 매칭 사이트 (21)
        • 다모아 : 개발자 중개 플랫폼 (20)
      • 📗스터디 (13)
        • CNN : 웹개발 스터디 (10)
        • Node&React로 유튜브 사이트 만들기 (3)
      • 📙독서 및 강연 기록 (36)
        • 강연 (14)
        • 독서 (22)
  • 방문자 수
    • 전체:
    • 오늘:
    • 어제:
  • 최근 댓글
      등록된 댓글이 없습니다.
    • 최근 공지
        등록된 공지가 없습니다.
      # Home
      # 공지사항
      #
      # 태그
      # 검색결과
      # 방명록
      • [셸위:게임 친구 매칭 사이트] MBTI 테스트 구현 (2) - 테스트 로직
        2024년 09월 02일
        • Song hyun
        • 작성자
        • 2024.09.02.:37
        728x90
        반응형

        [셸위:게임 친구 매칭 사이트] MBTI 테스트 구현 (2) - 테스트 로직

         

         

        *DB 

         

        1. TestController.java

        package com.example.demo.controller;
        
        import java.util.List;
        
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.http.ResponseEntity;
        import org.springframework.stereotype.Controller;
        import org.springframework.ui.Model;
        import org.springframework.web.bind.annotation.GetMapping;
        import org.springframework.web.bind.annotation.PostMapping;
        import org.springframework.web.bind.annotation.RequestBody;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestParam;
        import org.springframework.web.bind.annotation.ResponseBody;
        
        import com.example.demo.repository.QuestionRepository;
        import com.example.demo.repository.model.Answer;
        import com.example.demo.repository.model.Mbti;
        import com.example.demo.repository.model.Question;
        import com.example.demo.service.MbtiService;
        import com.example.demo.service.QuestionService;
        
        import jakarta.servlet.http.HttpSession;
        import lombok.RequiredArgsConstructor;
        
        @Controller
        @RequestMapping("/test")
        @RequiredArgsConstructor
        public class TestController {
        	
        	@Autowired
        	private HttpSession httpSession;
        	
        	@Autowired
        	private QuestionService questionService;
        	@Autowired
        	private MbtiService mbtiService;
        	private int progressNumber;
        	
        	public TestController(HttpSession httpSession, QuestionService questionService){
        		this.httpSession  = httpSession;
        		this.questionService = questionService;
        		progressNumber=1;
        	}
        	
        
        	/**
        	 * 메인 페이지 이동
        	 * @return
        	 */
        	// http://localhost:8080/test/main
        	@GetMapping("/main")
        	public String mainPage() {
        		return "mainPage";
        	}
        	
        	/**
        	 * MBTI 테스트 페이지 이동
        	 * @param model
        	 * @return
        	 */
        	// http://localhost:8080/test/start-test
        	@GetMapping("/start-test")
        	public String testPage(Model model) {
        		
        		List<Question> questionList = questionService.getAllQuestion();
        		int progressNumber = 0;
        		model.addAttribute("questionList", questionList);
        		model.addAttribute("progressNumber", progressNumber);
        		return "test/startTestPage";
        	}
        	
        	/**
        	 * MBTI 결과 페이지 송출
        	 * @param entity
        	 * @return
        	 */
        	// http://localhost:8080/test/show-result
        	@PostMapping("/show-result")
        	public String postMethodName(@RequestParam("answerArray") List<String> answerArray,
        			Model model) {
        		// 로깅
            	//answers.forEach(answer -> {
                //    System.out.println(" Answer: " + answer.getAnswer());
                // });
            	
            	int sNum=0; // 외향형
            	int nNum=0; // 내향형
            	int qNum=0; // 낭만형
            	int mNum=0; // 효율형
            	int rNum=0; // 리더형
            	int eNum=0; // 개인형
            	int tNum=0; // 즐기는 자형
            	int cNum=0; // 승부욕 형
            	
            	// 외향-내향형 가르기
            	for(int i=0; i<3; i++) {
            		if(answerArray.get(i).contains("no")) {
            			sNum++;
            		} else if(answerArray.get(i).contains("yes")){
                		nNum++;
            		}
            	}
            	
            	// 낭만-효율형 가르기
            	for(int i=3; i<6; i++) {
            		if(answerArray.get(i).contains("no")) {
            			qNum++;
            		} else if(answerArray.get(i).contains("yes")) {
                		mNum++;
            		}
            	}
            	
            	// 리더-개인형 가르기
            	for(int i=6; i<9; i++) {
            		if(answerArray.get(i).contains("no")) {
            			eNum++;
            		} else if(answerArray.get(i).contains("yes")) {
            			rNum++;
            		}
            	}
            	
            	// 즐기는 자-승부욕 형 가르기
            	for(int i=9; i<11; i++) {
            		if(answerArray.get(i).contains("no")) {
            			tNum++;
            		} else if(answerArray.get(i).contains("yes")) {
            			cNum++;
            		}
            	}
            	
            	// 키워드 뽑기
            	String first = sNum>nNum ? "S" : "N";
            	String second = qNum>mNum ? "Q" : "M";
            	String third = eNum>rNum ? "E" : "R";
            	String fourth = tNum>eNum ? "T" : "C";
            	
            	// 키워드 합치기
            	String result=first+second+third+fourth;
            	
            	System.out.println(result);
            	
            	// 키워드를 통해 결과 탐색
            	Mbti resultMbti = mbtiService.selectMbtiByName(result);
            	
            	// 키워드를 통해 궁합 탐색
            	Mbti goodMatchedMbti = mbtiService.selectMbtiByCompatibility(100);
            	Mbti badMatchedMbti = mbtiService.selectMbtiByCompatibility(0);
        
            	// 세션에 데이터 저장
            	model.addAttribute("resultMbti", resultMbti);
            	model.addAttribute("goodMatchedMbti", goodMatchedMbti);
            	model.addAttribute("badMatchedMbti", badMatchedMbti);
        
                // 페이지 리디렉션
                return "/test/resultTest";
        	}
        	
        	
        }

         

         

        2. QuestionService.java

        package com.example.demo.service;
        
        import java.util.ArrayList;
        import java.util.List;
        
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.stereotype.Service;
        
        import com.example.demo.repository.QuestionRepository;
        import com.example.demo.repository.model.Question;
        
        @Service
        public class QuestionService {
        	
        	@Autowired
        	private QuestionRepository questionRepository;
        	
        	public QuestionService() {
        		this.questionRepository=questionRepository;
        	}
        	
        	public Question getQuestionById(Integer id) {
        		Question question = questionRepository.selectQuestionbyId(id);
        		return question;
        	}
        	
        	public List<Question> getAllQuestion() {
        		List<Question> questionList = new ArrayList<>();
        		questionList=questionRepository.selectAllQuestions();
        		return questionList;
        	}
        
        }

         

         

        3. QuestionRepository

        package com.example.demo.repository;
        
        import java.util.List;
        
        import org.apache.ibatis.annotations.Mapper;
        
        import com.example.demo.repository.model.Question;
        
        @Mapper
        public interface QuestionRepository {
        	
        	// id로 질문 찾아오기
        	Question selectQuestionbyId(Integer id);
        
        	// 모든 질문 찾아오기
        	List<Question> selectAllQuestions();
        }
        728x90
        반응형

        '💡My project > 셸위 : 게임 친구 매칭 사이트' 카테고리의 다른 글

        [셸위:게임 친구 매칭 사이트] 드롭다운 메뉴 구현  (1) 2024.09.04
        [셸위:게임 친구 매칭 사이트] 슬라이드 배너 구현  (4) 2024.09.03
        [셸위:게임 친구 매칭 사이트] MBTI 테스트(1) - 프론트  (0) 2024.09.02
        [셸위:게임 친구 매칭 사이트] 6. 1차 기능 구현(2) - 2024.08.26  (0) 2024.08.26
        [셸위:게임 친구 매칭 사이트] 6. 1차 기능 구현(1) - 2024.08.23  (0) 2024.08.24
        다음글
        다음 글이 없습니다.
        이전글
        이전 글이 없습니다.
        댓글
      조회된 결과가 없습니다.
      스킨 업데이트 안내
      현재 이용하고 계신 스킨의 버전보다 더 높은 최신 버전이 감지 되었습니다. 최신버전 스킨 파일을 다운로드 받을 수 있는 페이지로 이동하시겠습니까?
      ("아니오" 를 선택할 시 30일 동안 최신 버전이 감지되어도 모달 창이 표시되지 않습니다.)
      목차
      표시할 목차가 없습니다.
        • 안녕하세요
        • 감사해요
        • 잘있어요

        티스토리툴바