1. 程式人生 > >LayUI資料表格

LayUI資料表格

自用LayUI資料表格資料轉換

package com.util;

import java.util.List;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class LayuiToString {
	/**
	 * @param count
	 * @param list
	 * 總數和分頁的list
	 * @throws JsonProcessingException
	 */
	public
static String listToString(int count,List<?> list) throws JsonProcessingException{ ObjectMapper mapper = new ObjectMapper(); String jsonlist = mapper.writeValueAsString(list); StringBuffer sb = new StringBuffer(); sb.append("{\"count\":"); sb.append(count); sb.append(",\"code\":")
; sb.append(0); sb.append(",\"msg\":"); sb.append("null"); sb.append(",\"data\":"); sb.append(jsonlist); sb.append("}"); String jsonString = sb.toString(); return jsonString; } }