Calibre 安装与使用

参考

安装 Calibre

  1. 下载安装包Calibre
  2. 直接安装就好了,记得设置书库位置。

Calibre-Web 部署

  1. 使用 Docker 部署服务
    1
    2
    3
    4
    5
    6
    7
    8
    services:
    calibre-web:
    image: linuxserver/calibre-web
    container_name: calibre-web
    volumes:
    - ./calibre-library:/app/calibre-web/calibre-library # Calibre库的位置
    - ./config:/config # 配置地址
    # 默认端口8083
  2. 访问http://localhost:8083或者http://localhost:8083/opds
  3. 使用默认的帐号密码登录。
    • 默认帐号:admin
    • 默认密码:admin123
  4. 将本地的Calibre数据库拷贝到服务器上。
  5. 设置数据库文件位置metadata.db,就是Calibre数据库文件夹位置,然后设置将好了。

制作EPUB电子书

使用 KCC 制作漫画电子书

  1. 下载KCC
  2. 将漫画图片都放在一个文件夹中
  3. 将漫画图片按照顺序命名,例如: 001.jpg, 002.jpg, 003.jpg, …
  4. 打开KCC,点击Add images folder添加漫画文件夹。
  5. 选择各项参数设置,参考:Kindle Comic Converter:最简单的漫画转换工具
    • Manga mode:日本动漫模式-开启从右向左翻页。
    • stretch/Upscale:拉伸/适应
      • 未勾选:小于设备分辨率的图像将不会调整大小
      • 不确定:小于设备分辨率的图像将被调整尺寸。 长宽比将不会保留。
      • 勾选:小于设备分辨率的图像将被调整尺寸。 长宽比将被保留。
  6. 选择要输出的格式,例如:EPUB
  7. 点击Convert开始转换。

使用sigil对EPUB电子书进行进一步完善

  1. 下载sigil,并且安装。
  2. 打开EPUB电子书。
  3. 点击源数据编辑器图标(粉色M),对元数据进行完善。

Rime输入法

参考

快速开始

  1. 下载Rime
  2. 安装时候我只勾选了朙月拼音(简体字),其他都不勾选因为我只要简体字将好了。
  3. 电脑打开语言设置,在键盘选项中去除不需要的输入法,方便切换到你像要的输入法。

Rime输入法配置

必知必会

  • 重新部署:配置文件修改后,需要重新部署才能生效。

    • 小狼豪:小狼毫输入法右键->重新部署。
  • 文件位置:常用文件/文件夹位置。

    • 用户文件夹<Rime安装位置>/userData,或者小狼毫输入法右键->用户文件夹。
    • 输入方案配置文件<用户文件夹>/default.custom.yaml
      • 默认的配置文件:用户自定义的配置文件,一般用于修改输入法配置。如果找不到就手动创建。
      • 不同输入法单独定制,则在用户文件夹下创建对应的配置文件如luna_pinyin.custom.yaml
    • 程序配置文件<用户文件夹>/weasel.custom.yaml程序相关的配置,比如程序的样式,字体,颜色等。

配置用户资料同步

  1. 打开用户文件夹的installation.yaml文件
  2. 添加sync_dir: 'D:\BaiduSyncdisk\RimeSync'代码,配置本地同步文件夹
    1
    2
    3
    4
    5
    6
    7
    distribution_code_name: Weasel
    distribution_name: "小狼毫"
    distribution_version: 0.16.3
    install_time: "Mon Feb 24 13:43:53 2025"
    installation_id: "eb30629c-3ae6-458c-b2fd-0530de175159"
    rime_version: 1.11.2
    sync_dir: 'D:\BaiduSyncdisk\RimeSync'
  3. 重启输入法,同步用户资料
  4. 通过百度网盘等方式同步刚刚配置的本地文件夹。

常用输入法配置

  • 每页候选数:就是打字时候一页显示的候选词条数。
    1
    2
    3
    # default.custom.yaml
    patch:
    menu/page_size : 5
  • 选词排序方向:就是打字时候显示的候选词是横着排列还是竖着排列。
    1
    2
    3
    # weasel.custom.yaml
    patch:
    style/horizontal : true # 候选词水平排列

Spring Boot JPA连接操作数据库

参考

快速开始

  1. 在Spring Boot中添加相关依赖
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <!-- Spring Boot JPA依赖 提供对数据库操作的一套标准-->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>

    <!-- 根据使用的数据库,添加对应的依赖 -->
    <dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
    </dependency>
  2. 配置数据库连接
    1
    2
    3
    4
    5
    spring:
    datasource:
    url: jdbc:mysql://xxx.xxx.xxx.xxx:3306/spring
    username: spring
    password: spring

Spring Boot 加载配置文件信息

参考

加载配置文件信息使用场景

  • 游戏物品等策划配置的表格数据,如游戏物品名称,物品描述,物品图标等不会经常变动的数据,可以放在配置文件里,通过配置文件加载到内存中,减少数据库查询次数,提高性能。

配置文件加载方式

  1. 将表格获取其他数据的配置文件放在resources目录下。
  2. 定义数据结构相关的类
  3. 读取配置文件并使用

代码示例

  1. 将文件放在resources目录下,如src/main/resources/Prop.json
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [
    {
    "tId": 1,
    "name": "珍珠",
    "desc": "购买/解锁。获取说明:通过土地每日固定产出,以及小游戏消耗/获取"
    },
    {
    "tId": 2,
    "name": "铲铲",
    "desc": "解锁沙滩专用。获取说明:官方派发"
    },
    {
    "tId": 3,
    "name": "奇异种子",
    "desc": "用于种植奇异果实。获取说明:通过加工农产品获得奇异种子,加工1000珍珠可以获得1粒种子"
    }
    ]
  2. 定义数据结构相关的类
    1
    2
    3
    4
    5
    package com.chenlvtang.student.pojo.entity;

    //物品基础静态数据类
    public record PropTemplate(Number tId, String name, String desc) {
    }
  3. 读取配置文件并使用
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    import com.chenlvtang.student.pojo.entity.PropTemplate;
    import com.chenlvtang.student.service.PropTemplateService;
    import com.fasterxml.jackson.core.type.TypeReference;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import jakarta.annotation.PostConstruct;
    import org.springframework.stereotype.Service;

    import java.io.IOException;
    import java.io.InputStream;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    /**
    * Created with IntelliJ IDEA.
    *
    * @author Administrator
    * Date: 2025/1/16
    * Time: 14:42
    * Description:物品静态数据服务实现类
    */
    @Service
    public class PropTemplateServiceImpl implements PropTemplateService {
    private final Map<Number, PropTemplate> itemCache = new HashMap<>();

    private final ObjectMapper objectMapper;

    public PropTemplateServiceImpl(ObjectMapper objectMapper) {
    this.objectMapper = objectMapper;
    }

    @PostConstruct
    public void loadItemsIntoCache() throws IOException {
    InputStream inputStream = getClass().getClassLoader().getResourceAsStream("Prop.json");
    if (inputStream == null) {
    throw new IOException("未发现 Prop.json 文件");
    }

    List<PropTemplate> itemList = objectMapper.readValue(inputStream, new TypeReference<>() {
    });
    for (PropTemplate item : itemList) {
    itemCache.put(item.tId(), item);
    }
    }

    @Override
    public PropTemplate getPropTemplateById(int id) {
    return itemCache.get(id);
    }
    }

进一步完善:使用@Value传值

  1. 在application.properties中添加配置文件路径
    1
    2
    3
    4
    ### 这里都是自定义的
    config:
    file-path:
    prop: Prop.json
  2. 在类中使用@Value注解获取配置文件路径
    1
    2
    @Value("${config.file-path.prop}")
    private String propFilePath;

Spring Boot 参数校验

参考

简单实现参数校验

  1. 添加依赖参数校验所需依赖
    1
    2
    3
    4
    5
    <!-- 参数校验  -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
    </dependency>
  2. 添加参数校验注解:在要校验的类中添加参数校验注解如age
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    public class TestJson {

    private String name;

    @Min(value = 1, message = "年龄必须大于等于1")
    @Max(value = 160, message = "年龄必须小于等于160")
    private int age;

    public TestJson(String name, int age) {
    this.name = name;
    this.age = age;
    }

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }

    public int getAge() {
    return age;
    }

    public void setAge(int age) {
    this.age = age;
    }
    }
  3. 添加参数校验接口:在传入的参数中添加@Validated注解
    1
    2
    3
    4
    @PostMapping("/json")
    public TestJson json(@Validated @RequestBody TestJson json) {
    return json;
    }

Spring Boot 各个层作用与联系

参考

POJO层

  • POJO层即数据库实体层,也被称为entity层,model层
  • 一般数据库一张表对应一个实体类,类属性同表字段一一对应

DAO层

  • DAO层即数据访问层,也称为mapper层。
  • dao层的作用为访问数据库,向数据库发送sql语句,完成数据的增删改查任务。
  • 一般数据库一张表对应一个DAO接口,接口方法对应数据库操作。

Service层

  • Service层即业务逻辑层。
  • Service层的作用为对dao层进行业务逻辑处理,完成业务逻辑。

Controller层

  • Controller层即控制层,也称为web层。
  • Controller层的作用为接收请求,调用service层进行业务逻辑处理,返回结果。