면접을 보는데 탄탄한 기본이 되있어야지 기술면접때 잘할 수 있을것같다

알고와 이것이 자바다 도전!

 

1. 색칠 재귀

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
package 색칠재귀;
 
public class TaewonClass {
    
    
    public static void main(String[] args) {
        //0를 모두 2로 색칠하세요
        int[][] arr = {
                {0,0,0,0,0},
                {0,0,1,1,0},
                {0,0,0,0,1},
                {0,0,0,0,0},
                {0,0,1,0,0}};
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr.length; j++) {
                if(arr[i][j] == 0) arr[i][j] = 2
            }
        }
 
        for(int i = 0; i < arr.length; i++) {
            for(int j = 0; j < arr.length; j++) {
                System.out.print(arr[i][j]);
            }
            System.out.println();
        }
        
        //재귀호출을 안하고 이렇게 출력을 했는데 알고리즘은 재귀호출을 원했다..
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
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
package 색칠재귀;
 
public class MainClass {
 
    static final int SIZE = 5;
    static final int COLOR = 2;
    static int count = 0;
    static int[][] map = {
            {0,0,0,0,0},
            {0,0,1,1,0},
            {0,0,0,0,1},
            {0,0,0,0,0},
            {0,0,1,0,0}};
    
    public static void color(int x, int y) {
        count++;
        if(map[x][y] != 1)map[x][y] = COLOR;
        
        //위로 2와 그리고 1 이 아닌것을 검색
        if(x - 1 >= 0 && map[x - 1][y] != COLOR && map[x -1][y] != 1) {
            System.out.println(count + " turn result is === " + (x-1+ "  " + y );
            color(x-1, y);
        }
        
        //밑으로 2와 그리고 1이 아닌것을 검색
        if(x + 1 <= SIZE-1 && map[x + 1][y] != COLOR && map[x + 1][y] != 1) {
            System.out.println(count + " turn result is === " + (x+1+ "  " + y );
            color(x+1, y);
        }
        
        //오른쪽으로 2와 그리고 1이 아닌것을 검색
        if(y + 1 <= SIZE-1 && map[x][y+1!= COLOR && map[x][y +1!= 1) {
            System.out.println(count + " turn result is === " + (x) + "  " + (y+1) );
            color(x, y +1);
        }
        
        //왼쪽으로 2와 그리고 1이 아닌것을 검색
        if(y -1 >= 0 && map[x][y - 1!= COLOR && map[x][y - 1!= 1) {
            System.out.println(count + " turn result is === " + (x) + "  " + (y-1) );
            color(x, y - 1);
        }
        
        //여기서 포인트는 방향별 if문과 if문안에있는 재귀호출 메소드 color이다. 
        //재귀호출이 어떻게 도는지 궁굼해서 출력도 해놨으니 참고하면 좋을것 같다!
        
    }
    
    public static void main(String[] args) {
        for(int i = 0; i < SIZE; i ++) {
            for(int j = 0; j < SIZE; j ++) {
                System.out.print(map[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
        System.out.println();
        
        color(2,2);
        
        for(int i = 0; i < SIZE; i ++) {
            for(int j = 0; j < SIZE; j ++) {
                System.out.print(map[i][j] + " ");
            }
            System.out.println();
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

두번째 코드의 결과물, 재귀호출이 어떻게 도는지 볼 수 있다

2. 숫자추출재귀'

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
package 숫자추출재귀;
 
import java.util.Scanner;
 
public class TaewonMain {
    
    public static void numberz(int n) {
 
        if(n/10 == 0) {
            System.out.println(n);
            return;
        }
        
        numberz(n/10); //numberz(123) numberz(12) numberz(1)
        System.out.println(n%10);
        //여기서 앞숫자를 먼저 프린트하기 위해서 재귀를 쓴다
        //만약 뒷숫자를 먼저 출력면 단순히 % 10 한 값을 출력후 /10한 값을 저장 후 반복
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        
        numberz(input);
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 
 

3. 이진수재귀

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package 이진수재귀;
 
import java.util.Scanner;
 
public class TaewonMain {
 
    public static void binary(int input) {
        if(input/2==0) {
            System.out.print(input);
            return;
        }
        binary(input/2);
        System.out.print(input%2);
        //똑같은 방식, 간단간단, 마지막 숫자가 0일때까지 실행
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int input = scan.nextInt();
        binary(input);
        
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

4. 피보나치수재귀

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package 피보나치수재귀;
 
import java.util.Scanner;
 
public class TaewonMain {
    
    public static int pibo(int n) {
        System.out.println("this is : " + n);
        if(n ==1return 1;
        if(n ==2return 1;
        
        return pibo(n - 1+ pibo(n - 2);
        //첫번째 그리고 두번째 수는 1이니까 앞에 조건문으로 잡아주고 시작
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        
        int ans = pibo(n);
        
        System.out.println(ans);
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

5. 단지수출력재귀

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
package 단지수출력재귀;
 
public class MainClass {
    static final int SIZE = 5;
    static final int APART = 1;
    
    static int apratCnt = 0;
    static int[] houseHold = new int[10];
    
    static int[][] arr = 
        {{0,0,0,1,1},
        {0,0,0,0,1},
        {1,0,0,0,0},
        {1,1,0,0,0},
        {1,1,0,1,1}};
    
    public static void doFunc(int y, int x, int apartIndex) {
        //change color to 0
        arr[y][x] = 0;
        houseHold[apartIndex]++;
        
        if(x - 1 >= 0 && arr[y][x-1== APART) doFunc(y, x-1, apartIndex);
        if(x + 1 < SIZE && arr[y][x+1== APART) doFunc(y, x+1, apartIndex);
        if(y + 1 < SIZE && arr[y+1][x] == APART) doFunc(y+1, x, apartIndex);
        if(y - 1 >= 0 && arr[y-1][x] == APART) doFunc(y-1, x, apartIndex);
    }
    
    public static void main(String[] args) {
        for(int i = 0; i < SIZE; i++) {
            for(int j = 0; j < SIZE; j ++) {
                if(arr[i][j] == 1) {
                    doFunc(i, j , apratCnt);
                    apratCnt++;
                }
            }
        }
        System.out.println(apratCnt);
        for(int i : houseHold) {
            if(i != 0)
            System.out.print(i + " ");
        }
    }
    //이 재귀는 조금 난이도가 있었던 것 같다 
    //풀이된 답을 보면 이해는 하나 당시 풀때는 멘붕
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

1. board

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
CREATE TABLE `board` (
  `boardId` int(11NOT NULL AUTO_INCREMENT,
  `bUsername` varchar(10DEFAULT NULL,
  `bTitle` varchar(20DEFAULT NULL,
  `bContent` varchar(200DEFAULT NULL,
  `bDate` timestamp NULL DEFAULT NULL,
  `bHit` int(11DEFAULT NULL,
  `bGroup` int(11DEFAULT NULL,
  `bIndent` int(11DEFAULT NULL,
  `bStep` int(11DEFAULT NULL,
  PRIMARY KEY (`boardId`),
  KEY `board_ibfk_1` (`bUsername`),
  CONSTRAINT `board_ibfk_1` FOREIGN KEY (`bUsername`REFERENCES `boardmember` (`username`ON DELETE CASCADE ON UPDATE CASCADE
ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. boardmember

1
2
3
4
5
6
7
8
9
10
11
12
CREATE TABLE `boardmember` (
  `memberId` int(11unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(10DEFAULT NULL,
  `password` varchar(10DEFAULT NULL,
  `email` varchar(20DEFAULT NULL,
  `gender` varchar(2DEFAULT NULL,
  `joindate` datetime DEFAULT CURRENT_TIMESTAMP,
  `birthday` datetime DEFAULT NULL,
  PRIMARY KEY (`memberId`),
  UNIQUE KEY `username` (`username`)
ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
CREATE TABLE `comment` (
  `commentId` int(11NOT NULL AUTO_INCREMENT,
  `boardId` int(11DEFAULT NULL,
  `username` varchar(10DEFAULT NULL,
  `content` varchar(100DEFAULT NULL,
  `cLike` int(11DEFAULT NULL,
  `cGroup` int(11DEFAULT NULL,
  `cIndent` int(11DEFAULT NULL,
  `cStep` int(11DEFAULT NULL,
  `cDate` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`commentId`),
  KEY `username` (`username`),
  KEY `comment_ibfk_1` (`boardId`),
  CONSTRAINT `comment_ibfk_1` FOREIGN KEY (`boardId`REFERENCES `board` (`boardId`ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `comment_ibfk_2` FOREIGN KEY (`username`REFERENCES `boardmember` (`username`)
ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Algorithm time complexity  (2) 2019.12.01
자바 메모리 구조  (0) 2019.11.23
Various html  (0) 2019.11.14
Settings  (0) 2019.11.14
Controller  (1) 2019.11.14

1. home

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
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
</head>
<body>
<h1>
    Hello world!  
</h1>
${success }<br>
${session }
<P>  The time on the server is ${serverTime}. </P>
<c:choose>
    <c:when test="${session == null}">
        <a href="toLogin">login</a> &nbsp;&nbsp;&nbsp;
        <a href="toRegister">register</a> &nbsp;&nbsp;&nbsp;
    </c:when>
    <c:otherwise>
        <a href="logout">Logout</a> &nbsp;&nbsp;&nbsp;
        <a href="toRegister">register</a> &nbsp;&nbsp;&nbsp;
    </c:otherwise>
</c:choose>
<a href="boardList">게시판</a>&nbsp;&nbsp;&nbsp;
<form action="search">
    <span>검색 : </span><input type="text" name="search">&nbsp;&nbsp;
    <select name="type">
        <option value="btitle" selected="selected">title</option>
        <option value="bContent" >content</option>
    </select>
    <input type="submit" value="검색">
</form>
 
</body>
</html>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. member

a. login

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
${fail }
<form action="loginCheck" method="post">
    <div class="container">
        <label for="username"><b>Username</b></label>
        <input type="text" placeholder="Enter Username" name="username" required><br>
    
        <label for="password"><b>Password</b></label>
        <input type="password" placeholder="Enter Password" name="password" required><br>
        
        <button type="submit">Login</button>
        <input type="checkbox" name="remember">Remember me
    </div>
    <div class="container">
        <button type="button" class="cancelbtn">Cancel</button>
        <span class="psw"><a href="findPassword">Forgot password?</a></span>
    </div>
</form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. register

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="register" method="post">
    <div class="container">
        <label name="username"><b>Username</b></label>
        <input type="text" name="username"><br>
        
        <label name="password"><b>Password</b></label>
        <input type="password" name="password"><br>
        
        <label name="passwordCheck"><b>Password check</b></label>
        <input type="password" name="passwordCheck"><br>
        
        <label name="gender"><b>Select gender</b></label>
        <input type="radio" name="gender" value="m">M
        <input type="radio" name="gender" value="f">F<br>
        
        <label name="email"><b>Email</b></label>
        <input type="text" name="email"><br>
        
        <label name="birthday"><b>Birthday</b></label>
        <input type="date" name="birthday"><br>
        <input type="submit" value="JOIN">
    </div>
    <div class="container">
        <a href="findPassword">Forgot Password?</a>
    </div>
    
 
</form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

c. edit

d. findpassword

 

3. board

a. boardList

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
76
77
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
//이전 버튼 이벤트
function fn_prev(page, range, rangeSize) {
        var page = ((range - 2* rangeSize) + 1;
        var range = range - 1;
        var url = "boardList";
        url = url + "?page=" + page;
        url = url + "&range=" + range;
        location.href = url;
    }
 
  //페이지 번호 클릭
    function fn_pagination(page, range, rangeSize, searchType, keyword) {
        var url = "boardList";
        url = url + "?page=" + page;
        url = url + "&range=" + range;
        location.href = url;    
    }
 
    //다음 버튼 이벤트
    function fn_next(page, range, rangeSize) {
        var page = parseInt((range * rangeSize)) + 1;
        var range = parseInt(range) + 1;
        var url = "boardList";
        url = url + "?page=" + page;
        url = url + "&range=" + range;
        location.href = url;
    }
</script>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="../home.jsp" %>
<table border="1">
    <tr>
        <th>No.</th>
        <th>Title</th>
        <th>Writer</th>
        <th>Date</th>
        <th>Hit</th>
    </tr>
    <c:forEach var="board" items="${board}">
    <tr>
        <td>${board.boardId }</td>
        <td><a href="boardView?boardId=${board.boardId }">
        <c:forEach begin="1" end="${board.BIndent }">-</c:forEach>${board.BTitle }</a></td>
        <td>${board.BUsername }</td>
        <td>${board.BDate }</td>
        <td>${board.BHit }</td>
    </tr>
    </c:forEach>
</table>
<c:if test="${session != null }">
    <a href="boardWrite">글 쓰기</a>&nbsp;&nbsp;&nbsp;
</c:if>
<div id="paginationBox">
        <ul class="pagination">
            <c:if test="${pagination.prev}">
                <li class="page-item"><a class="page-link" href="#" onClick="fn_prev('${pagination.page}', '${pagination.range}', '${pagination.rangeSize}')">Previous</a></li>
            </c:if>
            <c:forEach begin="${pagination.startPage}" end="${pagination.endPage}" var="idx">
                <li class="page-item <c:out value="${pagination.page == idx ? 'active' : ''}"/> "><a class="page-link" href="#" onClick="fn_pagination('${idx}', '${pagination.range}', '${pagination.rangeSize}')"> ${idx} </a></li>
            </c:forEach>
            <c:if test="${pagination.next}">
                <li class="page-item"><a class="page-link" href="#" onClick="fn_next('${pagination.range}', '${pagination.range}', '${pagination.rangeSize}')" >Next</a></li>
            </c:if>
        </ul>
    </div>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. boardVieww

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
76
77
78
79
80
81
82
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <%@include file="../home.jsp"%>
    
    <c:if test="${board.BUsername == session.username}">
        <form action="toBoardEdit" method="post">
            <input type="hidden" value="${board.boardId }" name="boardId">
            <input type="submit" value="edit">
        </form>
        <form action="boardDelete" method="post">
            <input type="hidden" value="${board.boardId }" name="boardId">
            <input type="submit" value="delete">
        </form>
    </c:if>
    <c:if test="${session != null }">
        <form action="toBoardReply" method="post">
            <input type="hidden" value="${board.BGroup }" name="BGroup">
            <input type="hidden" value="${board.BStep }" name="BStep">
            <input type="hidden" value="${board.BIndent }" name="BIndent">
            <input type="submit" value="reply to post">
        </form>
    </c:if>
    
    <table border="1">
        <tr>
            <td>이름</td>
            <td>${board.BUsername}</td>
        </tr>
        <tr>
            <td>Title</td>
            <td>${board.BTitle}</td>
        </tr>
        <tr>
            <td>조회수</td>
            <td>${board.BHit }</td>
        </tr>
        <tr>
            <td>Time</td>
            <td>${board.BDate }</td>
        </tr>
        <tr>
            <td>Content</td>
            <td>${board.BContent }</td>
        </tr>
    </table>
    <table border="1">
        <c:forEach var="comment" items="${comment }">
        <tr>
            <td><span>${comment.username }</span></td>
            <td><span>${comment.content }</span></td>
            <td>
                <c:if test="${comment.username == session.username }">
                    <form action="deleteComment" method="post">
                        <input type="hidden" name="boardId" value="${comment.boardId }">
                        <input type="hidden" name="commentId" value="${comment.commentId }">
                        <input type="submit" value="delete comment">
                    </form>
                </c:if>
            </td>
        </tr>
        </c:forEach>
    </table>
    <form action="postComment" method="post">
        <input type="hidden" name="boardId" value="${board.boardId }">
        <input type="hidden" name="username" value="${session.username }">
        <textarea rows="5" cols="100" name="content"></textarea><br>
        <c:if test="${session.username != null }">
            <input type="submit" value="comment submit">
        </c:if>
    </form>
 
 
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

c. boardWrite

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="boardInsert" method="post">
    <input type="hidden" name="bUsername" value="${session.username }">
        <table border="1">
            <tr>
                <td>이름</td>
                <td>${session.username }</td>
            </tr>
            <tr>
                <td>Title</td>
                <td><input type="text" name="bTitle"></td>
            </tr>
            <tr>
                <td>Content</td>
                <td><textarea name="bContent" rows="30" cols="100"></textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                <input type="submit" value="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

d. boardEdit

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="boardEdit" method="post">
    <input type="hidden" name="boardId" value="${board.boardId}">
        <table border="1">
            <tr>
                <td>이름</td>
                <td>${board.BUsername }</td>
            </tr>
            <tr>
                <td>Title</td>
                <td><input type="text" name="bTitle" value="${board.BTitle }"></td>
            </tr>
            <tr>
                <td>Content</td>
                <td><textarea name="bContent" rows="30" cols="100">${board.BContent }</textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                <input type="submit" value="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

e. boardReply

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="boardReply" method="post">
        <input type="hidden" value="${board.BGroup }" name="BGroup">
        <input type="hidden" value="${board.BStep }" name="BStep">
        <input type="hidden" value="${board.BIndent }" name="BIndent">
        <input type="hidden" name="bUsername" value="${session.username }">
        <table border="1">
            <tr>
                <td>이름</td>
                <td>${session.username }</td>
            </tr>
            <tr>
                <td>Title</td>
                <td><input type="text" name="bTitle"></td>
            </tr>
            <tr>
                <td>Content</td>
                <td><textarea name="bContent" rows="30" cols="100"></textarea></td>
            </tr>
            <tr>
                <td colspan="2">
                <input type="submit" value="submit">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

4. search

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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%@include file="../home.jsp" %>
${result }
<table border="1">
    <tr>
        <th>No.</th>
        <th>Title</th>
        <th>Writer</th>
        <th>Date</th>
        <th>Hit</th>
    </tr>
    <c:forEach var="board" items="${result}">
    <tr>
        <td>${board.boardId }</td>
        <td><a href="boardView?boardId=${board.boardId }">
        <c:forEach begin="1" end="${board.BIndent }">-</c:forEach>${board.BTitle }</a></td>
        <td>${board.BUsername }</td>
        <td>${board.BDate }</td>
        <td>${board.BHit }</td>
    </tr>
    </c:forEach>
</table>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

'ETC' 카테고리의 다른 글

자바 메모리 구조  (0) 2019.11.23
various query  (0) 2019.11.14
Settings  (0) 2019.11.14
Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14

1. datasource.properties for easier database access

1
2
3
4
5
dbname=mysql
url=jdbc:mysql://localhost:3306/november11board?serverTimezone=UTC
id=****
pw=****
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. root-context.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
<?xml version="1.0" encoding="UTF-8"?>
    
    <!-- Root Context: defines shared resources visible to all other web components -->
    <context:property-placeholder
        location="classpath:/mybatis/config/datasource.properties" />
    <context:annotation-config />
    <bean id="dataSource"
        <property name="driverClassName" value="${driver}" />
        <property name="url" value="${url}" />
        <property name="username" value="${id}" />
        <property name="password" value="${pw}" />
    </bean>
    <bean id="sqlSessionFactoryBean"
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations"
            value="classpath:/mybatis/mappers/*Mapper.xml" />
        <property name="typeAliasesPackage"
            value="com.test.taewon.model.dto" />
    </bean>
    <bean id="sqlSession"
        class="org.mybatis.spring.SqlSessionTemplate">
        <constructor-arg index="0" ref="sqlSessionFactoryBean"></constructor-arg>
    </bean>
    <bean id="TransactionManager"
        <property name="dataSource" ref="dataSource"></property>
    </bean>
        <property name="basePackage" value="com.test.taewon.model.dao"></property>
    </bean>
</beans>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. web.xml added filtering for language

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
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 
    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>   
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>  
            <param-value>true</param-value>
        </init-param>
    </filter>    
 
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>                 
    </filter-mapping>
    
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
        
    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    
    
 
</web-app>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

4. pom.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?xml version="1.0" encoding="UTF-8"?>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.test</groupId>
    <artifactId>taewon</artifactId>
    <name>november9</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.1.1.RELEASE
        </org.springframework-version>
        <org.aspectj-version>1.6.10</org.aspectj-version>
        <org.slf4j-version>1.6.6</org.slf4j-version>
    </properties>
 
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework-version}</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
 
        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>
 
        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${org.slf4j-version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>
 
        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
 
        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
 
        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>
        <!-- JDBC Oracle -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
 
 
        <!-- Has Simple JDBCTemplate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
 
 
        <!-- ORM MyBatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.0</version>
        </dependency>
        <!-- Spring MyBatis lib -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
 
        <!-- CONNECTION POOL -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
 
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.10</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
 
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature
                        </projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder
                        </buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument>-Xlint:all</compilerArgument>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <configuration>
                    <mainClass>org.test.int1.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

various query  (0) 2019.11.14
Various html  (0) 2019.11.14
Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14

1. BoardController

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
 
import org.springframework.stereotype.Controller;
 
 
@Controller
public class BoardController {
 
    @Autowired
    BoardService boardService;
    
    @Autowired
    CommentService commentService;
    
    @RequestMapping("boardList")
    public String toBoardList(Model model, Board board,
            @RequestParam(required = false, defaultValue= "1")int page,
            @RequestParam(required = false, defaultValue= "1")int range) throws Exception {
        //전체 게시글 개수
        int listCnt = boardService.getBoardListCnt();
        
        //Pagination 
        Pagination pagination = new Pagination();
        pagination.pageInfo(page, range, listCnt);
        
        model.addAttribute("pagination", pagination);
        model.addAttribute("board", boardService.selectAll(pagination));
        return "board/boardList";
    }
    
    @RequestMapping("boardWrite")
    public String toBoardWrite() {
        return "board/boardWrite";
    }
    
    @RequestMapping("boardInsert")
    public String boardInsert(Board board) {
        return "redirect:boardList";
    }
    
    @RequestMapping("boardView")
    public String toBoardView(Board board, Model model) {
        model.addAttribute("board"boardService.select(board));
        model.addAttribute("comment", commentService.selectAll(board.getBoardId()));
        return "board/boardView";
    }
    
    @RequestMapping("toBoardEdit")
    public String toBoardEdit(Board board, Model model) {
        model.addAttribute("board"boardService.select(board));
        return "board/boardEdit";
    }
    
    @RequestMapping("boardEdit")
    public String boardEdit(Board board) {
        return "redirect:boardView?boardId=" + board.getBoardId();
    }
    
    @RequestMapping("boardDelete")
    public String boardDelete(Board board) {
        return "redirect:boardList";
    }
    
    @RequestMapping("toBoardReply")
    public String toBoardReply(Board board, Model model) {
        model.addAttribute("board", board);
        return "board/boardReply";
    }
    
    @RequestMapping("boardReply")
    public String BoardReply(Board board, HttpServletRequest request) {
        return "redirect:boardList";
    }
    
    @RequestMapping("search")
    public String search(@RequestParam("search"String search, @RequestParam("type"String type, Model model) {
        model.addAttribute("result"boardService.search(search, type));
        System.out.println(boardService.search(search, type));
        return "board/search";
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentController

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
 
import org.springframework.stereotype.Controller;
 
 
@Controller
public class CommentController {
 
    @Autowired
    CommentService commentService;
    
    @RequestMapping("postComment")
    public String postComment(Comment comment) {
        return "redirect:boardView?boardId=" + comment.getBoardId();
    }
    
    @RequestMapping("deleteComment")
    public String deleteComment(Comment comment) {
        return "redirect:boardView?boardId="+ comment.getBoardId();
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberController

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
 
 
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
 
 
@Controller
public class MemberController {
 
    @Autowired 
    MemberService memberService;
 
    @RequestMapping("toLogin")
    public String toLogin() {
        
        return "member/login";
    }
    
    @RequestMapping("loginCheck")
    public String login(Boardmember member, HttpSession session, Model model) {
        if(memberService.checkMember(member)) {
            model.addAttribute("success""Login Success!");
            session.setAttribute("session", member);
            return "home";
        } else {
            model.addAttribute("fail""Try reentering username or password");
            return "member/login";
        }
    }
    
    @RequestMapping("toRegister")
    public String toRegister() {
        return "member/register";
    }
    
    @RequestMapping("register")
    public String register(Boardmember member, Model model, BindingResult bindingResult) {
        memberService.registerMember(member);
        if(bindingResult.hasErrors()) {
            return "member/register";
        } else {
            model.addAttribute("success""Register Success! Now login");
        }
        
        
        return "home";
    }
    
    @RequestMapping("logout")
    public String logout(HttpSession session, Model model) {
        session.invalidate();
        model.addAttribute("success""Logout Success!");
        return "home";
    }
    
    
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Various html  (0) 2019.11.14
Settings  (0) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14

1. a. Board interface

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
 
 
public interface BoardService {
 
    List<Board> selectAll(Pagination pagination);
    void insert(Board board);
    Board select(Board board);
    void delete(Board board);
    void update(Board board);
    void hit(int board);
    void reply(Board board);
    List<Board> search(String search, String type);
    
    public int getBoardListCnt() throws Exception;
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. BoardServiceImpl

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
 
 
import org.springframework.stereotype.Service;
 
 
@Service
public class BoardServiceImpl implements BoardService{
 
    @Autowired
    BoardMapper boardMapper;
 
    @Override
    public List<Board> selectAll(Pagination pagination) {
        
        return boardMapper.selectAll(pagination);
    }
 
    @Override
    public void insert(Board board) {
    }
 
    @Override
    public Board select(Board board) {
        return boardMapper.select(board);
    }
 
    @Override
    public void delete(Board board) {
    }
 
    @Override
    public void update(Board board) {
    }
 
    @Override
    public void hit(int board) {
        boardMapper.hit(board);
    }
 
    @Override
    public void reply(Board board) {
        boardMapper.replyShape(board);
    }
 
    @Override
    public List<Board> search(String search, String type) {
        System.out.println(search + type);
        System.out.println("its boardserviceimpl" + boardMapper.search(search, type));
        return boardMapper.search(search, type);
    }
    
    @Override
    public int getBoardListCnt() throws Exception {
        return boardMapper.getBoardListCnt();
    }
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2.a. CommentServic interface

1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
public interface CommentService {
    List<Comment> selectAll(int boardId);
    void insert(Comment comment);
    void delete(int comment);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. commentserviceimpl 

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
 
 
import org.springframework.stereotype.Service;
 
 
@Service
public class CommentServiceImpl implements CommentService{
 
    @Autowired
    CommentMapper commentMapper;
 
    @Override
    public List<Comment> selectAll(int comment) {
        return commentMapper.selectAll(comment);
    }
 
    @Override
    public void insert(Comment comment) {
    }
 
    @Override
    public void delete(int comment) {
    }
    
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. a. MemberService interface

1
2
3
4
5
6
7
8
9
 
 
public interface MemberService {
    boolean checkMember(Boardmember member);
    void registerMember(Boardmember member);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

b. MemberServiceImpl 

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
 
import org.springframework.stereotype.Service;
 
 
@Service
public class MemberServiceImpl implements MemberService{
 
    @Autowired
    MemberMapper memberMapper;
    
    @Override
    public boolean checkMember(Boardmember member) {
        return memberMapper.checkMember(member) != null;
    }
 
    @Override
    public void registerMember(Boardmember member) {
        memberMapper.registerMember(member);
    }
    
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Settings  (0) 2019.11.14
Controller  (1) 2019.11.14
Paging  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14
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
 
import lombok.Data;
 
@Data
public class Pagination {
    
    private int listSize = 10//한 페이지당 보여질 리스트 개수
    private int rangeSize = 10//한 페이지 범위에 보여질 페이지의 개수
    private int page; //현재 목록의 페이지 번호
    private int range; //각 페이지 범위 시작 번호
    private int listCnt; //전채 게시물의 개수
    private int pageCnt; //전체 페이지 범위의 개수
    private int startPage; //각 페이지 범위 시작 번호
    private int startList; //해당 페이지 당 게시판 시작 번호
    private int endPage; //각 페이지 범위 끝 번호
    private boolean prev; //이전 페이지 버튼 여부
    private boolean next; //다음 페이지 버튼 여부
    
    public void pageInfo(int page, int range, int listCnt) {
        this.page = page;
        this.range = range;
        this.listCnt = listCnt;
        
        //전체 페이지수
        this.pageCnt = (intMath.ceil(listCnt/listSize);
        
        //시작 페이지
        this.startPage = (range - 1* rangeSize + 1;
        
        //끝 페이지
        this.endPage = range * rangeSize;
        
        //게시판 시작번호
        this.startList = (page - 1* listSize;
        
        //이전 버튼 상태
        this.prev = range == 1 ? false : true;
        
        //다음 버튼 상태
        this.next = endPage > pageCnt ? false : true;
        if(this.endPage > this.pageCnt) {
            this.endPage = this.pageCnt + 1;
            this.next = false;
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Mapper interface + Mapper xml  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14
Caleb Curry's Database design course  (0) 2019.11.08

1. BoardMapper 

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
 
 
 
 
public interface BoardMapper {
 
    List<Board> selectAll(Pagination pagination);
    void insert(Board board);
    Board select(Board board);
    void delete(Board board);
    void update(Board board);
    void hit(int board);
    void reply(Board board);
    void replyShape(Board board);
//    List<Board> search(@Param("search") String search,@Param("type") String type);
    List<Board> search(@Param("search"String search,@Param("type"String type);
    
    int getBoardListCnt();
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentMapper

1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
public interface CommentMapper {
    void insert(Comment comment);
    List<Comment> selectAll(int comment);
    void delete(int comment);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberMapper

1
2
3
4
5
6
7
8
9
10
 
 
public interface MemberMapper {
    
    Boardmember checkMember(Boardmember member);
    void registerMember(Boardmember member);
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

1. 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
68
69
70
71
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 //EN"
 
    <select id="selectAll" resultType="board">
        select * from board 
        order by bGroup desc, bStep asc
        limit #{startList}, #{listSize}
    </select>
    
    <select id="getBoardListCnt" resultType="int">
        select count(*) listCnt 
        from board
    </select>
 
    <insert id="insert" parameterType="board">
        insert into board (bUsername, bTitle, bContent, bDate, bHit, bGroup, bIndent, bStep)
        values (#{bUsername}, #{bTitle}, #{bContent}, now(), 0, 
            (select max(boardId)+1 from board bo), 0, 0)
    </insert>
    
    <select id="select" parameterType="board" resultType="Board">
        select * from board 
        where boardId = #{boardId}
    </select>
    <update id="update" parameterType="board">
        update board
        set bTitle = #{bTitle}, bContent = #{bContent}
        where boardId = #{boardId}
    </update>
    <delete id="delete" parameterType="board">
        delete from board
        where boardId = #{boardId}
    </delete>
    
    <update id="hit" parameterType="int">
        update board
        set bHit = bHit +1
        where boardId = #{boardId}
    </update>
    
    <insert id="reply" parameterType="board">
        insert into board(bUsername, bTitle, bContent, bDate, bHit, bGroup, bIndent, bStep)
        values(#{bUsername}, #{bTitle}, #{bContent}, now(), 0, #{bGroup}, #{bIndent} + 1, #{bStep} +1)
    </insert>
    
    <update id="replyShape" parameterType="board">
        update board 
        set bStep = #{bStep} + 1
        where bGroup = #{bGroup} and bStep > #{bStep}
    </update>
    
    <select id="search" parameterType="map" resultType="board">
<!--     <bind name="result" value="'%' + #{search} + '%'"/> -->
        select * from board
        <trim prefix="where" prefixOverrides="and|or">
            <if test="type==btitle">
                and btitle like concat('%',#{search},'%')
            </if>
            <if test="type==bcontent">
                and bcontent like concat('%',#{search},'%')
            </if>
        </trim>
<!--         where #{type} like concat('%',#{search},'%') -->
<!--         select("*"); -->
<!--         from("board"); -->
<!--         where("#{type} like '%' #{search} '%'"); -->
        
    </select>
</mapper>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

2. CommentMapper xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 //EN"
    
    <select id="selectAll" parameterType="int" resultType="comment">
        select * from comment 
        where boardId = #{boardId}
        order by commentId desc
    </select>
    
    <insert id="insert" parameterType="comment">
        insert into comment(boardId, username, content, cDate, cGroup, cIndent, cStep, cLike)
        values(#{boardId}, #{username}, #{content}, now(), (select max(commentId) from comment co) +1, 0, 0, 0)
    </insert>
    
    <delete id="delete" parameterType="int">
        delete from comment 
        where commentId = #{commentId}
    </delete>
    
</mapper>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

3. MemberMapper xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0 //EN"
    
    
    <select id="checkMember" parameterType="Boardmember" resultType="Boardmember">
        select * from Boardmember
        where username = #{username} and password = #{password}
    </select>
    
    <insert id="registerMember" parameterType="Boardmember">
        insert into boardmember (username, password, email, gender, birthday, joinDate)
        values (#{username}, #{password}, #{email}, #{gender}, #{birthday}, now())
    </insert>
</mapper>
http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
 

 

'ETC' 카테고리의 다른 글

Controller  (1) 2019.11.14
Service interface + ServiceImpl class  (0) 2019.11.14
Paging  (0) 2019.11.14
게시판 DTO  (3) 2019.11.14
Caleb Curry's Database design course  (0) 2019.11.08

+ Recent posts