123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package com.primeton.dsp.dataservice.utils;
- import com.alibaba.fastjson.JSONObject;
- import java.util.List;
- import java.util.Map;
- /**
- *
- * 执行查询 SQL 输出的结果类。 返回查询行数、字段表头、数据行。
- *
- * <pre>
- *
- * Created by zhaopx.
- * User: zhaopx
- * Date: 2020-03-26
- * Time: 10:20
- *
- * </pre>
- *
- * @author zhaopx
- */
- public class QueryResult {
- /**
- * 是否成功
- */
- boolean success = true;
- /**
- * 当前是否成功
- */
- String message = "OK";
- /**
- * 执行的 SQL
- */
- String sql;
- /**
- * 执行查询结果集的行数
- */
- final int rows;
- /**
- * 表头,和类型
- */
- final List<Map<String, Object>> fields;
- /**
- * 数据集,多行
- */
- final List<Map<String, Object>> dataset;
- public QueryResult(List<Map<String, Object>> fields, List<Map<String, Object>> dataset) {
- this.fields = fields;
- this.dataset = dataset;
- this.rows = dataset.size();
- }
- public int getRows() {
- return rows;
- }
- public List<Map<String, Object>> getFields() {
- return fields;
- }
- public List<Map<String, Object>> getDataset() {
- return dataset;
- }
- /**
- * 返回一个结果
- * @return
- */
- public Map<String, Object> getOne() {
- return dataset.size() > 0 ? dataset.get(0) : null;
- }
- public boolean isSuccess() {
- return success;
- }
- public String getMessage() {
- return message;
- }
- public void setSuccess(boolean success) {
- this.success = success;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public String getSql() {
- return sql;
- }
- public void setSql(String sql) {
- this.sql = sql;
- }
- @Override
- public String toString() {
- return JSONObject.toJSONString(this);
- }
- }
|