@Test public void importBean() { CsvBean bean = createBean("小明", 25, "自由", "某某小区"); try { processor.importBean(bean, testBeanPath); } catch (IOException e) { logger.error("", e); } }
@Override public void importBean(Object bean, String filePath) throws IOException { Class<?> clazz = bean.getClass(); List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); String data = toCsvLine(list, bean); List<String> titles = processeCache.getTitles(clazz); if (CollectionUtil.isEmpty(titles)) { WriterUtil.writeLinesAndClose(filePath, data, false, GBK); return; } String title = CsvUtil.toCsvString(titles); WriterUtil.writeLinesAndClose(filePath, false, GBK, new Object[] { title, data }); }
CsvProcessor implements FileProcessor { @Override public void importBean(Object bean, String filePath) throws IOException { Class<?> clazz = bean.getClass(); List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); String data = toCsvLine(list, bean); List<String> titles = processeCache.getTitles(clazz); if (CollectionUtil.isEmpty(titles)) { WriterUtil.writeLinesAndClose(filePath, data, false, GBK); return; } String title = CsvUtil.toCsvString(titles); WriterUtil.writeLinesAndClose(filePath, false, GBK, new Object[] { title, data }); } }
CsvProcessor implements FileProcessor { @Override public void importBean(Object bean, String filePath) throws IOException { Class<?> clazz = bean.getClass(); List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); String data = toCsvLine(list, bean); List<String> titles = processeCache.getTitles(clazz); if (CollectionUtil.isEmpty(titles)) { WriterUtil.writeLinesAndClose(filePath, data, false, GBK); return; } String title = CsvUtil.toCsvString(titles); WriterUtil.writeLinesAndClose(filePath, false, GBK, new Object[] { title, data }); }  }
CsvProcessor implements FileProcessor { @Override public void importBean(Object bean, String filePath) throws IOException { Class<?> clazz = bean.getClass(); List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); String data = toCsvLine(list, bean); List<String> titles = processeCache.getTitles(clazz); if (CollectionUtil.isEmpty(titles)) { WriterUtil.writeLinesAndClose(filePath, data, false, GBK); return; } String title = CsvUtil.toCsvString(titles); WriterUtil.writeLinesAndClose(filePath, false, GBK, new Object[] { title, data }); }  @Override void importBean(Object bean, String filePath); @Override void importBeans(Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(String[] contents, String filePath); @Override void importBeans(List<String> contents, String filePath); @Override T exportBean(Class<T> clazz, String filePath); @Override List<T> exportBeans(Class<T> clazz, String filePath); @Override void importBeans(String[] headers, Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(ListMap<String, String> headers, Class<?> clazz, Object[] beans, String filePath); @Override List<String> collectData(FileBeanInfo beanInfo); @Override void importBeans(FileBeanInfo beanInfo, String filePath); @Override ByteArray toByteArray(FileBeanInfo beanInfo); @Override ByteArray toByteArray(List<String> contents); }
CsvProcessor implements FileProcessor { @Override public void importBean(Object bean, String filePath) throws IOException { Class<?> clazz = bean.getClass(); List<FieldDesc> list = processeCache.getFieldDescs(clazz); Assert.assertTrue(CollectionUtil.isNotEmpty(list), "FieldDesc is not empty"); String data = toCsvLine(list, bean); List<String> titles = processeCache.getTitles(clazz); if (CollectionUtil.isEmpty(titles)) { WriterUtil.writeLinesAndClose(filePath, data, false, GBK); return; } String title = CsvUtil.toCsvString(titles); WriterUtil.writeLinesAndClose(filePath, false, GBK, new Object[] { title, data }); }  @Override void importBean(Object bean, String filePath); @Override void importBeans(Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(String[] contents, String filePath); @Override void importBeans(List<String> contents, String filePath); @Override T exportBean(Class<T> clazz, String filePath); @Override List<T> exportBeans(Class<T> clazz, String filePath); @Override void importBeans(String[] headers, Class<?> clazz, Object[] beans, String filePath); @Override void importBeans(ListMap<String, String> headers, Class<?> clazz, Object[] beans, String filePath); @Override List<String> collectData(FileBeanInfo beanInfo); @Override void importBeans(FileBeanInfo beanInfo, String filePath); @Override ByteArray toByteArray(FileBeanInfo beanInfo); @Override ByteArray toByteArray(List<String> contents);  }