com.litongjava.table.utils.TableResultUtils Maven / Gradle / Ivy
package com.litongjava.table.utils;
import java.util.List;
import com.jfinal.kit.Kv;
import com.litongjava.db.TableResult;
import com.litongjava.db.activerecord.Record;
import com.litongjava.model.page.Page;
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);
Page pageData = new Page<>();
pageData.setTotalRow(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));
}
}