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.activerecord.Page;
import com.litongjava.db.activerecord.Record;
import com.litongjava.table.model.DbPage;
import com.litongjava.table.model.TableResult;

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

    DbPage pageData = new DbPage<>();
    pageData.setTotal(totalRow);
    pageData.setList(newList);

    return new TableResult<>(jsonBean.getCode(), jsonBean.getMsg(), pageData);

  }

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

  }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy