增加设置验证码大小和针对alias注释

This commit is contained in:
Looly
2024-04-11 21:28:50 +08:00
parent b2dbd55c1e
commit b859cf4913
8 changed files with 192 additions and 51 deletions

View File

@@ -352,4 +352,11 @@ public class JSONUtilTest {
final String jsonStr = JSONUtil.toJsonStr(true); final String jsonStr = JSONUtil.toJsonStr(true);
Assertions.assertEquals("true", jsonStr); Assertions.assertEquals("true", jsonStr);
} }
@Test
public void issue3540Test() {
final Long userId=10101010L;
final String jsonStr = JSONUtil.toJsonStr(userId);
Assertions.assertEquals("10101010", jsonStr);
}
} }

View File

@@ -81,6 +81,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
private final AtomicInteger currentRow; private final AtomicInteger currentRow;
// region Constructors // region Constructors
/** /**
* 构造默认生成xls格式的Excel文件<br> * 构造默认生成xls格式的Excel文件<br>
* 此构造不传入写出的Excel文件路径只能调用{@link #flush(OutputStream)}方法写出到流<br> * 此构造不传入写出的Excel文件路径只能调用{@link #flush(OutputStream)}方法写出到流<br>
@@ -449,6 +450,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
/** /**
* 设置是否只保留别名中的字段值如果为true则不设置alias的字段将不被输出false表示原样输出 * 设置是否只保留别名中的字段值如果为true则不设置alias的字段将不被输出false表示原样输出
* Bean中设置@Alias时setOnlyAlias是无效的这个参数只和addHeaderAlias配合使用原因是注解是Bean内部的操作而addHeaderAlias是Writer的操作不互通。
* *
* @param isOnlyAlias 是否只保留别名中的字段值 * @param isOnlyAlias 是否只保留别名中的字段值
* @return this * @return this
@@ -799,6 +801,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
} }
// region ----- writeImg // region ----- writeImg
/** /**
* 写出数据本方法只是将数据写入Workbook中的Sheet并不写出到文件<br> * 写出数据本方法只是将数据写入Workbook中的Sheet并不写出到文件<br>
* 添加图片到当前sheet中 / 默认图片类型png / 默认的起始坐标和结束坐标都为0 * 添加图片到当前sheet中 / 默认图片类型png / 默认的起始坐标和结束坐标都为0
@@ -899,6 +902,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
// endregion // endregion
// region ----- writeRow // region ----- writeRow
/** /**
* 写出一行标题数据<br> * 写出一行标题数据<br>
* 本方法只是将数据写入Workbook中的Sheet并不写出到文件<br> * 本方法只是将数据写入Workbook中的Sheet并不写出到文件<br>
@@ -1070,6 +1074,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
// endregion // endregion
// region ----- writeCol // region ----- writeCol
/** /**
* 从第1列开始按列写入数据(index 从0开始)<br> * 从第1列开始按列写入数据(index 从0开始)<br>
* 本方法只是将数据写入Workbook中的Sheet并不写出到文件<br> * 本方法只是将数据写入Workbook中的Sheet并不写出到文件<br>
@@ -1153,6 +1158,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
// endregion // endregion
// region ----- writeCellValue // region ----- writeCellValue
/** /**
* 给指定单元格赋值,使用默认单元格样式 * 给指定单元格赋值,使用默认单元格样式
* *
@@ -1196,6 +1202,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
// endregion // endregion
// region ----- setStyle // region ----- setStyle
/** /**
* 设置某个单元格的样式<br> * 设置某个单元格的样式<br>
* 此方法用于多个单元格共享样式的情况<br> * 此方法用于多个单元格共享样式的情况<br>
@@ -1313,6 +1320,7 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
// endregion // endregion
// region ----- flush // region ----- flush
/** /**
* 将Excel Workbook刷出到预定义的文件<br> * 将Excel Workbook刷出到预定义的文件<br>
* 如果用户未自定义输出的文件,将抛出{@link NullPointerException}<br> * 如果用户未自定义输出的文件,将抛出{@link NullPointerException}<br>

View File

@@ -99,12 +99,25 @@ public abstract class AbstractCaptcha implements ICaptcha {
* @param interfereCount 验证码干扰元素个数 * @param interfereCount 验证码干扰元素个数
*/ */
public AbstractCaptcha(final int width, final int height, final CodeGenerator generator, final int 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.width = width;
this.height = height; this.height = height;
this.generator = generator; this.generator = generator;
this.interfereCount = interfereCount; this.interfereCount = interfereCount;
// 字体高度设为验证码高度-2留边距 // 字体高度设为验证码高度-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 @Override

View File

@@ -44,6 +44,21 @@ public class CaptchaUtil {
return new LineCaptcha(width, height, codeCount, lineCount); 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个干扰圈 * 创建圆圈干扰的验证码默认5位验证码15个干扰圈
* *
@@ -70,6 +85,21 @@ public class CaptchaUtil {
return new CircleCaptcha(width, height, codeCount, circleCount); 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位验证码 * 创建扭曲干扰的验证码默认5位验证码
* *
@@ -96,6 +126,20 @@ public class CaptchaUtil {
return new ShearCaptcha(width, height, codeCount, thickness); 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验证码 * 创建GIF验证码
* *
@@ -118,4 +162,19 @@ public class CaptchaUtil {
public static GifCaptcha ofGifCaptcha(final int width, final int height, final int codeCount) { public static GifCaptcha ofGifCaptcha(final int width, final int height, final int codeCount) {
return new GifCaptcha(width, height, 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);
}
} }

View File

@@ -30,7 +30,6 @@ import java.util.concurrent.ThreadLocalRandom;
* *
* @author looly * @author looly
* @since 3.2.3 * @since 3.2.3
*
*/ */
public class CircleCaptcha extends AbstractCaptcha { public class CircleCaptcha extends AbstractCaptcha {
private static final long serialVersionUID = -7096627300356535494L; private static final long serialVersionUID = -7096627300356535494L;
@@ -80,6 +79,19 @@ public class CircleCaptcha extends AbstractCaptcha {
super(width, height, generator, interfereCount); 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 @Override
public Image createImage(final String code) { public Image createImage(final String code) {
final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
@@ -99,6 +111,7 @@ public class CircleCaptcha extends AbstractCaptcha {
} }
// ----------------------------------------------------------------------------------------------------- Private method start // ----------------------------------------------------------------------------------------------------- Private method start
/** /**
* 绘制字符串 * 绘制字符串
* *

View File

@@ -86,6 +86,19 @@ public class GifCaptcha extends AbstractCaptcha {
super(width, height, generator, interfereCount); 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种颜色)。 * 设置图像的颜色量化(转换质量 由GIF规范允许的最大256种颜色)。
* 低的值(最小值= 1)产生更好的颜色,但处理显著缓慢。 * 低的值(最小值= 1)产生更好的颜色,但处理显著缓慢。

View File

@@ -36,6 +36,7 @@ public class LineCaptcha extends AbstractCaptcha {
private static final long serialVersionUID = 8691294460763091089L; private static final long serialVersionUID = 8691294460763091089L;
// -------------------------------------------------------------------- Constructor start // -------------------------------------------------------------------- Constructor start
/** /**
* 构造默认5位验证码150条干扰线 * 构造默认5位验证码150条干扰线
* *
@@ -69,6 +70,19 @@ public class LineCaptcha extends AbstractCaptcha {
public LineCaptcha(final int width, final int height, final CodeGenerator generator, final int interfereCount) { public LineCaptcha(final int width, final int height, final CodeGenerator generator, final int interfereCount) {
super(width, height, generator, 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 // -------------------------------------------------------------------- Constructor end
@Override @Override
@@ -91,6 +105,7 @@ public class LineCaptcha extends AbstractCaptcha {
} }
// ----------------------------------------------------------------------------------------------------- Private method start // ----------------------------------------------------------------------------------------------------- Private method start
/** /**
* 绘制字符串 * 绘制字符串
* *

View File

@@ -30,7 +30,6 @@ import java.awt.image.BufferedImage;
* *
* @author looly * @author looly
* @since 3.2.3 * @since 3.2.3
*
*/ */
public class ShearCaptcha extends AbstractCaptcha { public class ShearCaptcha extends AbstractCaptcha {
private static final long serialVersionUID = -7096627300356535494L; private static final long serialVersionUID = -7096627300356535494L;
@@ -80,6 +79,19 @@ public class ShearCaptcha extends AbstractCaptcha {
super(width, height, generator, interfereCount); 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 @Override
public Image createImage(final String code) { public Image createImage(final String code) {
final BufferedImage image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB); final BufferedImage image = new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB);
@@ -100,6 +112,7 @@ public class ShearCaptcha extends AbstractCaptcha {
} }
// ----------------------------------------------------------------------------------------------------- Private method start // ----------------------------------------------------------------------------------------------------- Private method start
/** /**
* 绘制字符串 * 绘制字符串
* *