1. Sourcetree와 github를 이용하여 소스 관리하는 방법
· 협업하는 경우 형상관리(소스관리)툴인 CVS, SVN, github를 사용하여 소스 관리를 하도록 한다.
1)github 본인 계정에서 new repository 생성, name은 이클립스에서 사용하는 프로젝트명과 되도록이면 동일하게 작성
2)프로젝트 폴더에 .gitignore 문서 추가할 것(필요없는 문서를 올라가지 않게 하는 역할, 반드시 처음부터 넣어야함!!!)
3)해당 프로젝트 오른쪽 클릭 → Team → Share project → 아래와 같이 Repository를 설정하면 해당 폴더에는 git 폴더가 생성됨
4)연동이 성공되면 사진과 같이 타원형으로 표시되고, 해당 프로젝트 오른쪽 클릭 → Team → Commit 선택
Unstaged Changes에서 + 클릭하여 Commit하려는 파일을 Staged Changes로 이동 (stage는 중간에 복사한다는 의미로 사용)
5)소스트리에서 Add an account → URL은 github로 지정하여 계정 추가 후 add 클릭
6)해당 프로젝트의 git 폴더 경로를 지정하고 add → history → commit/push 과정을 거치면 github에 해당 소스가 저장된다.
(브랜치: 깃허브/서버기준은 orginmaster, 내 기준은 master)
7)github에 저장된 spring_board_5_test 소스코드!!
※연습문제※
· 스프링부트를 통해 게시판을 완성하고, 깃허브와 소스트리에 댓글관련 branch를 별도로 저장하여 master에 Merge하시오.
(단, page 등 게시판 모두 부트스트랩 적용할 것!)
<application.properties>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#server port number
server.port = 8282
#datasource (oracle)
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/xe
spring.datasource.username=scott
spring.datasource.password=tiger
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsp
spring.thymeleaf.view-names=thymeleaf/*
mybatis.mapper-locations=classpath:mappers/**/*.xml
|
cs |
<BoardController.java>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
@Slf4j
@Controller
public class BoardController {
@Autowired
private BoardService boardService;
@GetMapping("/list")
public String list(Criteria cri, Model model) {
log.info("list");
model.addAttribute("list", boardService.getList(cri));
int total = boardService.totalCount(cri);
log.info("page");
PageVO pageVO = new PageVO(cri, total);
model.addAttribute("page", pageVO);
return "list";
}
@GetMapping("/content_view")
public String content_view(BoardVO boardVO, Model model) {
log.info("content_view");
model.addAttribute("content_view", boardService.content(boardVO.getbId()));
return "content_view";
}
@GetMapping("/write_view")
public String write_view() {
log.info("write_view");
return "write_view";
}
@PostMapping("/write")
public String write(BoardVO boardVO, Model model) {
log.info("write");
boardService.write(boardVO);
return "redirect:list";
}
@PostMapping("/modify")
public String modify(BoardVO boardVO) {
log.info("modify");
boardService.modify(boardVO);
return "redirect:list";
}
@GetMapping("/delete")
public String delete(BoardVO boardVO) {
log.info("delete");
boardService.delete(boardVO.getbId());
return "redirect:list";
}
@GetMapping("/reply_view")
public String replyview(BoardVO boardVO, Model model) {
log.info("delete");
model.addAttribute("reply_view", boardService.replyView(boardVO.getbId()));
return "reply_view";
}
@PostMapping("/reply")
public String reply(BoardVO boardVO) {
log.info("reply");
boardService.reply(boardVO);
return "redirect:list";
}
}
|
cs |
<SpringBootBoardListApplication.java>MapperScan을 통해 mapper의 위치 선언
1
2
3
4
5
6
7
8
|
@SpringBootApplication
@MapperScan(basePackages = {"edu.bit.ex.mapper"})
public class SpringBootBoardListApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootBoardListApplication.class, args);
}
}
|
cs |
<BoardVO.java>
1
2
3
4
5
6
7
8
9
10
11
12
|
@Data
public class BoardVO {
private int bId;
private String bName;
private String bTitle;
private String bContent;
private String bDae;
private int bHit;
private int bGroup;
private int bStep;
private int bIndent;
}
|
cs |
<Criteria.java>
1
2
3
4
5
6
7
8
9
10
11
12
13
|
@Data
public class Criteria {
private int pageNum;
private int amount;
public Criteria() {
this(1, 5);
}
public Criteria(int pageNum, int amount) {
this.pageNum = pageNum;
this.amount = amount;
}
}
|
cs |
<PageVO.java>
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
32
|
@Data
public class PageVO {
private Criteria cri;
private int startPage;
private int endPage;
private boolean prev, next;
private int total;
public PageVO(Criteria cri, int total) {
this.cri = cri;
this.total = total;
this.endPage = (int)(Math.ceil(cri.getPageNum()/10.0)) * 10;
this.startPage = this.endPage - 9;
int realPage = (int)(Math.ceil((total*1.0)/cri.getAmount()));
if(realPage<=this.endPage) {
this.endPage = realPage;
}
this.prev = this.startPage > 1;
this.next = this.endPage < realPage;
}
public String makeQuery(int page) {
UriComponents uriComponentsBuilder = UriComponentsBuilder.newInstance().queryParam("pageNum", page)
.queryParam("amount", cri.getAmount())
.build();
return uriComponentsBuilder.toUriString();
}
}
|
cs |
<BoardService.java>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
public interface BoardService {
public List<BoardVO> getList(Criteria cri);
public int totalCount(Criteria cri);
public BoardVO content(int getbId);
public void write(BoardVO boardVO);
public void modify(BoardVO boardVO);
public void delete(int getbId);
public BoardVO replyView(int getbId);
public void reply(BoardVO boardVO);
}
|
cs |
<BoardServiceImpl.java>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
@Slf4j
@Service
public class BoardServiceImpl implements BoardService{
@Autowired
private BoardMapper mapper;
@Override
public List<BoardVO> getList(Criteria cri){
log.info("list");
return mapper.getList(cri);
}
@Override
public int totalCount(Criteria cri) {
log.info("count");
return mapper.totalCount(cri);
}
@Override
public BoardVO content(int getbId) {
log.info("content");
mapper.hit(getbId);
return mapper.content(getbId);
}
@Override
public void write(BoardVO boardVO) {
log.info("write");
mapper.write(boardVO);
}
@Override
public void modify(BoardVO boardVO) {
log.info("modify");
mapper.modify(boardVO);
}
@Override
public void delete(int getbId) {
log.info("delete");
mapper.delete(getbId);
}
@Override
public BoardVO replyView(int getbId) {
log.info("replyView");
return mapper.replyView(getbId);
}
@Override
public void reply(BoardVO boardVO) {
log.info("reply");
mapper.reply(boardVO);
mapper.replyShape(boardVO);
}
}
|
cs |
<BoardMapper.java>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
@Mapper
public interface BoardMapper {
public List<BoardVO> getList(Criteria cri);
public int totalCount(Criteria cri);
public BoardVO content(int getbId);
public void hit(int getbId);
public void write(BoardVO boardVO);
public void modify(BoardVO boardVO);
public void delete(int getbId);
public BoardVO replyView(int getbId);
public void reply(BoardVO boardVO);
public void replyShape(BoardVO boardVO);
}
|
cs |
<BoardMapper.xml>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<mapper namespace="edu.bit.ex.mapper.BoardMapper">
<select id="getList" resultType="edu.bit.ex.vo.BoardVO">
<![CDATA[
select * from(
select rownum as rn, A.* from (
select * from mvc_board order by bGroup desc, bStep asc
) A where rownum <= #{pageNum} * #{amount}
) where rn > (#{pageNum}-1) * #{amount}
]]>
</select>
<select id="totalCount" resultType="int">
<![CDATA[
select count(*) from mvc_board
]]>
</select>
<select id="content" resultType="edu.bit.ex.vo.BoardVO">
<![CDATA[
select * from mvc_board where bId=#{bId}
]]>
</select>
<select id="hit">
<![CDATA[
update mvc_board set bHit=bHit+1 where bId=#{bId}
]]>
</select>
<select id="write">
<![CDATA[
insert into mvc_board(bId, bName, bTitle, bContent, bHit, bGroup, bStep, bIndent)
values(mvc_board_seq.nextval, #{bName}, #{bTitle}, #{bContent}, 0, mvc_board_seq.currval, 0, 0)
]]>
</select>
<select id="delete">
<![CDATA[
delete from mvc_board where bId=#{bId}
]]>
</select>
<select id="modify">
<![CDATA[
update mvc_board set bName=#{bName}, bTitle=#{bTitle}, bContent=#{bContent} where bId=#{bId}
]]>
</select>
<select id="replyView" resultType="edu.bit.ex.vo.BoardVO">
<![CDATA[
select * from mvc_board where bId=#{bId}
]]>
</select>
<select id="reply">
<![CDATA[
insert into mvc_board(bId, bName, bTitle, bContent, bHit, bGroup, bStep, bIndent)
values(mvc_board_seq.nextval, #{bName}, #{bTitle}, #{bContent}, #{bHit}, #{bGroup}, #{bStep}+1, #{bIndent}+1)
]]>
</select>
<select id="replyShape">
<![CDATA[
update mvc_board set bStep=#{bStep}+1 where bGroup=#{bGroup} and bStep > #{bStep}
]]>
</select>
</mapper>
|
cs |
<list.jsp>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<style>
ul{
margin-left: 230px;
}
h2{
margin-bottom: 20px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>MVC_BOARD</h2>
<table class="table table-bordered" >
<thead>
<tr>
<th>번호</th>
<th>이름</th>
<th>제목</th>
<th>날짜</th>
<th>조회수</th>
</tr>
</thead>
<c:forEach items="${list}" var="dto">
<tbody>
<tr>
<td>${dto.bId}</td>
<td>${dto.bName}</td>
<td><c:forEach begin="1" end="${dto.bIndent}">-[RE]</c:forEach>
<a href="content_view?bId=${dto.bId}">${dto.bTitle}</a></td>
<td>${dto.bDae}</td>
<td>${dto.bHit}</td>
</tr>
</tbody>
</c:forEach>
</table>
<button type="button" class="btn btn-info" onclick="location.href='write_view'">글작성</button>
<ul id="ul" class="pagination">
<c:if test="${page.prev}">
<li class="page-item"><a class="page-link" href="list${page.makeQuery(page.startPage - 1)}">Prev</a></li>
</c:if>
<c:forEach begin="${page.startPage}" end="${page.endPage}" var="idx">
<li class="page-item "><a class="page-link" href="list${page.makeQuery(idx)}">${idx}</a></li>
</c:forEach>
<c:if test="${page.next && page.endPage > 0}">
<li class="page-item"><a class="page-link" href="list${page.makeQuery(page.endPage +1) }">Next</a></li>
</c:if>
</ul>
</div>
</body>
</html>
|
cs |
<content_view.jsp>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body >
<form action="modify" method="post">
<div class="container mt-3" >
<div class="row" >
<div class="col-sm-7">
<input type="hidden" name="bId" value="${content_view.bId}">
<table class="table">
<thead>
<tr class="table-light">
<th colspan="3"><h5 class="text-center text-dark"><게시판 조회></h5></th>
</tr>
</thead>
<tbody>
<tr>
<td>번호</td>
<td colspan="3">${content_view.bId}</td>
</tr>
<tr>
<td>히트</td>
<td>${content_view.bHit}</td>
</tr>
<tr>
<td>이름</td>
<td><input type="text" class="form-control" name="bName" value="${content_view.bName}"></td>
</tr>
<tr>
<td>제목</td>
<td><input type="text" class="form-control" name="bTitle" value="${content_view.bTitle}"></td>
</tr>
<tr>
<td>내용</td>
<td><textarea rows="5" class="form-control" name="bContent">${content_view.bContent}</textarea></td>
</tr>
<tr><td class="text-center" colspan="3">
<button type="submit" class="btn btn-outline-info" > 수정 </button>
<button type="button" class="btn btn-outline-success" onclick="location.href='list'"> 목록 </button>
<button type="button" class="btn btn-outline-danger" onclick="location.href='delete?bId=${content_view.bId}'"> 삭제 </button>
<button type="button" class="btn btn-outline-info" onclick="location.href='reply_view?bId=${content_view.bId}'"> 답변 </button>
</tbody>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
|
cs |
<write_view.jsp>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body >
<form action="write" method="post">
<div class="container mt-3" >
<div class="row" >
<div class="col-sm-7">
<table class="table">
<thead>
<tr class="table-light">
<th colspan="3"><h5 class="text-center text-dark"><게시글 작성></h5></th>
</tr>
</thead>
<tbody>
<tr>
<td>이름</td>
<td><input type="text" class="form-control" name="bName" value="${write_view.bName}"></td>
</tr>
<tr>
<td>제목</td>
<td><input type="text" class="form-control" name="bTitle" value="${write_view.bTitle}"></td>
</tr>
<tr>
<td>내용</td>
<td><textarea rows="5" class="form-control" name="bContent">${write_view.bContent}</textarea></td>
</tr>
<tr><td class="text-center" colspan="3">
<button type="submit" class="btn btn-outline-info" > 입력 </button>
<button type="button" class="btn btn-outline-success" onclick="location.href='list'"> 목록 </button>
</tbody>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
|
cs |
<reply_view.jsp>
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</head>
<body >
<form action="reply" method="post">
<div class="container mt-3" >
<div class="row" >
<div class="col-sm-7">
<input type="hidden" name="bId" value="${reply_view.bId}">
<input type="hidden" name="bGroup" value="${reply_view.bGroup}">
<input type="hidden" name="bStep" value="${reply_view.bStep}">
<input type="hidden" name="bIndent" value="${reply_view.bIndent}">
<table class="table">
<thead>
<tr class="table-light">
<th colspan="3"><h5 class="text-center text-dark"><답변 작성></h5></th>
</tr>
</thead>
<tbody>
<tr>
<td>번호</td>
<td colspan="3">${reply_view.bId}</td>
</tr>
<tr>
<td>히트</td>
<td>${reply_view.bHit}</td>
</tr>
<tr>
<td>이름</td>
<td><input type="text" class="form-control" name="bName" value="${reply_view.bName}"></td>
</tr>
<tr>
<td>제목</td>
<td><input type="text" class="form-control" name="bTitle" value="${reply_view.bTitle}"></td>
</tr>
<tr>
<td>내용</td>
<td><textarea rows="5" class="form-control" name="bContent"></textarea></td>
</tr>
<tr><td class="text-center" colspan="3">
<button type="submit" class="btn btn-outline-info" > 답변 </button>
<button type="button" class="btn btn-outline-success" onclick="location.href='list'"> 목록 </button>
</tbody>
</table>
</div>
</div>
</div>
</form>
</body>
</html>
|
cs |
<출력 화면>
<Github 화면>
<Sourcetree 화면>