Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.对某些需要输出null值字段的需求,增加输出null值的开关 #770

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions APIJSONORM/src/main/java/apijson/JSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.JSONReader;

import java.util.List;

Expand Down Expand Up @@ -203,7 +202,7 @@ public static String toJSONString(Object obj, SerializerFeature... features) {
try {
return com.alibaba.fastjson.JSON.toJSONString(obj, features);
} catch (Exception e) {
Log.e(TAG, "parseArray catch \n" + e.getMessage());
Log.e(TAG, "toJSONString catch \n" + e.getMessage());
}
return null;
}
Expand Down
43 changes: 18 additions & 25 deletions APIJSONORM/src/main/java/apijson/orm/AbstractSQLExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,32 @@

package apijson.orm;

import apijson.*;
import apijson.orm.Join.On;
import apijson.orm.exception.NotExistException;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Connection;
import java.util.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Savepoint;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.*;
import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.Year;
import java.util.Date;
import java.util.*;
import java.util.Map.Entry;
import java.util.regex.Pattern;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import apijson.JSONResponse;
import apijson.Log;
import apijson.NotNull;
import apijson.RequestMethod;
import apijson.StringUtil;
import apijson.orm.Join.On;
import apijson.orm.exception.NotExistException;

/**executor for query(read) or update(write) MySQL database
* @author Lemon
*/
public abstract class AbstractSQLExecutor<T extends Object> implements SQLExecutor<T> {
private static final String TAG = "AbstractSQLExecutor";

//是否返回 值为null的字段
public static boolean ENABLE_OUTPUT_NULL_COLUMN = false;
public static String KEY_RAW_LIST = "@RAW@LIST"; // 避免和字段命名冲突,不用 $RAW@LIST$ 是因为 $ 会在 fastjson 内部转义,浪费性能

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

// 主表必须 put 至少一个 null 进去,否则全部字段为 null 都不 put 会导致中断后续正常返回值
if (value != null || (join == null && table.isEmpty())) {
if (value != null) {
table.put(label, value);
} else{
if (join == null && table.isEmpty()) {
table.put(label, null);
} else if (ENABLE_OUTPUT_NULL_COLUMN) {
table.put(label, null);
}
}

return table;
Expand Down