All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.table.utils.TableResultUtils Maven / Gradle / Ivy

There is a newer version: 1.4.8
Show newest version
package com.litongjava.table.utils;

import java.util.List;

import com.jfinal.kit.Kv;
import com.litongjava.db.TableResult;
import com.litongjava.db.activerecord.Row;
import com.litongjava.kit.RowUtils;
import com.litongjava.model.page.DbPage;
import com.litongjava.model.page.Page;

public class TableResultUtils {

  public static TableResult recordToKv(TableResult jsonBean) {
    Row data = jsonBean.getData();
    if (data == null) {
      return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg());
    } else {
      return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg(), RowUtils.recordToKv(data, false));
    }
  }

  public static TableResult recordToKv(TableResult jsonBean, boolean underscoreToCamel) {
    Row data = jsonBean.getData();
    if (data == null) {
      return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg());
    } else {
      return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg(), RowUtils.recordToKv(data, underscoreToCamel));
    }
  }

  public static TableResult> pageToDbPage(TableResult> jsonBean, boolean underscoreToCamel) {
    int totalRow = jsonBean.getData().getTotalRow();
    List list = jsonBean.getData().getList();
    List newList = RowUtils.recordsToKv(list, underscoreToCamel);

    DbPage pageData = new DbPage<>();
    pageData.setTotal(totalRow);
    pageData.setList(newList);
    return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg(), pageData);
  }

  public static TableResult> recordsToKv(TableResult> jsonBean, boolean underscoreToCamel) {
    return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg(), RowUtils.recordsToKv(jsonBean.getData(), underscoreToCamel));
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy