MySql - limit 사용하기

*** 사용법1 ***
LIMIT 정수
쿼리 실행 결과의 갯수를 제한한다.


예제)
select * from TABLE_NAME limit 5;

*** 사용법2 ***
LIMIT 정수, 정수
쿼리 실행 결과를 지정된 인덱스부터 지정된 갯수만큼 조회한다.
첫번째 정수는 시작 인덱스를 지정. 0부터 시작.
두번째 정수는 결과 갯수를 지정.

예제)
select * from TABLE_NAME limit 0, 5;

Java - 날짜 포맷 (FastDateFormat)

*** 설명 ***
기존 SimpleDateFormat 보다 빠름.
Thread Safe.
Apache Commons Lang 라이브러리 필요.

*** 사용예 ***
FastDateFormat fdf = FastDateFormat.getInstance("yyyyMMdd");
System.out.println("FastDateFormat =" + fdf.format(Calendar.getInstance()));

*** maven repository ***
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
    <version>3.4</version>
</dependency>

Oracle - UNION, UNION ALL

*** UNION ***
두 테이블을 결합한 결과를 반환하는데 중복되지 않는 값들만 반환.
결과는 정렬되어서 반환.


*** UNION ALL ***
두 테이블을 결합한 결과를 반환하는데 중복되는 값들도 모두 반환.


ex) 
TABLE_1                           TABLE_2
---------                         ---------
COL_A                              COL_A
---------                         ---------
1                                         3
2                                         2
3                                         1

select COL_A from TABLE_!
union
select COL_A from TABLE_2
=> 결과
1
2
3

select COL_A from TABLE_!
union all
select COL_A from TABLE_2
=> 결과
1
2
3
3
2
1

MyBatis 동적 쿼리 - choose

*** choose 문 ***
스위치 구문과 비슷. 여러 조건을 순서대로 체크하여 해당하는 조건의 구문을 추가.
해당되는 조건이 없을 경우 otherwise에 해당하는 구문을 추가

ex)
<select id="testSql" parameterType="hashmap" resultType="hashmap">
    select
        ID, NAME
    from
        T_TEST A
    where USE_YN = 'Y'
    <choose>       
        <when test="type == 'A' ">
            and TYPE = 'A'
        </when>       
        <when test="type == 'B' ">
            and TYPE = 'B'
        </when>
        <otherwise>
            and TYPE = 'C'
        </otherwise>
    </choose>
</select>

interface 형식
@Select("<script>"
    + "select "
    + " ID, NAME "
    + "from T_TEST A "
    + "where USE_YN = 'Y' "
    + " <choose>"
    + "   <when test=\"type == 'A'\"> TYPE = 'A' </when>"
    + "   <when test=\"type == 'B'\"> TYPE = 'B' </when>"
    + "   <otherwise> TYPE = 'C' </otherwise>"
    + " </choose>"
    + "</script> ")
List<HashMap> select(@Param("type")String type);

MyBatis 동적 쿼리 - if

*** if 문 ***
조건을 만족하는 경우 추가

ex) type 값이 null이 아니고, 빈값이 아닐때 조건에 추가
xml 형식
<select id="testSql" parameterType="hashmap" resultType="hashmap">
    select
        ID, NAME
    from
        T_TEST A
    where USE_YN = 'Y'
    <if test="type != null and type != ''"> and TYPE = #{type} </if>
</select>

interface 형식
@Select("<script>"
    + "select "
    + " ID, NAME "
    + "from T_TEST A "
    + "where USE_YN = 'Y' "
    + "<if test=\"type != null and type != ''\"> and TYPE = #{type} </if>"
    + "</script> ")
List<HashMap> select(@Param("type")String type);

JQuery select 인덱스로 선택하기

*** 설명 ***
기존에 선택되어 있던 것의 선택을 해제한 후 인덱스에 해당하는 것을 선택한다.

*** example ***
var newIndex = 0;
var selectedIndex = $('#select option').index($('#select option:selected'));
$('#select option:eq(' + selectedIndex + ')').removeAttr('selected');
$('#select option:eq(' + newIndex + ')').attr('selected', 'selected');

JQuery select 값 변경시 이벤트 함수

*** example ***
jQuery(function($) {
   $('#select').change(function(){
       alert('select change. value' + $('select').val());

   });
});