作者归档:Rick

docusaurus 部署到 GitHub Pages 自定义域名

在 iCloud Drive 下创建目录 docusaurus, 命令行进入 docusaurus

npm init docusaurus@latest

What should we name this site? docs-test
…默认选择向下执行

托管 github

新建仓库 docs-test

git init
git add .
git commit -m 'project int'
git remote add origin https://github.com/jkxyx205/docs-test.git
git push -u origin main
  • 开启 github pages
    docs-test/Settings/Pages/, Source 设置 Github Actions
  • 创建部署文件.github/workflows/deploy.yml
    提示词:「docusaurus 自动部署到 GitHub Pages, 写一下部署的yml」,下面的配置是通过 Claude 3.5 sonnet 生成的
  1. name: Deploy Docusaurus to GitHub Pages
  2. on:
  3. push:
  4. branches: ["main"]
  5. workflow_dispatch:
  6. permissions:
  7. contents: read
  8. pages: write
  9. id-token: write
  10. concurrency:
  11. group: "pages"
  12. cancel-in-progress: false
  13. jobs:
  14. deploy:
  15. environment:
  16. name: github-pages
  17. url: ${{ steps.deployment.outputs.page_url }}
  18. runs-on: ubuntu-latest
  19. steps:
  20. - name: Checkout
  21. uses: actions/checkout@v4
  22. - name: Setup Node.js
  23. uses: actions/setup-node@v4
  24. with:
  25. node-version: '18'
  26. cache: npm
  27. - name: Install dependencies
  28. run: npm ci
  29. - name: Build website
  30. run: npm run build
  31. - name: Setup Pages
  32. uses: actions/configure-pages@v4
  33. - name: Upload artifact
  34. uses: actions/upload-pages-artifact@v3
  35. with:
  36. path: build
  37. - name: Deploy to GitHub Pages
  38. id: deployment
  39. uses: actions/deploy-pages@v4

提交 push ,如果成功部署可以访问: https://jkxyx205.github.io/docs-test/

绑定域名

  • 添加域名解析docs-test CNAME jkxyx205.github.io
  • docs-test/Settings/Pages/Custom domain 填写域名 docs-test.xxx.com 并保存
  • Enforce HTTPS 勾选,http 会自动跳转到 https

SpringBoot application.yml 配置参数,不上传到GitHub

需求:

application.yml 配置的数据库信息采用变量的形式,这样提交到GitHub的时候就不会泄露敏感信息

  • 项目目录下添加.env配置信息
  1. URL=jdbc:postgresql://localhost:5432/postgres
  2. USERNAME=root
  3. PASSWORD=123456
  • application.yml导入 .env
  1. spring:
  2. config:
  3. import:
  4. - optional:file:.env[.properties]
  • application.yml 使用变量
  1. datasource:
  2. url: ${URL}
  3. username: ${USERNAME}
  4. password: ${PASSWORD}
  • java 代码使用变量
  1. @Value("${USERNAME}")
  2. private String username;
  3. @Value("${spring.datasource.username}")
  4. private String username2;
  5. @Value("${PASSWORD}")
  6. private String password;
  • .gitignore 忽略 .env
.env*

SpringBoot 集成 sharp-database

添加依赖

  1. <parent>
  2. <groupId>org.springframework.boot</groupId>
  3. <artifactId>spring-boot-starter-parent</artifactId>
  4. <version>2.7.9</version>
  5. <relativePath/>
  6. </parent>
  7. <dependencies>
  8. <dependency>
  9. <groupId>org.springframework.boot</groupId>
  10. <artifactId>spring-boot-starter</artifactId>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.alibaba</groupId>
  14. <artifactId>druid-spring-boot-starter</artifactId>
  15. <version>1.2.24</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>com.mysql</groupId>
  19. <artifactId>mysql-connector-j</artifactId>
  20. </dependency>
  21. <dependency>
  22. <groupId>com.rick.db</groupId>
  23. <artifactId>sharp-database</artifactId>
  24. <version>2.0-SNAPSHOT</version>
  25. </dependency>
  26. </dependencies>

数据库配置文件:

  1. server:
  2. port: 8080
  3. spring:
  4. datasource:
  5. name: druidDataSource
  6. type: com.alibaba.druid.pool.DruidDataSource
  7. druid:
  8. driver-class-name: com.mysql.cj.jdbc.Driver
  9. url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8
  10. username: root
  11. password: root
  12. initialSize: 1
  13. minIdle: 5
  14. maxActive: 10
  15. maxWait: 60000
  16. sharp:
  17. database: # 多个包扫描用 , 隔开
  18. entity-base-package: com.rick.sharp.**.entity

测试

  1. @SpringBootApplication
  2. @DependsOn("entityDAOSupport")
  3. @EnableScheduling
  4. public class DemoApplication {
  5. @Autowired
  6. private EntityDAO<User, Long> userDAO;
  7. @Autowired
  8. private EntityDAO<CodeDescription, Long> codeDescriptionDAO;
  9. public static void main(String[] args) {
  10. SpringApplication.run(DemoApplication.class, args);
  11. String ss = JsonUtils.toJson("ss");
  12. System.out.println(ss);
  13. System.out.println("running.....");
  14. }
  15. @Scheduled(fixedRate = 5000)
  16. public void find() {
  17. User user = userDAO.selectById(1L).get();
  18. System.out.println(user.getName());
  19. codeDescriptionDAO.insert(CodeDescription.builder()
  20. .code("test-" + System.currentTimeMillis())
  21. .description("hello")
  22. .category(CodeDescription.CategoryEnum.MATERIAL)
  23. .build());
  24. }
  25. }

@Sql 根据对象的字段查询其他信息

假设对象有属性 物料id,联系人id,可以根据这个两个 id 分别获取 描述信息,并放到Map对象中。

将多行的 union all 进行「行转列」

  1. select
  2. MAX(CASE WHEN c1 = 'material_name' THEN c2 END) as 'material_name',
  3. MAX(CASE WHEN c1 = 'contact_person' THEN c2 END) as 'contact_person'
  4. from (
  5. select 'material_name' c1, name c2 from mm_material where id = 725446412870901760
  6. union all
  7. select 'contact_person', contact_person from core_contact where id = 738365393630253056)
  8. t

创建查询对象 GridQuery.java

  1. @Data
  2. @Table
  3. public class GridQuery {
  4. /**
  5. * 必须有一个主键字段
  6. */
  7. private Long id;
  8. private Long materialId;
  9. private Long contactId;
  10. @Transient
  11. @Sql(value = "select \n" +
  12. "MAX(CASE WHEN c1 = 'material_name' THEN c2 END) as 'material_name',\n" +
  13. "MAX(CASE WHEN c1 = 'contact_person' THEN c2 END) as 'contact_person'\n" +
  14. "from (\n" +
  15. "select 'material_name' c1, name c2 from mm_material where id = :materialId\n"
  16. "union all\n" +
  17. "select 'contact_person', contact_person from core_contact where id = :contactId)\n" +
  18. "t", params="materialId@materialId, contactId@contactId")
  19. private Map<String, Object> additionalInfo;
  20. }

测试信息

  1. @Autowired
  2. private EntityDAOSupport entityDAOSupport;
  3. @Test
  4. public void testQuery() {
  5. // 单个对象
  6. GridQuery query = new GridQuery();
  7. query.setMaterialId(725446412870901760L);
  8. query.setContactId(738365393630253056L);
  9. GridQuery query1 = entityDAOSupport.query(query);
  10. System.out.println(query1);
  11. // 对象数组
  12. GridQuery query2 = new GridQuery();
  13. query2.setMaterialId(725446412870901760L);
  14. GridQuery query3 = new GridQuery();
  15. query3.setContactId(738365393630253056L);
  16. List<GridQuery> query4 = entityDAOSupport.query(Arrays.asList(query2, query3));
  17. }