mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add return
This commit is contained in:
parent
c402d7cbc2
commit
ab195f4e67
@ -3,13 +3,14 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.6.7 (2021-06-04)
|
||||
# 5.6.7 (2021-06-06)
|
||||
|
||||
### 🐣新特性
|
||||
* 【core 】 CharSequenceUtil增加join重载(issue#I3TFJ5@Gitee)
|
||||
* 【http 】 HttpRequest增加form方法重载(pr#337@Gitee)
|
||||
* 【http 】 ImgUtil增加getMainColor方法(pr#338@Gitee)
|
||||
* 【core 】 改进TreeUtil.buid算法性能(pr#1594@Github)
|
||||
* 【core 】 CsvConfig的setXXX返回this(issue#I3UIQF@Gitee)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【core 】 修复FileUtil.normalize去掉末尾空格问题(issue#1603@Github)
|
||||
|
@ -30,27 +30,33 @@ public class CsvConfig implements Serializable {
|
||||
* 设置字段分隔符,默认逗号','
|
||||
*
|
||||
* @param fieldSeparator 字段分隔符,默认逗号','
|
||||
* @return this
|
||||
*/
|
||||
public void setFieldSeparator(final char fieldSeparator) {
|
||||
public CsvConfig setFieldSeparator(final char fieldSeparator) {
|
||||
this.fieldSeparator = fieldSeparator;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 文本分隔符,文本包装符,默认双引号'"'
|
||||
*
|
||||
* @param textDelimiter 文本分隔符,文本包装符,默认双引号'"'
|
||||
* @return this
|
||||
*/
|
||||
public void setTextDelimiter(char textDelimiter) {
|
||||
public CsvConfig setTextDelimiter(char textDelimiter) {
|
||||
this.textDelimiter = textDelimiter;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 注释符号,用于区分注释行
|
||||
*
|
||||
* @param commentCharacter 注释符号,用于区分注释行
|
||||
* @return this
|
||||
* @since 5.5.7
|
||||
*/
|
||||
public void setCommentCharacter(char commentCharacter) {
|
||||
public CsvConfig setCommentCharacter(char commentCharacter) {
|
||||
this.commentCharacter = commentCharacter;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* CSV读取配置项
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@ -20,7 +20,7 @@ public class CsvReadConfig extends CsvConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 默认配置
|
||||
*
|
||||
*
|
||||
* @return 默认配置
|
||||
*/
|
||||
public static CsvReadConfig defaultConfig() {
|
||||
@ -29,28 +29,34 @@ public class CsvReadConfig extends CsvConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置是否首行做为标题行,默认false
|
||||
*
|
||||
*
|
||||
* @param containsHeader 是否首行做为标题行,默认false
|
||||
* @return this
|
||||
*/
|
||||
public void setContainsHeader(boolean containsHeader) {
|
||||
public CsvReadConfig setContainsHeader(boolean containsHeader) {
|
||||
this.containsHeader = containsHeader;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否跳过空白行,默认true
|
||||
*
|
||||
*
|
||||
* @param skipEmptyRows 是否跳过空白行,默认true
|
||||
* @return this
|
||||
*/
|
||||
public void setSkipEmptyRows(boolean skipEmptyRows) {
|
||||
public CsvReadConfig setSkipEmptyRows(boolean skipEmptyRows) {
|
||||
this.skipEmptyRows = skipEmptyRows;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置每行字段个数不同时是否抛出异常,默认false
|
||||
*
|
||||
*
|
||||
* @param errorOnDifferentFieldCount 每行字段个数不同时是否抛出异常,默认false
|
||||
* @return this
|
||||
*/
|
||||
public void setErrorOnDifferentFieldCount(boolean errorOnDifferentFieldCount) {
|
||||
public CsvReadConfig setErrorOnDifferentFieldCount(boolean errorOnDifferentFieldCount) {
|
||||
this.errorOnDifferentFieldCount = errorOnDifferentFieldCount;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,29 @@
|
||||
package cn.hutool.core.text.csv;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* CSV写出配置项
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public class CsvWriteConfig extends CsvConfig implements Serializable {
|
||||
private static final long serialVersionUID = 5396453565371560052L;
|
||||
|
||||
/** 是否始终使用文本分隔符,文本包装符,默认false,按需添加 */
|
||||
/**
|
||||
* 是否始终使用文本分隔符,文本包装符,默认false,按需添加
|
||||
*/
|
||||
protected boolean alwaysDelimitText;
|
||||
/** 换行符 */
|
||||
/**
|
||||
* 换行符
|
||||
*/
|
||||
protected char[] lineDelimiter = {CharUtil.CR, CharUtil.LF};
|
||||
|
||||
/**
|
||||
* 默认配置
|
||||
*
|
||||
*
|
||||
* @return 默认配置
|
||||
*/
|
||||
public static CsvWriteConfig defaultConfig() {
|
||||
@ -29,19 +32,23 @@ public class CsvWriteConfig extends CsvConfig implements Serializable {
|
||||
|
||||
/**
|
||||
* 设置是否始终使用文本分隔符,文本包装符,默认false,按需添加
|
||||
*
|
||||
*
|
||||
* @param alwaysDelimitText 是否始终使用文本分隔符,文本包装符,默认false,按需添加
|
||||
* @return this
|
||||
*/
|
||||
public void setAlwaysDelimitText(boolean alwaysDelimitText) {
|
||||
public CsvWriteConfig setAlwaysDelimitText(boolean alwaysDelimitText) {
|
||||
this.alwaysDelimitText = alwaysDelimitText;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置换行符
|
||||
*
|
||||
*
|
||||
* @param lineDelimiter 换行符
|
||||
* @return this
|
||||
*/
|
||||
public void setLineDelimiter(char[] lineDelimiter) {
|
||||
public CsvWriteConfig setLineDelimiter(char[] lineDelimiter) {
|
||||
this.lineDelimiter = lineDelimiter;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CsvReaderTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void readTest() {
|
||||
CsvReader reader = new CsvReader();
|
||||
@ -85,4 +85,16 @@ public class CsvReaderTest {
|
||||
Console.log(strings);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void readTest3(){
|
||||
final CsvReadConfig csvReadConfig = CsvReadConfig.defaultConfig();
|
||||
csvReadConfig.setContainsHeader(true);
|
||||
final CsvReader reader = CsvUtil.getReader(csvReadConfig);
|
||||
final CsvData read = reader.read(FileUtil.file("d:/test/ceshi.csv"));
|
||||
for (CsvRow row : read) {
|
||||
Console.log(row.getByName("案件ID"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user