728x90
더보기
Day83. 230828
index이용 메인페이지,redirect
MainController>
package com.mycom.app;
import com.mycom.app.question.entity.Question;
import com.mycom.app.question.repository.QuestionRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
@Controller
public class MainController {
@Autowired
private QuestionRepository questionRepository;
//요청주소 http://localhost:8090/
//메인화면이 보여줘야한다.
//요청주소 http://localhost:8090/question/list
//일단 여기에서는 질의목록페이지(question_list.html)를 출력
@GetMapping("/")
//@ResponseBody
public String index(){
return "index"; //templates폴더하위 index.html문서
}
}
redirect : 페이지 전환 주체가 클라이언트로,서버에서 클라이언트에게 요청한 url을 다른 url로 재접속하라고 명령을 보내는 것이다.
index.html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
</head>
<body>
<h1>INDEX</h1>
<h2>index화면</h2>
<ul>
<li><a href="/question/list">질의응답게시판(목록조회)</a></li>
</ul>
</body>
</html>
localhost:8090 으로 요청했을 때 redirect요청으로 index화면으로 간다.
728x90
'개발 수업 > Spring Boot' 카테고리의 다른 글
[SpringBoot] 질문 목록에 답변 갯수 출력 (0) | 2023.08.28 |
---|---|
[SpringBoot] Thymeleaf(타임리프) 사용(유효성검사, 네비게이션바) (0) | 2023.08.28 |
[SpringBoot] QnA게시판 질문 등록 (0) | 2023.08.27 |
[SpringBoot] 게시판 상세조회 댓글 수/댓글 출력 (0) | 2023.08.27 |
[SpringBoot] 부트스트랩5 적용 (0) | 2023.08.24 |