sm 기술 블로그

Utillity 본문

스프링부트

Utillity

sm_hope 2022. 6. 30. 21:23

Utillity

동작에 필수적이지는 않지만 일부 작업을 정상적으로 수행할 수 있도록 도와준다.

"msg": "4번이 없어요.",

위 예시에서는 4라는 숫자를 위해서 사용하였다.

프레임워크

package com.example.demo.util;

public class Ut {

	public static boolean empty(Object obj) {
		if (obj == null) {
			return true;
		}

		if (obj instanceof String == false) {
			return true;
		}

		String str = (String) obj;

		return str.trim().length() == 0;
	}

	public static String f(String format, Object... args) {
		return String.format(format, args);
	}

}

  1. 값이 비어있는지 여부를 체크함.
  2. 문자열 출력을 도와줌 (format에 원하는 출력 문자열을 쓰고 args 에 객체를 넣는다.(위 예시에서는 번호를 넣었다.))
Comments