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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?xml version="1.0" encoding="UTF-8" ?>
 
 
 
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
 
 
 
<sqlMap namespace="board">
    <typeAlias alias="boardVO" type="board.vo.BoardVO" />
    <typeAlias alias="commentVO" type="board.vo.CommentVO" />
    
 
    <!-- 리스트 조회시 where절 -->
 
    <sql id="board.where.getList">
        <isNotEmpty property="searchStr">
            <isEqual property="searchSelect" compareValue="title">
                AND title LIKE '%'||#searchStr#||'%'
            </isEqual>
            <isEqual property="searchSelect" compareValue="writer">
                AND writer LIKE '%'||#searchStr#||'%'
            </isEqual>
        </isNotEmpty>
    </sql>
 
    
 
    <!-- 상세정보 조회시 코멘트 같이 조회 -->
 
    <resultMap class="boardVO" id="boardInfoMap">
 
        <result property="no" column="no"/>
        <result property="groupNo" column="group_no"/>
        <result property="title" column="title"/>
        <result property="writer" column="writer"/>
        <result property="contents" column="contents"/>
        <result property="hit" column="hit"/>
        <result property="regdate" column="regdate"/>
        <result property="comments" select="board.getCommentList" column="no"/>
 
    </resultMap>
 
    
 
    <!-- board 시퀀스 구하기 -->
 
    <select id="getSeq" resultClass="int">
 
        SELECT board_seq.nextval
 
        FROM dual
 
    </select>
 
    
 
    <!-- 리스트 목록 조회 -->
 
    <select id="getList" parameterClass="boardVO" resultClass="boardVO">
 
        <![CDATA[
        SELECT     no,
                group_no groupNo,
                depth_no depthNo,
                title,
                writer,
                contents,
                hit,
                type,
                regdate
        FROM (
            SELECT /*+ index_desc(a board_pk)*/rownum rn, no, group_no, order_no, depth_no, title, writer, contents, hit, type, regdate
            FROM board a
            WHERE no > 0 AND rownum <= #end#
        )
        WHERE rn >= #begin# AND type=#type#
 
        ]]>
 
        <include refid="board.where.getList" />
 
        ORDER BY group_no DESC, order_no ASC
 
    </select>
 
    
 
    <!-- 게시글 등록 -->
 
    <insert id="insertBoard" parameterClass="boardVO">
 
        INSERT INTO board (no, group_no, order_no, depth_no, id, title, writer, contents, hit, type, regdate)
 
                    VALUES (#no#, #groupNo#, #orderNo#, #depthNo#, #id#, #title#, #writer#, #contents#, 0, #type#, sysdate)
 
    </insert>
 
    
 
    <!-- 전체게시글 수 구하기 -->
 
    <select id="getTotalRow" parameterClass="boardVO" resultClass="int">
 
        SELECT count(*)
 
        FROM board
 
        WHERE type=#type#
 
        <include refid="board.where.getList" />
 
    </select>
 
    
 
    <!-- 조회수 증가 -->
 
    <update id="updateHit" parameterClass="int">
 
        UPDATE board SET hit=hit+1
 
        WHERE no=#value#
 
    </update>
 
    
 
    <!-- 상세정보 조회 -->
 
    <select id="getInfo" parameterClass="int" resultMap="boardInfoMap">
 
        SELECT no, group_no, title, writer, contents, hit, regdate
 
        FROM board
 
        WHERE no=#value#
 
    </select>
 
    
 
    <!-- 부모글 정보 조회 -->
 
    <select id="getParentInfo" parameterClass="int" resultClass="boardVO">
 
        SELECT     group_no groupNo,
 
                order_no orderNo,
 
                depth_no depthNo
 
        FROM board
 
        WHERE no=#value#
 
    </select>
 
    
 
    <!-- 부모글 순서보다 큰 게시글 업데이트하기 -->
 
    <update id="updateDepthNo" parameterClass="boardVO">
 
        <![CDATA[
        UPDATE board SET order_no=order_no+1
        WHERE group_no=#groupNo# AND order_no > #orderNo#
 
        ]]>
 
    </update>
 
    
 
    <!-- 게시글 수정 -->
 
    <update id="updateBoard" parameterClass="boardVO">
 
        UPDATE board SET
 
                title=#title#,
 
                writer=#writer#,
 
                contents=#contents#
 
        WHERE no=#no#
 
    </update>
 
    
 
    <!-- 게시글 삭제 -->
 
    <delete id="deleteBoard" parameterClass="int">
 
        DELETE FROM board
 
        WHERE no=#value#
 
    </delete>
 
    
 
    <!-- 코멘트 시퀀스 얻기 -->
 
    <select id="getCommentSeq" resultClass="int">
 
        SELECT board_comment_seq.nextval
 
        FROM dual
 
    </select>
 
    
 
    <!-- 코맨트 작성 -->
 
    <insert id="insertComment" parameterClass="commentVO">
 
        INSERT INTO board_comment(no, board_no, id, writer, contents, regdate)
 
                VALUES (#no#, #boardNo#, #id#, #writer#, #contents#, sysdate)
 
    </insert>
 
    
 
    <!-- 코멘트 상세정보 -->
 
    <select id="getCommentInfo" parameterClass="int" resultClass="commentVO">
 
        SELECT     no,
 
                board_no boardNo,
 
                id,
 
                writer,
 
                contents,
 
                regdate
 
        FROM board_comment
 
        WHERE no=#value#
 
    </select>
 
    
 
    <!-- 코멘트 리스트 조회 -->
 
    <select id="getCommentList" parameterClass="int" resultClass="commentVO">
 
        SELECT     no,
 
                board_no boardNo,
 
                id,
 
                writer,
 
                contents,
 
                regdate
 
        FROM board_comment
 
        WHERE board_no=#value#
 
        order by no
 
    </select>
 
    
 
    <!-- 코멘트 수정 -->
 
    <update id="updateComment" parameterClass="commentVO">
 
        UPDATE board_comment SET contents=#contents#
 
        WHERE no=#no#
 
    </update>
 
    
 
    <!-- 코멘트 삭제 -->
 
    <delete id="deleteComment" parameterClass="int">
 
        DELETE FROM board_comment
 
        WHERE no=#value#
 
    </delete>
 
</sqlMap>
 
 
 
 
cs


Posted by MR 손
,