diff --git a/hutool-json/src/test/java/org/dromara/hutool/json/JSONUtilTest.java b/hutool-json/src/test/java/org/dromara/hutool/json/JSONUtilTest.java index e3d3882a8..f2acb147c 100644 --- a/hutool-json/src/test/java/org/dromara/hutool/json/JSONUtilTest.java +++ b/hutool-json/src/test/java/org/dromara/hutool/json/JSONUtilTest.java @@ -352,4 +352,11 @@ public class JSONUtilTest { final String jsonStr = JSONUtil.toJsonStr(true); Assertions.assertEquals("true", jsonStr); } + + @Test + public void issue3540Test() { + final Long userId=10101010L; + final String jsonStr = JSONUtil.toJsonStr(userId); + Assertions.assertEquals("10101010", jsonStr); + } } diff --git a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java index 61cf3e6ef..bf43073f9 100644 --- a/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java +++ b/hutool-poi/src/main/java/org/dromara/hutool/poi/excel/ExcelWriter.java @@ -81,6 +81,7 @@ public class ExcelWriter extends ExcelBase { private final AtomicInteger currentRow; // region Constructors + /** * 构造,默认生成xls格式的Excel文件
* 此构造不传入写出的Excel文件路径,只能调用{@link #flush(OutputStream)}方法写出到流
@@ -449,6 +450,7 @@ public class ExcelWriter extends ExcelBase { /** * 设置是否只保留别名中的字段值,如果为true,则不设置alias的字段将不被输出,false表示原样输出 + * Bean中设置@Alias时,setOnlyAlias是无效的,这个参数只和addHeaderAlias配合使用,原因是注解是Bean内部的操作,而addHeaderAlias是Writer的操作,不互通。 * * @param isOnlyAlias 是否只保留别名中的字段值 * @return this @@ -799,6 +801,7 @@ public class ExcelWriter extends ExcelBase { } // region ----- writeImg + /** * 写出数据,本方法只是将数据写入Workbook中的Sheet,并不写出到文件
* 添加图片到当前sheet中 / 默认图片类型png / 默认的起始坐标和结束坐标都为0 @@ -899,6 +902,7 @@ public class ExcelWriter extends ExcelBase { // endregion // region ----- writeRow + /** * 写出一行标题数据
* 本方法只是将数据写入Workbook中的Sheet,并不写出到文件
@@ -1070,6 +1074,7 @@ public class ExcelWriter extends ExcelBase { // endregion // region ----- writeCol + /** * 从第1列开始按列写入数据(index 从0开始)
* 本方法只是将数据写入Workbook中的Sheet,并不写出到文件
@@ -1080,7 +1085,7 @@ public class ExcelWriter extends ExcelBase { * @param isWriteKeyAsHead 是否将Map的Key作为表头输出,如果为True第一行为表头,紧接着为values * @return this */ - public ExcelWriter writeCol(final Map> colMap, final boolean isWriteKeyAsHead){ + public ExcelWriter writeCol(final Map> colMap, final boolean isWriteKeyAsHead) { return writeCol(colMap, 0, isWriteKeyAsHead); } @@ -1095,12 +1100,12 @@ public class ExcelWriter extends ExcelBase { * @param isWriteKeyAsHead 是否将Map的Key作为表头输出,如果为True第一行为表头,紧接着为values * @return this */ - public ExcelWriter writeCol(final Map> colMap, int startColIndex, final boolean isWriteKeyAsHead){ + public ExcelWriter writeCol(final Map> colMap, int startColIndex, final boolean isWriteKeyAsHead) { for (final Object k : colMap.keySet()) { final Iterable v = colMap.get(k); - if(v != null){ - writeCol(isWriteKeyAsHead?k:null,startColIndex, v, startColIndex != colMap.size() - 1); - startColIndex ++; + if (v != null) { + writeCol(isWriteKeyAsHead ? k : null, startColIndex, v, startColIndex != colMap.size() - 1); + startColIndex++; } } return this; @@ -1118,8 +1123,8 @@ public class ExcelWriter extends ExcelBase { * @param isResetRowIndex 如果为true,写入完毕后Row index 将会重置为写入之前的未知,如果为false,写入完毕后Row index将会在写完的数据下方 * @return this */ - public ExcelWriter writeCol(final Object headerVal, final Iterable colData, final boolean isResetRowIndex){ - return writeCol(headerVal,0,colData,isResetRowIndex); + public ExcelWriter writeCol(final Object headerVal, final Iterable colData, final boolean isResetRowIndex) { + return writeCol(headerVal, 0, colData, isResetRowIndex); } /** @@ -1134,18 +1139,18 @@ public class ExcelWriter extends ExcelBase { * @param isResetRowIndex 如果为true,写入完毕后Row index 将会重置为写入之前的未知,如果为false,写入完毕后Row index将会在写完的数据下方 * @return this */ - public ExcelWriter writeCol(final Object headerVal, final int colIndex, final Iterable colData, final boolean isResetRowIndex){ + public ExcelWriter writeCol(final Object headerVal, final int colIndex, final Iterable colData, final boolean isResetRowIndex) { Assert.isFalse(this.isClosed, "ExcelWriter has been closed!"); int currentRowIndex = currentRow.get(); - if(null != headerVal){ - writeCellValue(colIndex, currentRowIndex, headerVal,true); + if (null != headerVal) { + writeCellValue(colIndex, currentRowIndex, headerVal, true); currentRowIndex++; } for (final Object colDatum : colData) { writeCellValue(colIndex, currentRowIndex, colDatum); currentRowIndex++; } - if(!isResetRowIndex){ + if (!isResetRowIndex) { currentRow.set(currentRowIndex); } return this; @@ -1153,6 +1158,7 @@ public class ExcelWriter extends ExcelBase { // endregion // region ----- writeCellValue + /** * 给指定单元格赋值,使用默认单元格样式 * @@ -1196,6 +1202,7 @@ public class ExcelWriter extends ExcelBase { // endregion // region ----- setStyle + /** * 设置某个单元格的样式
* 此方法用于多个单元格共享样式的情况
@@ -1313,6 +1320,7 @@ public class ExcelWriter extends ExcelBase { // endregion // region ----- flush + /** * 将Excel Workbook刷出到预定义的文件
* 如果用户未自定义输出的文件,将抛出{@link NullPointerException}
diff --git a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/AbstractCaptcha.java b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/AbstractCaptcha.java index 81edaa76f..0218667ff 100644 --- a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/AbstractCaptcha.java +++ b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/AbstractCaptcha.java @@ -99,12 +99,25 @@ public abstract class AbstractCaptcha implements ICaptcha { * @param interfereCount 验证码干扰元素个数 */ public AbstractCaptcha(final int width, final int height, final CodeGenerator generator, final int interfereCount) { + this(width, height, generator, interfereCount, 0.75f); + } + + /** + * 构造 + * + * @param width 图片宽 + * @param height 图片高 + * @param generator 验证码生成器 + * @param interfereCount 验证码干扰元素个数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + */ + public AbstractCaptcha(final int width, final int height, final CodeGenerator generator, final int interfereCount, final float sizeBaseHeight) { this.width = width; this.height = height; this.generator = generator; this.interfereCount = interfereCount; // 字体高度设为验证码高度-2,留边距 - this.font = new Font(Font.SANS_SERIF, Font.PLAIN, (int) (this.height * 0.75)); + this.font = new Font(Font.SANS_SERIF, Font.PLAIN, (int) (this.height * sizeBaseHeight)); } @Override @@ -114,7 +127,7 @@ public abstract class AbstractCaptcha implements ICaptcha { final ByteArrayOutputStream out = new ByteArrayOutputStream(); Image image = null; - try{ + try { image = createImage(this.code); ImgUtil.writePng(image, out); } finally { @@ -222,7 +235,7 @@ public abstract class AbstractCaptcha implements ICaptcha { * @return 图片带文件格式的 Base64 * @since 5.3.11 */ - public String getImageBase64Data(){ + public String getImageBase64Data() { return UrlUtil.getDataUriBase64("image/png", getImageBase64()); } diff --git a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CaptchaUtil.java b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CaptchaUtil.java index 9acac1258..659a4ca09 100644 --- a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CaptchaUtil.java +++ b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CaptchaUtil.java @@ -44,6 +44,21 @@ public class CaptchaUtil { return new LineCaptcha(width, height, codeCount, lineCount); } + /** + * 创建线干扰的验证码 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param lineCount 干扰线条数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + * @return {@link LineCaptcha} + */ + public static LineCaptcha ofLineCaptcha(final int width, final int height, final int codeCount, + final int lineCount, final float sizeBaseHeight) { + return new LineCaptcha(width, height, codeCount, lineCount, sizeBaseHeight); + } + /** * 创建圆圈干扰的验证码,默认5位验证码,15个干扰圈 * @@ -70,6 +85,21 @@ public class CaptchaUtil { return new CircleCaptcha(width, height, codeCount, circleCount); } + /** + * 创建圆圈干扰的验证码 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param circleCount 干扰圆圈条数 + * @param size 字体的大小 高度的倍数 + * @return {@link CircleCaptcha} + */ + public static CircleCaptcha ofCircleCaptcha(final int width, final int height, final int codeCount, + final int circleCount, final float size) { + return new CircleCaptcha(width, height, codeCount, circleCount, size); + } + /** * 创建扭曲干扰的验证码,默认5位验证码 * @@ -96,6 +126,20 @@ public class CaptchaUtil { return new ShearCaptcha(width, height, codeCount, thickness); } + /** + * 创建扭曲干扰的验证码,默认5位验证码 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param thickness 干扰线宽度 + * @param sizeBaseHeight 字体的大小 高度的倍数 + * @return {@link ShearCaptcha} + */ + public static ShearCaptcha ofShearCaptcha(final int width, final int height, final int codeCount, final int thickness, final float sizeBaseHeight) { + return new ShearCaptcha(width, height, codeCount, thickness, sizeBaseHeight); + } + /** * 创建GIF验证码 * @@ -118,4 +162,19 @@ public class CaptchaUtil { public static GifCaptcha ofGifCaptcha(final int width, final int height, final int codeCount) { return new GifCaptcha(width, height, codeCount); } + + /** + * 创建圆圈干扰的验证码 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param thickness 验证码干扰元素个数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + * @return {@link GifCaptcha} + */ + public static GifCaptcha ofGifCaptcha(final int width, final int height, final int codeCount, + final int thickness, final float sizeBaseHeight) { + return new GifCaptcha(width, height, codeCount, thickness, sizeBaseHeight); + } } diff --git a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CircleCaptcha.java b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CircleCaptcha.java index 4495ccabf..b227463ba 100644 --- a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CircleCaptcha.java +++ b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/CircleCaptcha.java @@ -30,7 +30,6 @@ import java.util.concurrent.ThreadLocalRandom; * * @author looly * @since 3.2.3 - * */ public class CircleCaptcha extends AbstractCaptcha { private static final long serialVersionUID = -7096627300356535494L; @@ -38,7 +37,7 @@ public class CircleCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 + * @param width 图片宽 * @param height 图片高 */ public CircleCaptcha(final int width, final int height) { @@ -48,8 +47,8 @@ public class CircleCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 - * @param height 图片高 + * @param width 图片宽 + * @param height 图片高 * @param codeCount 字符个数 */ public CircleCaptcha(final int width, final int height, final int codeCount) { @@ -59,9 +58,9 @@ public class CircleCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 - * @param height 图片高 - * @param codeCount 字符个数 + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 * @param interfereCount 验证码干扰元素个数 */ public CircleCaptcha(final int width, final int height, final int codeCount, final int interfereCount) { @@ -80,12 +79,25 @@ public class CircleCaptcha extends AbstractCaptcha { super(width, height, generator, interfereCount); } + /** + * 构造 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param interfereCount 验证码干扰元素个数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + */ + public CircleCaptcha(final int width, final int height, final int codeCount, final int interfereCount, final float sizeBaseHeight) { + super(width, height, new RandomGenerator(codeCount), interfereCount, sizeBaseHeight); + } + @Override public Image createImage(final String code) { final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final Graphics2D g = GraphicsUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE)); - try{ + try { // 随机画干扰圈圈 drawInterfere(g); @@ -99,10 +111,11 @@ public class CircleCaptcha extends AbstractCaptcha { } // ----------------------------------------------------------------------------------------------------- Private method start + /** * 绘制字符串 * - * @param g {@link Graphics2D}画笔 + * @param g {@link Graphics2D}画笔 * @param code 验证码 */ private void drawString(final Graphics2D g, final String code) { diff --git a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/GifCaptcha.java b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/GifCaptcha.java index 11f0e8300..5dc869116 100644 --- a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/GifCaptcha.java +++ b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/GifCaptcha.java @@ -86,6 +86,19 @@ public class GifCaptcha extends AbstractCaptcha { super(width, height, generator, interfereCount); } + /** + * 构造 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 验证码个数 + * @param interfereCount 验证码干扰元素个数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + */ + public GifCaptcha(final int width, final int height, final int codeCount, final int interfereCount, final float sizeBaseHeight) { + super(width, height, new RandomGenerator(codeCount), interfereCount, sizeBaseHeight); + } + /** * 设置图像的颜色量化(转换质量 由GIF规范允许的最大256种颜色)。 * 低的值(最小值= 1)产生更好的颜色,但处理显著缓慢。 diff --git a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/LineCaptcha.java b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/LineCaptcha.java index f79e3137e..bda92cba8 100644 --- a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/LineCaptcha.java +++ b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/LineCaptcha.java @@ -36,10 +36,11 @@ public class LineCaptcha extends AbstractCaptcha { private static final long serialVersionUID = 8691294460763091089L; // -------------------------------------------------------------------- Constructor start + /** * 构造,默认5位验证码,150条干扰线 * - * @param width 图片宽 + * @param width 图片宽 * @param height 图片高 */ public LineCaptcha(final int width, final int height) { @@ -49,8 +50,8 @@ public class LineCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 - * @param height 图片高 + * @param width 图片宽 + * @param height 图片高 * @param codeCount 字符个数 * @param lineCount 干扰线条数 */ @@ -69,6 +70,19 @@ public class LineCaptcha extends AbstractCaptcha { public LineCaptcha(final int width, final int height, final CodeGenerator generator, final int interfereCount) { super(width, height, generator, interfereCount); } + + /** + * 构造 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param interfereCount 验证码干扰元素个数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + */ + public LineCaptcha(final int width, final int height, final int codeCount, final int interfereCount, final float sizeBaseHeight) { + super(width, height, new RandomGenerator(codeCount), interfereCount, sizeBaseHeight); + } // -------------------------------------------------------------------- Constructor end @Override @@ -77,7 +91,7 @@ public class LineCaptcha extends AbstractCaptcha { final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final Graphics2D g = GraphicsUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE)); - try{ + try { // 干扰线 drawInterfere(g); @@ -91,10 +105,11 @@ public class LineCaptcha extends AbstractCaptcha { } // ----------------------------------------------------------------------------------------------------- Private method start + /** * 绘制字符串 * - * @param g {@link Graphics}画笔 + * @param g {@link Graphics}画笔 * @param code 验证码 */ private void drawString(final Graphics2D g, final String code) { diff --git a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/ShearCaptcha.java b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/ShearCaptcha.java index e97e90a18..f617801c3 100644 --- a/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/ShearCaptcha.java +++ b/hutool-swing/src/main/java/org/dromara/hutool/swing/captcha/ShearCaptcha.java @@ -30,7 +30,6 @@ import java.awt.image.BufferedImage; * * @author looly * @since 3.2.3 - * */ public class ShearCaptcha extends AbstractCaptcha { private static final long serialVersionUID = -7096627300356535494L; @@ -38,7 +37,7 @@ public class ShearCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 + * @param width 图片宽 * @param height 图片高 */ public ShearCaptcha(final int width, final int height) { @@ -48,8 +47,8 @@ public class ShearCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 - * @param height 图片高 + * @param width 图片宽 + * @param height 图片高 * @param codeCount 字符个数 */ public ShearCaptcha(final int width, final int height, final int codeCount) { @@ -59,8 +58,8 @@ public class ShearCaptcha extends AbstractCaptcha { /** * 构造 * - * @param width 图片宽 - * @param height 图片高 + * @param width 图片宽 + * @param height 图片高 * @param codeCount 字符个数 * @param thickness 干扰线宽度 */ @@ -80,12 +79,25 @@ public class ShearCaptcha extends AbstractCaptcha { super(width, height, generator, interfereCount); } + /** + * 构造 + * + * @param width 图片宽 + * @param height 图片高 + * @param codeCount 字符个数 + * @param interfereCount 验证码干扰元素个数 + * @param sizeBaseHeight 字体的大小 高度的倍数 + */ + public ShearCaptcha(final int width, final int height, final int codeCount, final int interfereCount, final float sizeBaseHeight) { + super(width, height, new RandomGenerator(codeCount), interfereCount, sizeBaseHeight); + } + @Override public Image createImage(final String code) { final BufferedImage image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB); final Graphics2D g = GraphicsUtil.createGraphics(image, ObjUtil.defaultIfNull(this.background, Color.WHITE)); - try{ + try { // 画字符串 drawString(g, code); // 扭曲 @@ -100,10 +112,11 @@ public class ShearCaptcha extends AbstractCaptcha { } // ----------------------------------------------------------------------------------------------------- Private method start + /** * 绘制字符串 * - * @param g {@link Graphics}画笔 + * @param g {@link Graphics}画笔 * @param code 验证码 */ private void drawString(final Graphics2D g, final String code) { @@ -117,9 +130,9 @@ public class ShearCaptcha extends AbstractCaptcha { /** * 扭曲 * - * @param g {@link Graphics} - * @param w1 w1 - * @param h1 h1 + * @param g {@link Graphics} + * @param w1 w1 + * @param h1 h1 * @param color 颜色 */ private void shear(final Graphics g, final int w1, final int h1, final Color color) { @@ -130,9 +143,9 @@ public class ShearCaptcha extends AbstractCaptcha { /** * X坐标扭曲 * - * @param g {@link Graphics} - * @param w1 宽 - * @param h1 高 + * @param g {@link Graphics} + * @param w1 宽 + * @param h1 高 * @param color 颜色 */ private void shearX(final Graphics g, final int w1, final int h1, final Color color) { @@ -155,9 +168,9 @@ public class ShearCaptcha extends AbstractCaptcha { /** * Y坐标扭曲 * - * @param g {@link Graphics} - * @param w1 宽 - * @param h1 高 + * @param g {@link Graphics} + * @param w1 宽 + * @param h1 高 * @param color 颜色 */ private void shearY(final Graphics g, final int w1, final int h1, final Color color) { @@ -180,13 +193,13 @@ public class ShearCaptcha extends AbstractCaptcha { /** * 干扰线 * - * @param g {@link Graphics} - * @param x1 x1 - * @param y1 y1 - * @param x2 x2 - * @param y2 y2 + * @param g {@link Graphics} + * @param x1 x1 + * @param y1 y1 + * @param x2 x2 + * @param y2 y2 * @param thickness 粗细 - * @param c 颜色 + * @param c 颜色 */ @SuppressWarnings("SameParameterValue") private void drawInterfere(final Graphics g, final int x1, final int y1, final int x2, final int y2, final int thickness, final Color c) {