feat: 优化页面显示
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package com.lanyuanxiaoyao.bookstore.helper;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 优化工具
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @version 20250929
|
||||
*/
|
||||
@Slf4j
|
||||
public class OptimiseHelper {
|
||||
public static String optimize(String text) {
|
||||
// 移除空行
|
||||
text = StrUtil.trimToNull(text);
|
||||
if (ObjectUtil.isNull(text)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 英文全角字符转换为半角字符
|
||||
text = halfWidth(text);
|
||||
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
private static String halfWidth(String text) {
|
||||
var builder = new StringBuilder();
|
||||
for (var c : text.toCharArray()) {
|
||||
// 检查是否为全角数字 (U+FF10 到 U+FF19)
|
||||
if (c >= 0xFF10 && c <= 0xFF19) {
|
||||
// 对应的半角数字是 (c - 0xFEE0)
|
||||
builder.append((char) (c - 0xFEE0));
|
||||
}
|
||||
// 检查是否为全角大写字母 (U+FF21 到 U+FF3A)
|
||||
else if (c >= 0xFF21 && c <= 0xFF3A) {
|
||||
// 对应的半角字母是 (c - 0xFEE0)
|
||||
builder.append((char) (c - 0xFEE0));
|
||||
}
|
||||
// 检查是否为全角小写字母 (U+FF41 到 U+FF5A)
|
||||
else if (c >= 0xFF41 && c <= 0xFF5A) {
|
||||
// 对应的半角字母是 (c - 0xFEE0)
|
||||
builder.append((char) (c - 0xFEE0));
|
||||
}
|
||||
// 非全角字母和数字字符直接添加
|
||||
else {
|
||||
builder.append(c);
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ChapterRepository extends SimpleRepository<Chapter> {
|
||||
@Query("select max(chapter.sequence) from Chapter chapter")
|
||||
@Query("select max(chapter.sequence) from Chapter chapter where chapter.book.id = ?1")
|
||||
Optional<Double> findMaxSequence(Long bookId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user