728x90
반응형
SMALL
  • 단일 항목 검색
    제목/내용/작성자
  • 다중 항목 검색
    제목 or 내용, 제목 or 작성자, 내용 or 작성자, 제목 or 내용 or 작성자

(1) MyBatis의 동적 태그들
if
choose(when, otherwise)
where
trim
foreach

(2) if
검색조건이 'T' : 제목이 키워드인 항목을 검색
<if test="type == 'T'.toString()">
(title like '%'||#{keyword}||'%')
</if>

- 검색조건이 'C' : 내용이 키워드인 항목을 검색
    <if test="type == 'C'.toString()">
        (content like '%'||#{keyword}||'%')
    </if>

- 검색조건이 'W' : 작성자가 키워드인 항목을 검색
    <if test="type == 'W'.toString()">
        (writer like '%'||#{keyword}||'%')
    </if>

(3) choose
<choose>
<when test="type == 'T'.toString()">
(title like '%'||#{keyword}||'%')
</when>
...
<otherwise>
(title like '%'||#{keyword}||'%' OR content like '%'||#{keyword}||'%'
</otherwise>
</choose>

(4) where
select * from tbl_board
<where>
<if test="bno != null">
bno = #{bno}
</if>
</where>

(5) trim
select * from tbl_board
<where>
<if test="bno != null">
bno = #{bno}
</if>
<trim prefixOverrides = "and">
rownum = 1
</trim>
</where>

* bno가 null일 때
  select * from tbl_board where rownum = 1

* bno가 null이 아닐 때
  select * from tbl_board where bno = 변수 and rownum = 1

(6) foreach
List, 배열, Map 등을 이용하여 루프 처리

*파라미터
Map map = new HashMap();
map.put("T","TTTT");
map.put("C","CCCC");

*쿼리
select * from board
// 앞에 붙는 OR를 없애주기 위함
<trim prefix="where (" suffix=")" prefixOverrides="OR">
    <foreach item="val" index="key" collection="map">
        <trim prefix="OR">
            <if test="key == 'T'.toString()">
                title = #{val}
            </if>
            <if test="key == 'C'.toString()">
                content = #{val}
            </if>
            <if test="key == 'W'.toString()">
                writer = #{val}
            </if>
        </trim>
    </foreach>
</trim>

* 결과
select * from tbl_board where (content = 'CCCC' OR title = 'TTTT')

728x90
반응형
LIST

'개발 > 정리 내용' 카테고리의 다른 글

웹 개발 방법론  (0) 2023.01.15
Reply 구현  (0) 2023.01.15
프리젠테이션 계층의 구조와 테스트  (0) 2023.01.15
비즈니스(Business)계층  (0) 2023.01.15
Front-Controller Pattern  (0) 2023.01.15
728x90
반응형
SMALL
Task   URL      Method  Parameter   Form  URL이동
전체 목록  /board/list GET 없음 없음 없음
등록  /board/register POST 모든 항목 필요 이동
조회 /board/read GET bno 필요 없음
삭제 /board/remove POST bno 필요 이동
수정 /board/modify POST 모든 항목 필요 이동

 

728x90
반응형
LIST

'개발 > 정리 내용' 카테고리의 다른 글

Reply 구현  (0) 2023.01.15
검색처리  (0) 2023.01.15
비즈니스(Business)계층  (0) 2023.01.15
Front-Controller Pattern  (0) 2023.01.15
MyBatis  (0) 2023.01.15
728x90
반응형
SMALL

프리젠테이션 계층(View)과 영속 계층(DBMS)의 중간다리 역할
영속 계층은 DBMS를 기준으로, 비즈니스 계층은 로직을 기준으로 처리한다.
예) 쇼핑몰에서 상품 구매 시 포인트 적립
영속 계층 설계는 '상품', '회원'으로 나누어 설계하지만 비즈니스 계층 설계는 상품 영역과 회원 영역을 동시에 사용하여 하나의 로직 처리

일반적으로 비지니스 영역에 있는 객체들은 서비스(Service)라는 용어를 사용

728x90
반응형
LIST

'개발 > 정리 내용' 카테고리의 다른 글

검색처리  (0) 2023.01.15
프리젠테이션 계층의 구조와 테스트  (0) 2023.01.15
Front-Controller Pattern  (0) 2023.01.15
MyBatis  (0) 2023.01.15
스프링에서의 CP  (0) 2023.01.15

+ Recent posts