Notice
Recent Posts
Recent Comments
Link
«   2026/03   »
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
more
Archives
Today
Total
관리 메뉴

ALLYES

[2022년 청년친화형 기업 ESG지원 사업 - 33] 본문

ESG

[2022년 청년친화형 기업 ESG지원 사업 - 33]

Allyes_99 2022. 10. 19. 17:50

일시 : 2022.10.19

시간 : 9:00 ~ 18:00


오전/오후 : spring


Spring

 

Maven Dependencies

Maven : 자바용 프로젝트 관리 도구

api들이 들어있음

 

짝수 버전을 쓰는것이 좋음 - 안정화가 되어있음

pom.xml - 4.3.18 (스프링 버전 바꿔주면 알아서 다운로드가 됨)


위와 마찬가지로 Java버전을 바꿔줌 : 1.6 -> 1.8

그 후 Maven update를 통해 적용해줌



w3school 홈페이지 이용

https://www.w3schools.com/

 

W3Schools Free Online Web Tutorials

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

 

<%@page import="kr.smhrd.entity.Board"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	List<Board> list = (List<Board>)request.getAttribute("list");
%>
<!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">Content</div> 
    <table class ="table table-bordered table-hover">
    	<thead>
    		<th>번호</th>
    		<th>제목</th>
    		<th>작성자</th>
    		<th>작성일</th>
    		<th>조회수</th>	
    	</thead>
    	<tbody>
    	<% for( Board vo : list)  {%>
    		<tr>
    			<td><%=vo.getIdx() %></td>
    			<td><%=vo.getTitle() %></td>
    			<td><%=vo.getWriter() %></td>
    			<td><%=vo.getIndate() %></td>
    			<td><%=vo.getCount() %></td>
    		</tr>
    		<%} %>
    	</tbody> 
    </table>
    <div class="card-footer">AI.BigData 취업역량강화_A</div>
  </div>
</div>

</body>
</html>
package kr.smhrd.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

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

import kr.smhrd.entity.Board;

@Controller
public class BoardController {	// POJO
	// 메서드
	// 리스트요청(list.do)을 처리하는 메서드
	@RequestMapping("/list.do")	// mapping 처리
	public String list(Model model) {
		
		// 데이터베이스에서 게시판 리스트를 가져오기
		List<Board> list = new ArrayList<Board>();
		Board b = new Board();
		b.setIdx(1L);	// Long 형 인 경우 L을 붙여줘야함
		b.setTitle("스프링게시판");
		b.setWriter("관리자");
		b.setIndate(new Date());
		b.setCount(0L);
		list.add(b);
		list.add(b);
		list.add(b);
		// 객체바인딩(HttpServletRequest, HttpSession)
		model.addAttribute("list", list);	// list(번지) --> ArrayList
		
		return "boards/list"; // redirect, forward(JSP)
	}
}
package kr.smhrd.entity;

import java.util.Date;

// 게시판(Object) -> 번호, 제목, 내용, 작성자, 작성일, 조회수
public class Board {
	private Long idx;
	private String title;
	private String content;
	private String writer;
	private Date indate;	// Date -> String
	private Long count;

	// getter & setter
	public Long getIdx() {
		return idx;
	}
	public void setIdx(Long idx) {
		this.idx = idx;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getWriter() {
		return writer;
	}
	public void setWriter(String writer) {
		this.writer = writer;
	}
	public Date getIndate() {
		return indate;
	}
	public void setIndate(Date indate) {
		this.indate = indate;
	}
	public Long getCount() {
		return count;
	}
	public void setCount(Long count) {
		this.count = count;
	}
	
	// toString()
	@Override
	public String toString() {
		return "Board [idx=" + idx + ", title=" + title + ", content=" + content + ", writer=" + writer + ", indate="
				+ indate + ", count=" + count + "]";
	}		
	
	
}

MVC 패턴


MyBatis : 객체 지향 언어인 자바의 관계형 데이터베이스 프로그래밍을 좀 더 쉽게 할 수 있게 도와 주는 개발 프레임 워크


Spring DataBase 연결 구조