|
5 | 5 |
|
6 | 6 | package apijson.orm; |
7 | 7 |
|
| 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 | + |
8 | 14 | import java.io.BufferedReader; |
9 | 15 | import java.math.BigDecimal; |
10 | 16 | 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.*; |
23 | 18 | import java.time.DayOfWeek; |
24 | 19 | import java.time.LocalDateTime; |
25 | 20 | import java.time.Month; |
26 | 21 | import java.time.Year; |
| 22 | +import java.util.Date; |
| 23 | +import java.util.*; |
27 | 24 | import java.util.Map.Entry; |
28 | 25 | import java.util.regex.Pattern; |
29 | 26 |
|
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 | | - |
41 | 27 | /**executor for query(read) or update(write) MySQL database |
42 | 28 | * @author Lemon |
43 | 29 | */ |
44 | 30 | public abstract class AbstractSQLExecutor<T extends Object> implements SQLExecutor<T> { |
45 | 31 | private static final String TAG = "AbstractSQLExecutor"; |
46 | | - |
| 32 | + //是否返回 值为null的字段 |
| 33 | + public static boolean ENABLE_OUTPUT_NULL_COLUMN = false; |
47 | 34 | public static String KEY_RAW_LIST = "@RAW@LIST"; // 避免和字段命名冲突,不用 $RAW@LIST$ 是因为 $ 会在 fastjson 内部转义,浪费性能 |
48 | 35 |
|
49 | 36 | private Parser<T> parser; |
@@ -918,8 +905,14 @@ protected JSONObject onPutColumn(@NotNull SQLConfig<T> config, @NotNull ResultSe |
918 | 905 | Object value = getValue(config, rs, rsmd, tablePosition, table, columnIndex, label, childMap); |
919 | 906 |
|
920 | 907 | // 主表必须 put 至少一个 null 进去,否则全部字段为 null 都不 put 会导致中断后续正常返回值 |
921 | | - if (value != null || (join == null && table.isEmpty())) { |
| 908 | + if (value != null) { |
922 | 909 | 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 | + } |
923 | 916 | } |
924 | 917 |
|
925 | 918 | return table; |
|
0 commit comments