ToB企服应用市场:ToB评测及商务社交产业平台

标题: 桌面版vscode用免费的微软4核8G服务器做远程开发(编译运行都在云上,还能 [打印本页]

作者: 自由的羽毛    时间: 2023-8-30 07:50
标题: 桌面版vscode用免费的微软4核8G服务器做远程开发(编译运行都在云上,还能
欢迎访问我的GitHub

这里分类和汇总了欣宸的全部原创(含配套源码):https://github.com/zq2599/blog_demos
本篇概览


实战目标


重要前提

环境信息


在vscode上做设置,使其支持Codespaces

新建分支

个性化设置










部署MySQL


  1. docker run \
  2. --name mysql \
  3. -p 3306:3306 \
  4. -v /workspaces/java-demo/mysql-data:/var/lib/mysql \
  5. -e MYSQL_ROOT_PASSWORD=123456 \
  6. -idt \
  7. mysql:8.0.29 \
  8. --character-set-server=utf8mb4 \
  9. --collation-server=utf8mb4_unicode_ci
复制代码

  1. docker exec -it mysql /bin/bash
复制代码
  1. @zq2599 ➜ ~ $ docker exec -it mysql /bin/bash
  2. root@f6a9dcc7fdcd:/# mysql -uroot -p
  3. Enter password:
  4. Welcome to the MySQL monitor.  Commands end with ; or \g.
  5. Your MySQL connection id is 18
  6. Server version: 8.0.29 MySQL Community Server - GPL
  7. Copyright (c) 2000, 2022, Oracle and/or its affiliates.
  8. Oracle is a registered trademark of Oracle Corporation and/or its
  9. affiliates. Other names may be trademarks of their respective
  10. owners.
  11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  12. mysql> show databases;
  13. +--------------------+
  14. | Database           |
  15. +--------------------+
  16. | information_schema |
  17. | mysql              |
  18. | performance_schema |
  19. | sys                |
  20. +--------------------+
  21. 4 rows in set (0.00 sec)
复制代码
  1. # 建数据库
  2. CREATE DATABASE first_db;
  3. # 选中数据库
  4. use first_db;
  5. # 建表
  6. CREATE TABLE IF NOT EXISTS `seller`(
  7.     `id` INT UNSIGNED AUTO_INCREMENT,
  8.     `name` VARCHAR(100) NOT NULL,
  9.     `product_num` INT NULL,
  10.     PRIMARY KEY ( `id` )
  11. )ENGINE=InnoDB DEFAULT CHARSET=utf8;
  12. # 新增三条记录
  13. insert into seller (name, product_num) values ('seller1', 1111);
  14. insert into seller (name, product_num) values ('seller2', 2222);
  15. insert into seller (name, product_num) values ('seller3', 3333);
复制代码
开发SpringBoot应用







  1. server:
  2.   port: 8080
  3. spring:
  4.   # 数据源
  5.   datasource:
  6.     username: root
  7.     password: 123456
  8.     url: jdbc:mysql://127.0.0.1:3306/first_db?useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=UTC
  9.     driver-class-name: com.mysql.cj.jdbc.Driver
  10. # mybatis配置
  11. mybatis:
  12.   # 配置文件所在位置
  13.   config-location: classpath:mybatis-config.xml
  14.   # 映射文件所在位置
  15.   mapper-locations: classpath:mappers/*Mapper.xml
  16. # 日志配置
  17. logging:
  18.   level:
  19.     root: INFO
  20.     com:
  21.       bolingcavalry:
  22.         demo:
  23.           mapper: debug
复制代码
验证-单元测试

  1. package com.bolingcavalry.demo;
  2. import org.junit.jupiter.api.*;
  3. import org.junit.jupiter.api.Test;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.boot.test.context.SpringBootTest;
  6. import com.bolingcavalry.demo.entity.Seller;
  7. import com.bolingcavalry.demo.service.SellerService;
  8. @SpringBootTest
  9. class DemoApplicationTests {
  10.         @Autowired
  11.         SellerService sellerService;
  12.         @Test
  13.         void testGetById() {
  14.                 int id = 1;
  15.                 Seller seller = sellerService.get(id);
  16.                 // 判定非空
  17.         Assertions.assertNotNull(seller);
  18.                 // id相等
  19.                 Assertions.assertEquals(id, seller.getId());
  20.         }
  21. }
复制代码
验证:web

  1. @RestController
  2. @Slf4j
  3. public class SellerController {
  4.    
  5.     @Autowired
  6.     private SellerService sellerService;
  7.     @RequestMapping(value = "/seller/{id}", method = RequestMethod.GET)
  8.     public Seller get(@PathVariable("id") Integer id) {
  9.         log.info("get entity, id=[{}]", id);
  10.         return sellerService.get(id);
  11.     }
  12. }
复制代码



提交到GitHub


欢迎关注博客园:程序员欣宸

学习路上,你不孤单,欣宸原创一路相伴...

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!




欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) Powered by Discuz! X3.4