Skip to content

Commit 24f357f

Browse files
authored
增加输出null值的开关,感谢 calmcc 的贡献 #770
#770
2 parents 781b0fe + 6ea0b9b commit 24f357f

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

APIJSONORM/src/main/java/apijson/JSON.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.alibaba.fastjson.JSONObject;
99
import com.alibaba.fastjson.parser.Feature;
1010
import com.alibaba.fastjson.serializer.SerializerFeature;
11-
import com.alibaba.fastjson.JSONReader;
1211

1312
import java.util.List;
1413

@@ -203,7 +202,7 @@ public static String toJSONString(Object obj, SerializerFeature... features) {
203202
try {
204203
return com.alibaba.fastjson.JSON.toJSONString(obj, features);
205204
} catch (Exception e) {
206-
Log.e(TAG, "parseArray catch \n" + e.getMessage());
205+
Log.e(TAG, "toJSONString catch \n" + e.getMessage());
207206
}
208207
return null;
209208
}

APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java

+18-25
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,32 @@
55

66
package apijson.orm;
77

8+
import apijson.*;
9+
import apijson.orm.Join.On;
10+
import apijson.orm.exception.NotExistException;
11+
import com.alibaba.fastjson.JSON;
12+
import com.alibaba.fastjson.JSONObject;
13+
814
import java.io.BufferedReader;
915
import java.math.BigDecimal;
1016
import java.math.BigInteger;
11-
import java.sql.Blob;
12-
import java.sql.Clob;
13-
import java.sql.Connection;
14-
import java.util.*;
15-
import java.sql.DriverManager;
16-
import java.sql.PreparedStatement;
17-
import java.sql.ResultSet;
18-
import java.sql.ResultSetMetaData;
19-
import java.sql.SQLException;
20-
import java.sql.Savepoint;
21-
import java.sql.Statement;
22-
import java.sql.Timestamp;
17+
import java.sql.*;
2318
import java.time.DayOfWeek;
2419
import java.time.LocalDateTime;
2520
import java.time.Month;
2621
import java.time.Year;
22+
import java.util.Date;
23+
import java.util.*;
2724
import java.util.Map.Entry;
2825
import java.util.regex.Pattern;
2926

30-
import com.alibaba.fastjson.JSON;
31-
import com.alibaba.fastjson.JSONObject;
32-
33-
import apijson.JSONResponse;
34-
import apijson.Log;
35-
import apijson.NotNull;
36-
import apijson.RequestMethod;
37-
import apijson.StringUtil;
38-
import apijson.orm.Join.On;
39-
import apijson.orm.exception.NotExistException;
40-
4127
/**executor for query(read) or update(write) MySQL database
4228
* @author Lemon
4329
*/
4430
public abstract class AbstractSQLExecutor<T extends Object> implements SQLExecutor<T> {
4531
private static final String TAG = "AbstractSQLExecutor";
46-
32+
//是否返回 值为null的字段
33+
public static boolean ENABLE_OUTPUT_NULL_COLUMN = false;
4734
public static String KEY_RAW_LIST = "@RAW@LIST"; // 避免和字段命名冲突,不用 $RAW@LIST$ 是因为 $ 会在 fastjson 内部转义,浪费性能
4835

4936
private Parser<T> parser;
@@ -918,8 +905,14 @@ protected JSONObject onPutColumn(@NotNull SQLConfig<T> config, @NotNull ResultSe
918905
Object value = getValue(config, rs, rsmd, tablePosition, table, columnIndex, label, childMap);
919906

920907
// 主表必须 put 至少一个 null 进去,否则全部字段为 null 都不 put 会导致中断后续正常返回值
921-
if (value != null || (join == null && table.isEmpty())) {
908+
if (value != null) {
922909
table.put(label, value);
910+
} else{
911+
if (join == null && table.isEmpty()) {
912+
table.put(label, null);
913+
} else if (ENABLE_OUTPUT_NULL_COLUMN) {
914+
table.put(label, null);
915+
}
923916
}
924917

925918
return table;

0 commit comments

Comments
 (0)