Compare commits
5
Commits
v0.0.5
..
02a13377bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02a13377bc | ||
|
|
8e1a1a1673 | ||
|
|
99fb2f62f2 | ||
|
|
e2bba01daf | ||
|
|
c99df7370c |
@@ -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.5</version>
|
<version>0.0.7</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通用工具
|
* 通用工具
|
||||||
@@ -81,6 +80,15 @@ 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)) {
|
||||||
@@ -105,7 +113,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 Objects.requireNonNullElse(obj, defaultObj);
|
return obj != null ? obj : defaultObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -30,4 +30,22 @@ 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
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).msg(toString());
|
return new TimiResponse<>(this).message(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -11,81 +10,53 @@ import java.util.Map;
|
|||||||
* @author 夜雨
|
* @author 夜雨
|
||||||
* @since 2023-04-27 15:55
|
* @since 2023-04-27 15:55
|
||||||
*/
|
*/
|
||||||
public class TimiError extends AssertionError implements LanguageMsgMapping<TimiError> {
|
@Getter
|
||||||
|
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;
|
this(code, code.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造器
|
* 构造器
|
||||||
*
|
*
|
||||||
* @param code 代码
|
* @param code 代码
|
||||||
* @param msg 消息
|
* @param messageCode 消息代码
|
||||||
*/
|
*/
|
||||||
public TimiError(TimiCode code, String msg) {
|
public TimiError(TimiCode code, String messageCode) {
|
||||||
super(msg);
|
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 响应
|
||||||
|
*/
|
||||||
public TimiResponse<?> toResponse() {
|
public TimiResponse<?> toResponse() {
|
||||||
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey, msgArgs);
|
return new TimiResponse<>(code).messageCode(messageCode, messageArgs);
|
||||||
}
|
|
||||||
|
|
||||||
@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,159 +2,133 @@ 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
|
||||||
*/
|
*/
|
||||||
public class TimiException extends RuntimeException implements LanguageMsgMapping<TimiException> {
|
@Getter
|
||||||
|
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;
|
this(code, code.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造器
|
* 构造器
|
||||||
*
|
*
|
||||||
* @param code 代码
|
* @param code 代码
|
||||||
* @param msg 消息
|
* @param messageCode 消息代码
|
||||||
*/
|
*/
|
||||||
public TimiException(TimiCode code, String msg) {
|
public TimiException(TimiCode code, String messageCode) {
|
||||||
super(msg);
|
this(code, messageCode, (Map<String, Object>) null);
|
||||||
this.code = code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构造器
|
* 构造器
|
||||||
*
|
*
|
||||||
* @param code 代码
|
* @param code 代码
|
||||||
* @param msg 消息
|
* @param messageCode 消息代码
|
||||||
|
* @param messageArgs 消息插值参数
|
||||||
*/
|
*/
|
||||||
public TimiException(TimiCode code, String msg, Throwable e) {
|
public TimiException(TimiCode code, String messageCode, Map<String, Object> messageArgs) {
|
||||||
super(msg, e);
|
super(messageCode);
|
||||||
this.code = code;
|
this.code = code;
|
||||||
|
this.messageCode = messageCode;
|
||||||
|
this.messageArgs = messageArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造器
|
||||||
|
*
|
||||||
|
* @param code 代码
|
||||||
|
* @param messageCode 消息代码
|
||||||
|
* @param e 异常
|
||||||
|
*/
|
||||||
|
public TimiException(TimiCode code, String messageCode, Throwable e) {
|
||||||
|
super(messageCode, e);
|
||||||
|
this.code = code;
|
||||||
|
this.messageCode = messageCode;
|
||||||
|
this.messageArgs = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转为通用响应
|
||||||
|
*
|
||||||
|
* @return 响应
|
||||||
|
*/
|
||||||
public TimiResponse<?> toResponse() {
|
public TimiResponse<?> toResponse() {
|
||||||
return new TimiResponse<>(code).msg(getMessage()).msgKey(msgKey, msgArgs);
|
return new TimiResponse<>(code).messageCode(messageCode, messageArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public static <T> T required(T t, String messageCode) {
|
||||||
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, message);
|
throw new TimiException(TimiCode.ARG_MISS, messageCode);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T required(T t, String message, String msgKey) {
|
public static <T> T required(T t, String messageCode, Map<String, Object> messageArgs) {
|
||||||
if (TimiJava.isEmpty(t)) {
|
if (TimiJava.isEmpty(t)) {
|
||||||
throw new TimiException(TimiCode.ARG_MISS, message).msgKey(msgKey);
|
throw new TimiException(TimiCode.ARG_MISS, messageCode, messageArgs);
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void requiredNull(T t, String message) throws TimiException {
|
public static <T> void requiredNull(T t, String messageCode) throws TimiException {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
throw new TimiException(TimiCode.ERROR, message);
|
throw new TimiException(TimiCode.ERROR, messageCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void requiredNull(T t, String message, String msgKey) throws TimiException {
|
public static <T> void requiredNull(T t, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(boolean bool, String message) throws TimiException {
|
public static void requiredTrue(boolean bool, String messageCode) throws TimiException {
|
||||||
if (bool) {
|
if (bool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new TimiException(TimiCode.ERROR, message);
|
throw new TimiException(TimiCode.ERROR, messageCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(boolean bool, String message, String msgKey) throws TimiException {
|
public static void requiredTrue(boolean bool, String messageCode, Map<String, Object> messageArgs) throws TimiException {
|
||||||
if (bool) {
|
if (bool) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new TimiException(TimiCode.ERROR, message).msgKey(msgKey);
|
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String message) throws TimiException {
|
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode) 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, message);
|
throw new TimiException(TimiCode.ERROR, messageCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void requiredTrue(CallbackReturn<Boolean> callback, String message, String msgKey) throws TimiException {
|
public static void requiredTrue(CallbackReturn<Boolean> callback, String messageCode, Map<String, Object> messageArgs) 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, message).msgKey(msgKey);
|
throw new TimiException(TimiCode.ERROR, messageCode, messageArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
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;
|
||||||
@@ -11,23 +10,33 @@ 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, LanguageMsgMapping<TimiResponse<T>> {
|
public class TimiResponse<T> implements Serializable {
|
||||||
|
|
||||||
/** 响应代码 */
|
/** 响应代码 */
|
||||||
@Setter
|
@Setter
|
||||||
@Getter
|
@Getter
|
||||||
protected Integer code;
|
protected Integer code;
|
||||||
|
|
||||||
/** 消息 */
|
/** 响应消息 */
|
||||||
protected String msg;
|
@Getter
|
||||||
|
@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
|
||||||
@@ -58,12 +67,12 @@ public class TimiResponse<T> implements Serializable, LanguageMsgMapping<TimiRes
|
|||||||
*
|
*
|
||||||
* @param code 代码
|
* @param code 代码
|
||||||
* @param data 数据体
|
* @param data 数据体
|
||||||
* @param msg 消息
|
* @param message 响应消息
|
||||||
*/
|
*/
|
||||||
public TimiResponse(TimiCode code, T data, String msg) {
|
public TimiResponse(TimiCode code, T data, String message) {
|
||||||
this.code = code.getValue();
|
this.code = code.getValue();
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.msg = msg;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return true 为成功,code 为 20000 段 */
|
/** @return true 为成功,code 为 20000 段 */
|
||||||
@@ -86,71 +95,41 @@ public class TimiResponse<T> implements Serializable, LanguageMsgMapping<TimiRes
|
|||||||
if (code == null) {
|
if (code == null) {
|
||||||
throw new NullPointerException("unknow timi code: " + this.code);
|
throw new NullPointerException("unknow timi code: " + this.code);
|
||||||
}
|
}
|
||||||
return code.toException(msg);
|
return new TimiException(code, messageCode == null ? message : messageCode, messageArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 追加消息(避免和泛型字符串冲突)
|
* 设置响应消息
|
||||||
*
|
*
|
||||||
* @param msg 消息
|
* @param message 响应消息
|
||||||
* @return 本对象
|
* @return 本对象
|
||||||
*/
|
*/
|
||||||
@Override
|
public TimiResponse<T> message(String message) {
|
||||||
public TimiResponse<T> msg(String msg) {
|
this.message = message;
|
||||||
this.msg = msg;
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取消息
|
* 设置响应消息代码
|
||||||
*
|
*
|
||||||
* @return 消息
|
* @param messageCode 响应消息代码
|
||||||
|
* @return 本对象
|
||||||
*/
|
*/
|
||||||
@Override
|
public TimiResponse<T> messageCode(String messageCode) {
|
||||||
public String getMsg() {
|
this.messageCode = messageCode;
|
||||||
return msg;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置消息
|
* 设置响应消息代码和插值参数
|
||||||
*
|
*
|
||||||
* @param msg 消息
|
* @param messageCode 响应消息代码
|
||||||
|
* @param messageArgs 插值参数
|
||||||
|
* @return 本对象
|
||||||
*/
|
*/
|
||||||
@Override
|
public TimiResponse<T> messageCode(String messageCode, Map<String, Object> messageArgs) {
|
||||||
public void setMsg(String msg) {
|
this.messageCode = messageCode;
|
||||||
this.msg = msg;
|
this.messageArgs = messageArgs;
|
||||||
}
|
|
||||||
|
|
||||||
@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