38 lines
893 B
Java
38 lines
893 B
Java
package com.ruoyi.common.utils;
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
|
/**
|
|
* @author 辉
|
|
* 2024/3/4
|
|
*/
|
|
public class ServiceUtil {
|
|
|
|
/**
|
|
* 判断是否满足条件,满足则抛出异常
|
|
* @param flag 条件
|
|
* @param msg 异常说明
|
|
*/
|
|
public static void assertion(boolean flag, String msg) {
|
|
assertion(flag, msg, 500);
|
|
}
|
|
|
|
/**
|
|
* 判断是否满足条件,满足则抛出异常
|
|
* @param flag 条件
|
|
* @param msg 异常说明
|
|
* @param code 业务代码
|
|
*/
|
|
public static void assertion(boolean flag, String msg, int code) {
|
|
if (flag) {
|
|
throw new ServiceException(msg, code);
|
|
}
|
|
}
|
|
|
|
public static void assertion(boolean flag, String format, Object ...args) {
|
|
if (flag) {
|
|
throw new ServiceException(String.format(format, args), 500);
|
|
}
|
|
}
|
|
}
|