Compare commits
10
Commits
dev
..
27bbfc60d5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
27bbfc60d5 | ||
|
|
6fdb02f3c1 | ||
|
|
5770a41893 | ||
|
|
a919cf0a52 | ||
|
|
5612d6a24a | ||
|
|
db530c1fed | ||
|
|
1fe9cf7b77 | ||
|
|
0d21b154ca | ||
|
|
acba4c11d9 | ||
|
|
d21fba0fc1 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.7</version>
|
<version>0.0.5</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.io.StringWriter;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用工具
|
* 通用工具
|
||||||
@@ -80,15 +81,6 @@ public interface TimiJava {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean allEmpty(Object... objects) {
|
|
||||||
for (Object object : objects) {
|
|
||||||
if (isNotEmpty(object)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static boolean allNotEmpty(Object... objects) {
|
static boolean allNotEmpty(Object... objects) {
|
||||||
for (Object object : objects) {
|
for (Object object : objects) {
|
||||||
if (isEmpty(object)) {
|
if (isEmpty(object)) {
|
||||||
@@ -113,7 +105,7 @@ public interface TimiJava {
|
|||||||
* @param <T> 对象类型
|
* @param <T> 对象类型
|
||||||
*/
|
*/
|
||||||
static <T> T defaultIfNull(T obj, T defaultObj) {
|
static <T> T defaultIfNull(T obj, T defaultObj) {
|
||||||
return obj != null ? obj : defaultObj;
|
return Objects.requireNonNullElse(obj, defaultObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,22 +30,4 @@ public class BasePage {
|
|||||||
public void next() {
|
public void next() {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取偏移量
|
|
||||||
*
|
|
||||||
* @return 偏移量
|
|
||||||
*/
|
|
||||||
public long getOffset() {
|
|
||||||
return (long) index * size;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取限制数量
|
|
||||||
*
|
|
||||||
* @return 限制数量
|
|
||||||
*/
|
|
||||||
public long getLimit() {
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package com.imyeyu.java.bean;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 多语言消息接口
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @since 2024-04-01 10:28
|
||||||
|
*/
|
||||||
|
public interface LanguageMsgMapping<T> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息
|
||||||
|
*
|
||||||
|
* @param msg 消息
|
||||||
|
* @return 原对象
|
||||||
|
*/
|
||||||
|
T msg(String msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息多语言键
|
||||||
|
*
|
||||||
|
* @param msgKey 键
|
||||||
|
* @return 原对象
|
||||||
|
*/
|
||||||
|
T msgKey(String msgKey);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息多语言键并附加插值参数
|
||||||
|
*
|
||||||
|
* @param msgKey 键
|
||||||
|
* @param msgArgs 插值参数
|
||||||
|
* @return 原对象
|
||||||
|
*/
|
||||||
|
T msgKey(String msgKey, Map<String, Object> msgArgs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息
|
||||||
|
*
|
||||||
|
* @param msg 消息
|
||||||
|
*/
|
||||||
|
void setMsg(String msg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息
|
||||||
|
*
|
||||||
|
* @return 消息
|
||||||
|
*/
|
||||||
|
String getMsg();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息多语言键
|
||||||
|
*
|
||||||
|
* @param msgKey 键
|
||||||
|
*/
|
||||||
|
void setMsgKey(String msgKey);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置消息多语言键并附加插值参数列表
|
||||||
|
*
|
||||||
|
* @param msgKey 键
|
||||||
|
* @param msgArgs 插值参数
|
||||||
|
*/
|
||||||
|
void setMsgKey(String msgKey, Map<String, Object> msgArgs);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取消息多语言键
|
||||||
|
*
|
||||||
|
* @return 键
|
||||||
|
*/
|
||||||
|
String getMsgKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取附加插值参数
|
||||||
|
*
|
||||||
|
* @return 附加插值参数列表
|
||||||
|
*/
|
||||||
|
Map<String, Object> getMsgArgs();
|
||||||
|
}
|
||||||
@@ -109,7 +109,7 @@ public enum TimiCode {
|
|||||||
* @return 返回对象
|
* @return 返回对象
|
||||||
*/
|
*/
|
||||||
public TimiResponse<?> toResponse() {
|
public TimiResponse<?> toResponse() {
|
||||||
return new TimiResponse<>(this).message(toString());
|
return new TimiResponse<>(this).msg(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.java.bean.timi;
|
package com.imyeyu.java.bean.timi;
|
||||||
|
|
||||||
|
import com.imyeyu.java.bean.LanguageMsgMapping;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -10,53 +11,81 @@ import java.util.Map;
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2023-04-27 15:55
|
* @since 2023-04-27 15:55
|
||||||
*/
|
*/
|
||||||
@Getter
|
public class TimiError extends AssertionError implements LanguageMsgMapping<TimiError> {
|
||||||
public class TimiError extends AssertionError {
|
|
||||||
|
|
||||||
/** 代码 */
|
/** 代码 */
|
||||||
|
@Getter
|
||||||
protected final TimiCode code;
|
protected final TimiCode code;
|
||||||
|
|
||||||
/** 消息代码 */
|
protected transient String msgKey;
|
||||||
protected final String messageCode;
|
|
||||||
|
|
||||||
/** 消息插值参数 */
|
protected transient Map<String, Object> msgArgs;
|
||||||
protected final transient Map<String, Object> messageArgs;
|
|
||||||
|
|
||||||
/** @param code 代码 */
|
/** @param code 代码 */
|
||||||
public TimiError(TimiCode code) {
|
public TimiError(TimiCode code) {
|
||||||
this(code, code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造器
|
|
||||||
*
|
|
||||||
* @param code 代码
|
|
||||||
* @param messageCode 消息代码
|
|
||||||
*/
|
|
||||||
public TimiError(TimiCode code, String messageCode) {
|
|
||||||
this(code, messageCode, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造器
|
|
||||||
*
|
|
||||||
* @param code 代码
|
|
||||||
* @param messageCode 消息代码
|
|
||||||
* @param messageArgs 消息插值参数
|
|
||||||
*/
|
|
||||||
public TimiError(TimiCode code, String messageCode, Map<String, Object> messageArgs) {
|
|
||||||
super(messageCode);
|
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.messageCode = messageCode;
|
|
||||||
this.messageArgs = messageArgs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转为通用响应
|
* 构造器
|
||||||
*
|
*
|
||||||
* @return 响应
|
* @param code 代码
|
||||||
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
|
public TimiError(TimiCode code, String msg) {
|
||||||
|
super(msg);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
public TimiResponse<?> toResponse() {
|
public TimiResponse<?> toResponse() {
|
||||||
return new TimiResponse<>(code).messageCode(messageCode, messageArgs);
|
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey, msgArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiError msg(String msg) {
|
||||||
|
throw new UnsupportedOperationException("unsupported to change message");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiError msgKey(String msgKey) {
|
||||||
|
setMsgKey(msgKey);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiError msgKey(String msgKey, Map<String, Object> msgArgs) {
|
||||||
|
setMsgKey(msgKey, msgArgs);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
throw new UnsupportedOperationException("unsupported to change message");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsg() {
|
||||||
|
return getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgKey(String msgKey) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsgKey() {
|
||||||
|
return msgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgKey(String msgKey, Map<String, Object> msgArgs) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
|
this.msgArgs = msgArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMsgArgs() {
|
||||||
|
return msgArgs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,133 +2,159 @@ package com.imyeyu.java.bean.timi;
|
|||||||
|
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
import com.imyeyu.java.bean.CallbackReturn;
|
import com.imyeyu.java.bean.CallbackReturn;
|
||||||
|
import com.imyeyu.java.bean.LanguageMsgMapping;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用运行时异常,附加通用代码和消息代码
|
* 通用运行时异常,附加通用代码
|
||||||
*
|
*
|
||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2021-05-20 15:18
|
* @since 2021-05-20 15:18
|
||||||
*/
|
*/
|
||||||
@Getter
|
public class TimiException extends RuntimeException implements LanguageMsgMapping<TimiException> {
|
||||||
public class TimiException extends RuntimeException {
|
|
||||||
|
|
||||||
/** 代码 */
|
/** 代码 */
|
||||||
|
@Getter
|
||||||
protected final TimiCode code;
|
protected final TimiCode code;
|
||||||
|
|
||||||
/** 消息代码 */
|
protected transient String msgKey;
|
||||||
protected final String messageCode;
|
|
||||||
|
|
||||||
/** 消息插值参数 */
|
protected transient Map<String, Object> msgArgs;
|
||||||
protected final transient Map<String, Object> messageArgs;
|
|
||||||
|
|
||||||
/** @param code 代码 */
|
/** @param code 代码 */
|
||||||
public TimiException(TimiCode code) {
|
public TimiException(TimiCode code) {
|
||||||
this(code, code.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造器
|
|
||||||
*
|
|
||||||
* @param code 代码
|
|
||||||
* @param messageCode 消息代码
|
|
||||||
*/
|
|
||||||
public TimiException(TimiCode code, String messageCode) {
|
|
||||||
this(code, messageCode, (Map<String, Object>) null);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造器
|
|
||||||
*
|
|
||||||
* @param code 代码
|
|
||||||
* @param messageCode 消息代码
|
|
||||||
* @param messageArgs 消息插值参数
|
|
||||||
*/
|
|
||||||
public TimiException(TimiCode code, String messageCode, Map<String, Object> messageArgs) {
|
|
||||||
super(messageCode);
|
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.messageCode = messageCode;
|
|
||||||
this.messageArgs = messageArgs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造器
|
* 构造器
|
||||||
*
|
*
|
||||||
* @param code 代码
|
* @param code 代码
|
||||||
* @param messageCode 消息代码
|
* @param msg 消息
|
||||||
* @param e 异常
|
|
||||||
*/
|
*/
|
||||||
public TimiException(TimiCode code, String messageCode, Throwable e) {
|
public TimiException(TimiCode code, String msg) {
|
||||||
super(messageCode, e);
|
super(msg);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.messageCode = messageCode;
|
|
||||||
this.messageArgs = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转为通用响应
|
* 构造器
|
||||||
*
|
*
|
||||||
* @return 响应
|
* @param code 代码
|
||||||
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
|
public TimiException(TimiCode code, String msg, Throwable e) {
|
||||||
|
super(msg, e);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
public TimiResponse<?> toResponse() {
|
public TimiResponse<?> toResponse() {
|
||||||
return new TimiResponse<>(code).messageCode(messageCode, messageArgs);
|
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey, msgArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T required(T t, String messageCode) {
|
@Override
|
||||||
|
public TimiException msg(String msg) {
|
||||||
|
throw new UnsupportedOperationException("unsupported to change message");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiException msgKey(String msgKey) {
|
||||||
|
setMsgKey(msgKey);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiException msgKey(String msgKey, Map<String, Object> msgArgs) {
|
||||||
|
setMsgKey(msgKey, msgArgs);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
throw new UnsupportedOperationException("unsupported to change message");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsg() {
|
||||||
|
return getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgKey(String msgKey) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgKey(String msgKey, Map<String, Object> msgArgs) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
|
this.msgArgs = msgArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsgKey() {
|
||||||
|
return msgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMsgArgs() {
|
||||||
|
return msgArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T required(T t, String message) {
|
||||||
if (TimiJava.isEmpty(t)) {
|
if (TimiJava.isEmpty(t)) {
|
||||||
throw new TimiException(TimiCode.ARG_MISS, messageCode);
|
throw new TimiException(TimiCode.ARG_MISS, message);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T required(T t, String messageCode, Map<String, Object> messageArgs) {
|
public static <T> T required(T t, String message, String msgKey) {
|
||||||
if (TimiJava.isEmpty(t)) {
|
if (TimiJava.isEmpty(t)) {
|
||||||
throw new TimiException(TimiCode.ARG_MISS, messageCode, messageArgs);
|
throw new TimiException(TimiCode.ARG_MISS, message).msgKey(msgKey);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void requiredNull(T t, String messageCode) throws TimiException {
|
public static <T> void requiredNull(T t, String message) throws TimiException {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
throw new TimiException(TimiCode.ERROR, messageCode);
|
throw new TimiException(TimiCode.ERROR, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void requiredNull(T t, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
public static <T> void requiredNull(T t, String message, String msgKey) throws TimiException {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(boolean bool, String messageCode) throws TimiException {
|
public static void requiredTrue(boolean bool, String message) throws TimiException {
|
||||||
if (bool) {
|
if (bool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new TimiException(TimiCode.ERROR, messageCode);
|
throw new TimiException(TimiCode.ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(boolean bool, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
public static void requiredTrue(boolean bool, String message, String msgKey) throws TimiException {
|
||||||
if (bool) {
|
if (bool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode) throws TimiException {
|
public static void requiredTrue(CallbackReturn<Boolean> callback, String message) throws TimiException {
|
||||||
TimiException.required(callback, "not found callback");
|
TimiException.required(callback, "not found callback");
|
||||||
if (callback.handler()) {
|
if (callback.handler()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new TimiException(TimiCode.ERROR, messageCode);
|
throw new TimiException(TimiCode.ERROR, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
public static void requiredTrue(CallbackReturn<Boolean> callback, String message, String msgKey) throws TimiException {
|
||||||
TimiException.required(callback, "not found callback");
|
TimiException.required(callback, "not found callback");
|
||||||
if (callback.handler()) {
|
if (callback.handler()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.imyeyu.java.bean.timi;
|
package com.imyeyu.java.bean.timi;
|
||||||
|
|
||||||
|
import com.imyeyu.java.bean.LanguageMsgMapping;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -10,33 +11,23 @@ import java.util.Map;
|
|||||||
/**
|
/**
|
||||||
* 通用接口返回对象
|
* 通用接口返回对象
|
||||||
*
|
*
|
||||||
* @param <T> 数据类型
|
|
||||||
*
|
|
||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2021-07-01 20:18
|
* @since 2021-07-01 20:18
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class TimiResponse<T> implements Serializable {
|
public class TimiResponse<T> implements Serializable, LanguageMsgMapping<TimiResponse<T>> {
|
||||||
|
|
||||||
/** 响应代码 */
|
/** 响应代码 */
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
protected Integer code;
|
protected Integer code;
|
||||||
|
|
||||||
/** 响应消息 */
|
/** 消息 */
|
||||||
@Getter
|
protected String msg;
|
||||||
@Setter
|
|
||||||
protected String message;
|
|
||||||
|
|
||||||
/** 响应消息代码 */
|
protected transient String msgKey;
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
protected String messageCode;
|
|
||||||
|
|
||||||
/** 消息插值参数 */
|
protected transient Map<String, Object> msgArgs;
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
protected transient Map<String, Object> messageArgs;
|
|
||||||
|
|
||||||
/** 数据体 */
|
/** 数据体 */
|
||||||
@Setter
|
@Setter
|
||||||
@@ -67,12 +58,12 @@ public class TimiResponse<T> implements Serializable {
|
|||||||
*
|
*
|
||||||
* @param code 代码
|
* @param code 代码
|
||||||
* @param data 数据体
|
* @param data 数据体
|
||||||
* @param message 响应消息
|
* @param msg 消息
|
||||||
*/
|
*/
|
||||||
public TimiResponse(TimiCode code, T data, String message) {
|
public TimiResponse(TimiCode code, T data, String msg) {
|
||||||
this.code = code.getValue();
|
this.code = code.getValue();
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.message = message;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true 为成功,code 为 20000 段 */
|
/** @return true 为成功,code 为 20000 段 */
|
||||||
@@ -95,41 +86,71 @@ public class TimiResponse<T> implements Serializable {
|
|||||||
if (code == null) {
|
if (code == null) {
|
||||||
throw new NullPointerException("unknow timi code: " + this.code);
|
throw new NullPointerException("unknow timi code: " + this.code);
|
||||||
}
|
}
|
||||||
return new TimiException(code, messageCode == null ? message : messageCode, messageArgs);
|
return code.toException(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置响应消息
|
* 追加消息(避免和泛型字符串冲突)
|
||||||
*
|
*
|
||||||
* @param message 响应消息
|
* @param msg 消息
|
||||||
* @return 本对象
|
* @return 本对象
|
||||||
*/
|
*/
|
||||||
public TimiResponse<T> message(String message) {
|
@Override
|
||||||
this.message = message;
|
public TimiResponse<T> msg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置响应消息代码
|
* 获取消息
|
||||||
*
|
*
|
||||||
* @param messageCode 响应消息代码
|
* @return 消息
|
||||||
* @return 本对象
|
|
||||||
*/
|
*/
|
||||||
public TimiResponse<T> messageCode(String messageCode) {
|
@Override
|
||||||
this.messageCode = messageCode;
|
public String getMsg() {
|
||||||
return this;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置响应消息代码和插值参数
|
* 设置消息
|
||||||
*
|
*
|
||||||
* @param messageCode 响应消息代码
|
* @param msg 消息
|
||||||
* @param messageArgs 插值参数
|
|
||||||
* @return 本对象
|
|
||||||
*/
|
*/
|
||||||
public TimiResponse<T> messageCode(String messageCode, Map<String, Object> messageArgs) {
|
@Override
|
||||||
this.messageCode = messageCode;
|
public void setMsg(String msg) {
|
||||||
this.messageArgs = messageArgs;
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiResponse<T> msgKey(String msgKey) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TimiResponse<T> msgKey(String msgKey, Map<String, Object> msgArgs) {
|
||||||
|
setMsgKey(msgKey, msgArgs);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMsgKey() {
|
||||||
|
return msgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgKey(String msgKey) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMsgKey(String msgKey, Map<String, Object> msgArgs) {
|
||||||
|
this.msgKey = msgKey;
|
||||||
|
this.msgArgs = msgArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getMsgArgs() {
|
||||||
|
return msgArgs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user