增加RetException
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
```sql
|
||||
SELECT * FROM user WHERE 1=2 OR user_name = 'hello'
|
||||
```
|
||||
  有些场景要求参数是必需的,就需要使用$${}来保证不会进行。
|
||||
  有些场景要求参数是必需的,就需要使用$${}来校验参数是否必需。
|
||||
```sql
|
||||
DELETE FROM user WHERE user_name = $${bean.userName}
|
||||
```
|
||||
@@ -79,6 +79,6 @@ public interface ForumInfoMapper extends BaseMapper<ForumInfo> {
|
||||
@Sql("UPDATE forum_section s "
|
||||
+ " SET s.forum_sectionid = '' "
|
||||
+ " WHERE s.forum_section_color = $${bean.forumSectionColor}")
|
||||
public int updateForumResult(ForumBean bean);
|
||||
public int updateForumResult(@Param("bean") ForumBean bean0);
|
||||
}
|
||||
```
|
||||
43
src/main/java/org/redkale/service/RetException.java
Normal file
43
src/main/java/org/redkale/service/RetException.java
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.service;
|
||||
|
||||
import org.redkale.util.RedkaleException;
|
||||
|
||||
/**
|
||||
* 错误码自定义异常类
|
||||
*
|
||||
* <p>详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class RetException extends RedkaleException {
|
||||
|
||||
private int code;
|
||||
|
||||
public RetException(int code) {
|
||||
super(RetCodes.retInfo(code));
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public RetException(int code, String message) {
|
||||
super(message);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public RetException(int code, Throwable cause) {
|
||||
super(RetCodes.retInfo(code), cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public RetException(int code, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -126,11 +126,21 @@ public class RetResult<T> implements Serializable {
|
||||
return new RetResult(retcode, retinfo);
|
||||
}
|
||||
|
||||
// @since 2.8.0
|
||||
public static <T> RetResult<T> fail(RetException ex) {
|
||||
return new RetResult(ex.getCode(), ex.getMessage());
|
||||
}
|
||||
|
||||
// @since 2.7.0
|
||||
public static <T> CompletableFuture<RetResult<T>> failFuture(int retcode, String retinfo) {
|
||||
return CompletableFuture.completedFuture(new RetResult(retcode, retinfo));
|
||||
}
|
||||
|
||||
// @since 2.8.0
|
||||
public static <T> CompletableFuture<RetResult<T>> failFuture(RetException ex) {
|
||||
return CompletableFuture.completedFuture(new RetResult(ex.getCode(), ex.getMessage()));
|
||||
}
|
||||
|
||||
// @since 2.7.0
|
||||
public T join() {
|
||||
if (isSuccess()) {
|
||||
|
||||
Reference in New Issue
Block a user