baseURL 을 지정해두면 나머지 경로만 입력하면 된다. (/api/v1/members/list -> /members/list)

axios.defaults.baseURL = '/api/v1';

인증 토큰은 백앤드 API 요청시 항상 전달하므로 기본값으로 설정할 수 있음

axios.defaults.headers.common['Authorization'] = JWT 

timeout에 설정된 시간내에 응답이 오지 않으면 연결이 중단(abort) 시킴

axios.defaults.timeout = 2000;

 

 

nth-child :  몇번째 자식요소

nth-of-type:  해당 태그들 중에 몇번째 요소

 

교착 상태에 빠지지 않게 하기 위해 비관점 잠금 타임아웃을 설정할 수 있다. 

Map<String, Object> hints = new HashMap<>();
hints.put("javax.persistence.lock.timeout", 2000);
Order order = entityManager.find(Order.class, LockModeType.PESSIMISTIC_WRITE, hints);

 

@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints({
	@QueryHint(name="javax.persistence.lock.timeout", value="2000" )
})
@Query("select m from Member where m.id = :id")
Optional<Member> findByIdForUpdate(@Param("id") MemberId memberId);

Throttle

여러 번 실행해도 최초의 실행이 끝날 때까지 실행되지 않는다.

let timer = 0;

function handleThrottle(){
    console.log('진입');

    if (timer) {
        return;
    }

    timer = setTimeout(() => {
       console.log('실행');
       timer = 0;
    }, 1000);
}

Debounce

여러 번 실행할 경우 마지막 것이 실행된다.

let timer = 0;

function handleDebounce(){
    console.log('진입');

    clearTimeout(timer);

    timer = setTimeout(() => {
       console.log('실행');
    }, 1000);
}

선언된 변수나 클래스 멤버 변수는 선언과 동시에 초깃값 할당 해야함

val data1: Int // 오류
val data2 = 10 // 성공

class User {
	
    val data3: Int  // 오류
    val data5: Int = 10 // 성공
}

함수의 경우 선언과 동시에 할당하지 않아도 되지만, 이용시 에는 값을 할당해야함

fun someFun() {
	
    val data1: Int
    println("data1 : $data1") // 오류
    data1 = 10
    println("Data1 : $data1") // 성공
}

초기화 미루기 ( lateinit , lazy)

lateinit 

  •  lateinit은 var 키워드로 선언한 변수에만 사용할 수 있습니다.
  • Int, Long, Short, Double, Float, Boolean, Byte 타입에는 사용할 수 없습니다.
lateinit var data1: Int  // 오류
lateinit val data2: String // 오류
lateinit var data3: String // 성공

선언한 변수는 선언과 동시에 초깃값을 할당하지 않아도 됩니다. 

lazy

  • 변수 선언문 뒤에 by lazy {} 형식으로 선언
  • 변수가 최초로 이용되는 순간 {} 부분이 자동 실행  초깃값으로 할당 
val data4: Int by lazy {
	
    println("in lazy.....")
    10
}

fun main(){
	
    println("in main...")
    println(data4 + 10)
    println(data4 + 10)
}

실행결과 

in main...
in lazy.....
20
20

중괄호 부분을 여러 줄로 작성한다면 마지막 줄의 실행 결과가 변수의 초깃값이 됩니다.

val (=value)

초기값이 할당되면 바꿀 수  없는 변수

var (=variable)

초기값이 할당된 후에도 값을 바꿀 수 있는 변수

RandomStringUtils.randomNumeric(int count)

- count 만큼 랜덤한 숫자를 생성

isNotEmpty

public static boolean isNotEmpty(Collection<?> coll)
Null-safe check if the specified collection is not empty.

Null returns false.

Parameters:
coll - the collection to check, may be null

Returns:

true if non-null and non-empty

+ Recent posts