sql执行tinyInt字段适配
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
package com.test.common.utils.sql;
|
||||||
|
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author liangdaliang
|
||||||
|
* @Description:
|
||||||
|
* @date 2025-03-07 13:32
|
||||||
|
*/
|
||||||
|
public class TinyIntTypeAdapter extends TypeAdapter<Number> {
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, Number value) throws IOException {
|
||||||
|
if (value == null) {
|
||||||
|
out.nullValue();
|
||||||
|
} else {
|
||||||
|
out.value(value.intValue()); // 强制转换为整数
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Number read(JsonReader in) throws IOException {
|
||||||
|
if (in.peek() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return in.nextInt(); // 读取为整数
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +8,7 @@ import com.test.common.utils.DateUtils;
|
|||||||
import com.test.common.utils.JMeterUtil;
|
import com.test.common.utils.JMeterUtil;
|
||||||
import com.test.common.utils.MySQLExecutor;
|
import com.test.common.utils.MySQLExecutor;
|
||||||
import com.test.common.utils.StringUtils;
|
import com.test.common.utils.StringUtils;
|
||||||
|
import com.test.common.utils.sql.TinyIntTypeAdapter;
|
||||||
import com.test.test.domain.TestCase;
|
import com.test.test.domain.TestCase;
|
||||||
import com.test.test.domain.TestCaseResult;
|
import com.test.test.domain.TestCaseResult;
|
||||||
import com.test.test.domain.TestCaseStep;
|
import com.test.test.domain.TestCaseStep;
|
||||||
@@ -261,6 +262,8 @@ public class TestCaseServiceImpl implements ITestCaseService
|
|||||||
sqlResult.setColumnNameList(columnNameList);
|
sqlResult.setColumnNameList(columnNameList);
|
||||||
sqlResult.setResultMapList(resultMapList);
|
sqlResult.setResultMapList(resultMapList);
|
||||||
Gson gson = new GsonBuilder()
|
Gson gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Integer.class, new TinyIntTypeAdapter())
|
||||||
|
.registerTypeAdapter(int.class, new TinyIntTypeAdapter())
|
||||||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeConverter())
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeConverter())
|
||||||
.create();
|
.create();
|
||||||
testCaseResult.setSqlResult(gson.toJson(sqlResult));
|
testCaseResult.setSqlResult(gson.toJson(sqlResult));
|
||||||
|
|||||||
Reference in New Issue
Block a user