본문 바로가기
스마트인재개발원/Spring

[Spring] 게시판 만들기(2) - 리스트 레이아웃 만들기

by 죠졍니 2022. 10. 19.
728x90
반응형
SMALL

게시판 만들기(2) - 리스트 레이아웃 만들기

 

1. list.jsp만들기

(1) 만들어둔 template.jsp 복사하기

(2) 이름을 list.jsp로 변경

 

 

(3) card-body클래스 내에 content 내용에 테이블 생셩하여 변경

 

<%@ page language="java" contentType="text/html; charset=UTF-8" 
	pageEncodig="UTF-8"%>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.slim.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/js/bootstrap.bundle.min.js"></script>
</head>
<body>
 
<div class="container">
  <h2>Spring MVC01</h2>
  <div class="card">
    <div class="card-header">BOARD</div>
    <div class="card-body">
    	<table class = "table table-bordered table-hover">
    		<thead>
    			<th>번호</th>
    			<th>제목</th>
    			<th>작성자</th>
    			<th>작성일</th>
    			<th>조회수</th>
    		</thead>
    		<tbody>
    			<tr>
    				<td>1</td>
    				<td>스프링 게시판</td>
    				<td>관리자</td>
    				<td>2022-10-19</td>
    				<td>0</td>
    			</tr>
    		</tbody>
    	</table>
    </div> 
    <div class="card-footer">AI.BigData 취업역량강화_조정은</div>
  </div>
</div>

</body>
</html>

 

 

코드를 돌려도 실행이 안될거임 -> controller가 없기 때문

: JSP를 만들었으면 Controller를 만들어서 실행하게 도와달라해야함

 

 

 

 

 

2. Boardcontroller 생성

controller패키지 안에

 

(1) BoardController.class파일 만들기

 

 

 

(2) BoardController안에 메서드 만들기 

 

@ : annotation

-> 클래스 밖에 이 파일이 controller라고 @Controller 써서 선언해주기

@Controller

 

 

 

(3) 리스트 요청 ( list.do ) 을 처리하는 메서드 만들기

 - 데이터베이스에서 게시판 리스트를 가져옴( redirect, forward(jsp))

: board폴더에 있는 list를 가져온다는 뜻

 

- 메서드에 annotation걸어서 list.do로 매핑시킴

 

 

package kr.smhrd.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class BoardController { //POJO

	//메서드
	//리스트 요청(list.do)을 처리하는 메서드 만들기
	@RequestMapping("/list.do")
	public String list() {
		
		//데이터베이스에서 게시판 리스트를 가져오기
		return  "board/list"; //redirect, forward(JSP)
	}
	
	
}

 

 

실행 후 url이름을 list.do로 설정하면

 

 

 

잘 나옵니당

 

 

 

 

 

 

 

 

 


참고

 

 

 

 

 

 (1)w3schools.com에서 bootstrat basic template 클릭

 

https://www.w3schools.com/bootstrap4/bootstrap_templates.asp

 

Bootstrap 4 Templates

W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

www.w3schools.com

 

 

 

 

 

 

(2) try it yourself클릭

 

 

 

728x90
반응형
LIST