일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 정규화표현식
- interface
- 참조타입
- Set
- scope
- 환경설정
- jsp
- String
- 자료구조
- jquery
- Selector
- SQL
- mybatis
- JavaScript
- extends
- DB
- regex
- 개선
- html
- 자바
- 자바스크립트
- jdbc
- java
- controller
- jar
- 알고리즘
- for문
- JCF
- 형변환
- iBATIS
- Today
- Total
프로그래밍공부노트
Day 44 - iBatis(Dynamic Query) 본문
배포와 실행관련된 부분을 인지하지 못하면 문제가 생긴다
코드를 제대로 정확히 작성했는데
ClassNotFoundException이 생기는 이유는 보고있는 resource는 java파일
근데 우리가 실행시키는 것은 compile된 class파일
java project로 실행할때는 문제가 없음
하지만 MAVEN 이나 WEB형태로 만들면 CONTEXTROOT/ WEB-INF / CLASSES 에 java로 만들어진 객체가 compile돼서 실행이 되는 것이다.
근데 위같은 문제가 생기는 것은 java파일의 compile에 문제가 있어서 배포가 되지 않았다는 것
그러면 다시 컴파일을 시키면 된다. project clean이 그 방법이다
1) delete from jobs_temp <= 전체 삭제
2) delete from jobs_temp where job_id = "it_prog" or job_id="it"; 두개 삭제
delete from jobs_temp where job_id in ("it_prog", "it");
3) delete from jobs_temp where job_id = "it_prog"
delete from jobs_temp where job_id = "it"
1번과 2번은 쿼리가 한줄로 되어 있음 하나의 sql 명령어가 동작이 되는 것
3번은 두개의 쿼리를 각각 한번씩 실행시켜서 "묶음"으로 만들어 줘야 함 -> transaction
Transaction이 되어야되는 쿼리
Dynamic Query
<isNotNull>
iBatis는 무조건 사용되는 메소드에 따라서 객체를 생성해서 반환한다.
JDBC를 사용할때처럼 NULL이라는 객체는 한개만 검색할때만 생성이 된다.
여러개일때는 NULL판단을 안해도 된다.
<select id="selectDynamic02" parameterClass="com.min.edu.dto.jobsDto" resultClass="com.min.edu.dto.jobsDto">
<include refid="allColumn"/>
<dynamic prepend="WHERE">
<isNotNull property="job_id">
JOB_ID = #job_id#
</isNotNull>
</dynamic>
</select>
job_id에 널이 없다면 job_id를 binding하여 select하여 출력해준다.
<prepend> override
<select id="selctDynamic03" parameterClass="com.min.edu.dto.jobsDto" resultClass="com.min.edu.dto.jobsDto">
<include refid="allColumn"/>
<dynamic prepend="WHERE">
<isNotNull property="job_id" prepend="OR">
JOB_ID = #job_id#
</isNotNull>
<isNotNull property="job_title" prepend="AND">
JOB_TITLE = #job_title#
</isNotNull>
<isGreaterEqual property="max_salary" compareValue="5000" prepend="OR">
MAX_SALARY =#max_salary#
</isGreaterEqual>
</dynamic>
</select>
1. job_id가 not null 이면 JOB_ID=#job_id#를 실행!
2.job_title이 NOT NULL이면 JOB_TITLE = #job_title#을 실행!
3.max_salary가 5000보다 크다면 MAX_SALARY=#max_salary#를 실행한다
public static void main(String[] args) {
jobsDto dto = new jobsDto();
dto.setJob_id("IT_PROG");
dto.setJob_title("Programmer");
dto.setMax_salary(8000);
List<jobsDto>lists = dynamicDao.selectDynamic03(dto);
System.out.println(lists);
}
위에서 3개 중에 선택하여 사용할 수 있다. 3가지 조건중 id와 tiltle 만 set하여 실행한다면 두 개가 and로 묶여서 실행된다. id와 salary를 set하여 실행한다면 두개가 or로 묶여서 실행된다.
여기서 prepend를 override하기 위해서는 prepend의 위치를 맞춰주는 작업이 필요해서 모두 작성한다.
쿼리를 여러번 안 날리고 한번에 원하는 것으로 선택하여 처리가능
ex) 게시판에서 작성자 + 내용 + 글번호 검색 / 작성자 + 내용 검색 / 내용 검색 이런식으로 사용함
'iBatis' 카테고리의 다른 글
Day 43 - iBatis (selectKey , Binding, DynamicQuery) (0) | 2021.04.15 |
---|---|
Day 42 - iBatis (0) | 2021.04.14 |
Day 41 - iBatis(환경설정, 테스트) (0) | 2021.04.12 |