├── spring-boot-validator ├── README.md └── src │ └── main │ ├── resources │ └── application.yaml │ └── java │ └── com │ └── example │ ├── ValidatorApplication.java │ ├── controller │ └── UserController.java │ └── entity │ └── User.java ├── spring-boot-logback ├── README.md └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── example │ ├── LogbackApplication.java │ └── controller │ └── LogController.java ├── spring-boot-cache-caffeine ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yaml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── CaffeineApplication.java │ │ │ └── dto │ │ │ ├── UserDto.java │ │ │ └── ItemStock.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── BaseTest.java └── README.md ├── spring-boot-multi-threading ├── src │ ├── main │ │ ├── resources │ │ │ └── application.yaml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── MultiThreadApplication.java │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── BaseTest.java └── README.md ├── spring-boot-excel ├── assets │ └── 1585643739275.png ├── src │ └── main │ │ ├── resources │ │ ├── excel │ │ │ ├── EasyExcel模板.xls │ │ │ ├── EasyExcel模板.xlsx │ │ │ └── tOUTPRODUCT.xlsx │ │ └── application.yaml │ │ └── java │ │ └── com │ │ └── example │ │ ├── ExcelApplication.java │ │ ├── service │ │ ├── IEasyExcelService.java │ │ └── IPoiService.java │ │ ├── util │ │ ├── CommonUtil.java │ │ └── DataUtil.java │ │ ├── dto │ │ └── DemoData.java │ │ └── controller │ │ └── EasyExcelController.java └── README.md ├── spring-boot-sharding-jdbc ├── spring-boot-sharding-jdbc-4.1.1 │ ├── sharding-jdbc-4.1.1-db-table │ │ └── src │ │ │ └── main │ │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ └── org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── service │ │ │ ├── IRedisService.java │ │ │ ├── IUserService.java │ │ │ ├── IGoodsService.java │ │ │ ├── ISystemService.java │ │ │ └── impl │ │ │ │ ├── UserServiceImpl.java │ │ │ │ ├── GoodsServiceImpl.java │ │ │ │ ├── SystemServiceImpl.java │ │ │ │ └── RedisServiceImpl.java │ │ │ ├── mapper │ │ │ ├── UserMapper.java │ │ │ ├── GoodsMapper.java │ │ │ └── SystemMapper.java │ │ │ ├── ShardingJdbc4Application.java │ │ │ ├── util │ │ │ └── CommonUtil.java │ │ │ ├── entity │ │ │ ├── System.java │ │ │ ├── BaseEntity.java │ │ │ └── User.java │ │ │ └── config │ │ │ ├── JacksonConfig.java │ │ │ └── sharding │ │ │ └── algorithm │ │ │ └── PreciseModuloShardingDatabaseAlgorithm.java │ ├── sharding-jdbc-4.1.1-simple-db-table │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── mapper │ │ │ │ ├── UserMapper.java │ │ │ │ ├── GoodsMapper.java │ │ │ │ └── SystemMapper.java │ │ │ │ ├── service │ │ │ │ ├── IUserService.java │ │ │ │ ├── IGoodsService.java │ │ │ │ ├── ISystemService.java │ │ │ │ └── impl │ │ │ │ │ ├── UserServiceImpl.java │ │ │ │ │ ├── GoodsServiceImpl.java │ │ │ │ │ └── SystemServiceImpl.java │ │ │ │ ├── ShardingJdbc4SimpleApplication.java │ │ │ │ └── config │ │ │ │ ├── MybatisPlusConfig.java │ │ │ │ └── JacksonConfig.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml ├── spring-boot-sharding-jdbc-5.0.0 │ ├── sharding-jdbc-5.0.0-db-table │ │ └── src │ │ │ └── main │ │ │ ├── resources │ │ │ ├── META-INF │ │ │ │ └── services │ │ │ │ │ ├── org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm │ │ │ │ │ └── org.apache.shardingsphere.sharding.spi.ShardingAlgorithm │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── service │ │ │ ├── IRedisService.java │ │ │ ├── IUserService.java │ │ │ ├── IGoodsService.java │ │ │ ├── ISystemService.java │ │ │ └── impl │ │ │ │ ├── UserServiceImpl.java │ │ │ │ ├── GoodsServiceImpl.java │ │ │ │ ├── SystemServiceImpl.java │ │ │ │ └── RedisServiceImpl.java │ │ │ ├── mapper │ │ │ ├── UserMapper.java │ │ │ ├── GoodsMapper.java │ │ │ └── SystemMapper.java │ │ │ ├── ShardingJdbc5Application.java │ │ │ ├── util │ │ │ └── CommonUtil.java │ │ │ ├── entity │ │ │ ├── System.java │ │ │ ├── BaseEntity.java │ │ │ └── User.java │ │ │ └── config │ │ │ └── JacksonConfig.java │ ├── sharding-jdbc-5.0.0-simple-db-table │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── mapper │ │ │ │ ├── UserMapper.java │ │ │ │ ├── GoodsMapper.java │ │ │ │ └── SystemMapper.java │ │ │ │ ├── service │ │ │ │ ├── IUserService.java │ │ │ │ ├── IGoodsService.java │ │ │ │ ├── ISystemService.java │ │ │ │ └── impl │ │ │ │ │ ├── UserServiceImpl.java │ │ │ │ │ ├── GoodsServiceImpl.java │ │ │ │ │ └── SystemServiceImpl.java │ │ │ │ ├── ShardingJdbc5SimpleApplication.java │ │ │ │ └── config │ │ │ │ ├── MybatisPlusConfig.java │ │ │ │ └── JacksonConfig.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml └── pom.xml ├── spring-boot-canal ├── src │ └── main │ │ ├── resources │ │ └── application.yaml │ │ └── java │ │ └── com │ │ └── example │ │ ├── canal │ │ ├── annotation │ │ │ └── CanalTable.java │ │ ├── handler │ │ │ └── CanalEntryHandler.java │ │ └── properties │ │ │ └── CanalClientProperties.java │ │ ├── CanalApplication.java │ │ └── test │ │ ├── service │ │ └── AdminService.java │ │ └── entity │ │ └── Admin.java └── README.md ├── spring-boot-mybatis-plus ├── spring-boot-mybatis-plus-demo │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── mapper │ │ │ │ ├── AdminMapper.xml │ │ │ │ └── UserMapper.xml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── service │ │ │ ├── IUserService.java │ │ │ ├── IAdminService.java │ │ │ └── impl │ │ │ │ ├── UserServiceImpl.java │ │ │ │ └── AdminServiceImpl.java │ │ │ ├── mapper │ │ │ ├── UserMapper.java │ │ │ └── AdminMapper.java │ │ │ ├── config │ │ │ ├── base │ │ │ │ ├── IBaseEnum.java │ │ │ │ └── BaseEntity.java │ │ │ ├── CustomIdGenerator.java │ │ │ ├── MyMetaObjectHandler.java │ │ │ ├── JacksonConfig.java │ │ │ └── SwaggerConfig.java │ │ │ ├── MybatisPlusApplication.java │ │ │ ├── controller │ │ │ ├── UserController.java │ │ │ └── AdminController.java │ │ │ ├── enums │ │ │ └── GenderEnum.java │ │ │ └── entity │ │ │ ├── Admin.java │ │ │ └── User.java │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── BaseTest.java ├── spring-boot-mybatis-plus-dynamic-datasource-demo │ └── src │ │ ├── main │ │ ├── resources │ │ │ ├── mapper │ │ │ │ └── AdminMapper.xml │ │ │ └── spy.properties │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── mapper │ │ │ └── AdminMapper.java │ │ │ ├── service │ │ │ ├── IAdminService.java │ │ │ └── impl │ │ │ │ └── AdminServiceImpl.java │ │ │ ├── MybatisPlusDynamicDatasourceApplication.java │ │ │ ├── controller │ │ │ └── AdminController.java │ │ │ ├── entity │ │ │ └── Admin.java │ │ │ └── config │ │ │ ├── base │ │ │ └── BaseEntity.java │ │ │ └── SwaggerConfig.java │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── BaseTest.java ├── spring-boot-mybatis-plus-generate │ └── src │ │ └── main │ │ ├── resources │ │ ├── customComplexTemplates │ │ │ ├── service.java.ftl │ │ │ ├── repository.java.ftl │ │ │ ├── serviceImpl.java.ftl │ │ │ ├── repositoryImpl.java.ftl │ │ │ ├── mapper.java.ftl │ │ │ ├── mapper.xml.ftl │ │ │ └── controller.java.ftl │ │ └── customSimpleTemplates │ │ │ ├── service.java.ftl │ │ │ ├── mapper.java.ftl │ │ │ ├── serviceImpl.java.ftl │ │ │ ├── mapper.xml.ftl │ │ │ └── controller.java.ftl │ │ └── java │ │ └── com │ │ └── example │ │ ├── CustomFileInfo.java │ │ ├── CustomFreemarkerTemplateEngine.java │ │ └── entity │ │ └── base │ │ └── BaseEntity.java ├── spring-boot-mybatis-plus-simple │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── mapper │ │ │ └── UserMapper.java │ │ │ ├── service │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── MybatisPlusSimpleApplication.java │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── BaseTest.java ├── spring-boot-mybatis-plus-p6spy-demo │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── mapper │ │ │ │ └── UserMapper.java │ │ │ │ ├── MybatisPlusP6spyApplication.java │ │ │ │ └── entity │ │ │ │ └── User.java │ │ └── resources │ │ │ ├── spy.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ ├── BaseTest.java │ │ └── mapper │ │ └── UserMapperTest.java ├── README.md └── pom.xml ├── spring-boot-elasticsearch ├── spring-boot-elasticsearch-6 │ └── src │ │ ├── main │ │ ├── resources │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── dto │ │ │ └── User.java │ │ │ ├── ElasticSearch6Application.java │ │ │ └── dao │ │ │ └── ProductDao.java │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── BaseTest.java ├── spring-boot-elasticsearch-7 │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── dto │ │ │ │ └── User.java │ │ │ │ ├── ElasticSearch7Application.java │ │ │ │ └── dao │ │ │ │ └── ProductDao.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── eample │ │ └── BaseTest.java └── pom.xml ├── spring-boot-cache-redis └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── example │ │ │ ├── dto │ │ │ └── UserDto.java │ │ │ ├── RedisApplication.java │ │ │ └── constant │ │ │ └── Constants.java │ └── resources │ │ └── application.yaml │ └── test │ └── java │ └── com │ └── example │ └── BaseTest.java ├── spring-boot-cache ├── README.md ├── spring-boot-redis-cache │ └── src │ │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── BaseTest.java │ │ │ └── service │ │ │ └── CacheTest.java │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ ├── RedisCacheApplication.java │ │ │ ├── entity │ │ │ └── Admin.java │ │ │ └── service │ │ │ └── ICacheService.java │ │ └── resources │ │ └── application.yaml ├── spring-boot-caffeine-cache │ └── src │ │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── BaseTest.java │ │ │ └── service │ │ │ └── CacheTest.java │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── example │ │ │ ├── CaffeineCacheApplication.java │ │ │ ├── entity │ │ │ └── Admin.java │ │ │ └── service │ │ │ └── ICacheService.java │ │ └── resources │ │ └── application.yaml └── pom.xml ├── spring-boot-mq-rabbitmq ├── spring-boot-rabbitmq-simple │ ├── consumer-simple │ │ └── src │ │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── RabbitMQSimpleConsumerApplication.java │ │ │ └── consumer │ │ │ └── Consumer.java │ ├── producer-simple │ │ └── src │ │ │ ├── main │ │ │ ├── resources │ │ │ │ └── application.yml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── RabbitMQSimpleProducerApplication.java │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── ProducerSimpleTest.java │ └── pom.xml ├── spring-boot-rabbitmq │ ├── producer │ │ └── src │ │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── RabbitMQProducerApplication.java │ │ │ └── service │ │ │ └── impl │ │ │ └── RabbitMQServiceImpl.java │ ├── consumer │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ ├── RabbitMQConsumerApplication.java │ │ │ ├── work │ │ │ ├── Consumer1.java │ │ │ └── Consumer2.java │ │ │ ├── fanout │ │ │ ├── SmsConsumer.java │ │ │ └── WeixinConsumer.java │ │ │ ├── direct │ │ │ ├── InfoConsumer.java │ │ │ ├── AllConsumer.java │ │ │ └── ErrorConsumer.java │ │ │ └── topic │ │ │ ├── FullLogConsumer.java │ │ │ ├── InfoLogConsumer.java │ │ │ └── ErrorLogConsumer.java │ └── pom.xml ├── pom.xml └── README.md ├── spring-boot-mq-rocketmq ├── spring-boot-rocketmq │ ├── rocketmq-consumer │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── dto │ │ │ │ ├── OrderStep.java │ │ │ │ ├── BatchDto.java │ │ │ │ └── OrderPaidEvent.java │ │ │ │ ├── RocketMQConsumerApplication.java │ │ │ │ └── service │ │ │ │ └── ConsumerBroadcast.java │ │ │ └── resources │ │ │ └── application.yml │ ├── rocketmq-producer │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── dto │ │ │ │ ├── OrderStep.java │ │ │ │ ├── BatchDto.java │ │ │ │ └── OrderPaidEvent.java │ │ │ │ └── RocketMQProducerApplication.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml ├── spring-boot-rocketmq-simple │ ├── rocketmq-consumer-simple │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── RocketMQSimpleConsumerApplication.java │ │ │ │ └── service │ │ │ │ └── Consumer.java │ │ │ └── resources │ │ │ └── application.yml │ ├── rocketmq-producer-simple │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── example │ │ │ │ │ └── RocketMQSimpleProducerApplication.java │ │ │ └── resources │ │ │ │ └── application.yml │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── ProducerSimpleTest.java │ └── pom.xml ├── pom.xml └── README.md ├── spring-boot-session-data-redis └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ ├── SessionApplication.java │ │ └── controller │ │ └── SessionController.java │ └── resources │ └── application.yaml ├── .gitignore └── spring-boot-swagger ├── spring-boot-swagger-simple └── src │ └── main │ └── java │ └── com │ └── example │ ├── SwaggerSimpleApplication.java │ ├── dto │ └── User.java │ └── controller │ └── SwaggerTestController.java ├── pom.xml └── README.md /spring-boot-validator/README.md: -------------------------------------------------------------------------------- 1 | # validator 2 | 3 | ## 1 概述 4 | 参数校验示例 5 | -------------------------------------------------------------------------------- /spring-boot-logback/README.md: -------------------------------------------------------------------------------- 1 | # spring-boot-logback 2 | 3 | ## 1 概述 4 | 日志框架 5 | -------------------------------------------------------------------------------- /spring-boot-cache-caffeine/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | -------------------------------------------------------------------------------- /spring-boot-multi-threading/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | -------------------------------------------------------------------------------- /spring-boot-excel/assets/1585643739275.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WENZIZZHENG/spring-boot-demo/HEAD/spring-boot-excel/assets/1585643739275.png -------------------------------------------------------------------------------- /spring-boot-validator/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8888 3 | 4 | spring: 5 | application: 6 | name: validator-server 7 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/resources/excel/EasyExcel模板.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WENZIZZHENG/spring-boot-demo/HEAD/spring-boot-excel/src/main/resources/excel/EasyExcel模板.xls -------------------------------------------------------------------------------- /spring-boot-excel/src/main/resources/excel/EasyExcel模板.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WENZIZZHENG/spring-boot-demo/HEAD/spring-boot-excel/src/main/resources/excel/EasyExcel模板.xlsx -------------------------------------------------------------------------------- /spring-boot-excel/src/main/resources/excel/tOUTPRODUCT.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WENZIZZHENG/spring-boot-demo/HEAD/spring-boot-excel/src/main/resources/excel/tOUTPRODUCT.xlsx -------------------------------------------------------------------------------- /spring-boot-excel/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | 4 | 5 | spring: 6 | servlet: 7 | # 文件上传限制 8 | multipart: 9 | max-file-size: 100MB 10 | max-request-size: 100MB 11 | 12 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/resources/META-INF/services/org.apache.shardingsphere.spi.keygen.ShardingKeyGenerator: -------------------------------------------------------------------------------- 1 | com.example.config.sharding.key.ShardingTableKeyGenerator 2 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.KeyGenerateAlgorithm: -------------------------------------------------------------------------------- 1 | com.example.config.sharding.key.ShardingTableKeyGenerator 2 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | 4 | # canal配置,默认单例 5 | canal: 6 | host: 127.0.0.1 7 | port: 11111 8 | destination: example 9 | username: canal 10 | password: canal 11 | acknowledge-mode: true 12 | -------------------------------------------------------------------------------- /spring-boot-cache-caffeine/README.md: -------------------------------------------------------------------------------- 1 | # caffeine本地缓存 2 | 3 | ## 1 概述 4 | 5 | 本地缓存框架,性能贼高 6 | 7 | 性能测试详情:https://github.com/ben-manes/caffeine/wiki/Benchmarks-zh-CN 8 | 9 | 10 | 11 | 12 | 13 | ## 2 其它参考 14 | 15 | 官网文档:https://github.com/ben-manes/caffeine/wiki/Home-zh-CN 16 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/resources/mapper/AdminMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-6/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8088 3 | 4 | 5 | spring: 6 | data: 7 | elasticsearch: 8 | # 要连接到的Elasticsearch端点,多个用逗号分隔 9 | cluster-nodes: 127.0.0.1:9300 10 | # Elasticsearch集群名称 11 | cluster-name: elasticsearch 12 | 13 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/resources/META-INF/services/org.apache.shardingsphere.sharding.spi.ShardingAlgorithm: -------------------------------------------------------------------------------- 1 | com.example.config.sharding.algorithm.StandardModuloShardingTableAlgorithm 2 | com.example.config.sharding.algorithm.StandardModuloShardingDatabaseAlgorithm 3 | -------------------------------------------------------------------------------- /spring-boot-cache-redis/src/main/java/com/example/dto/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | *

7 | * 测试 8 | *

9 | * 10 | * @author MrWen 11 | **/ 12 | @Data 13 | public class UserDto { 14 | 15 | private String userName; 16 | 17 | private Integer age; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7878 3 | 4 | spring: 5 | application: 6 | # 服务名称 7 | name: logback-service 8 | profiles: 9 | # 环境标识 10 | active: dev 11 | 12 | 13 | #日志配置,debug级别 14 | logging: 15 | level: 16 | root: info 17 | # 路径 18 | com.example: debug 19 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/resources/mapper/AdminMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/service.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | /** 4 | *

5 | * ${table.comment!} 服务类 6 | *

7 | * 8 | * @author ${author} 9 | * @since ${date} 10 | */ 11 | public interface ${table.serviceName} { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /spring-boot-cache/README.md: -------------------------------------------------------------------------------- 1 | # spring cache缓存 2 | 3 | ## 1 概述 4 | 5 | spring cache整合其它缓存框架,这里整合了 6 | 7 | 1. redis 8 | 2. caffeine 9 | 10 | 11 | 12 | ## 2 其它参考 13 | 14 | springboot 使用 redis guava caffeine 缓存示例:https://github.com/zheng-zy/spring-boot-redis-guava-caffeine-cache 15 | 16 | spring cache注解简单了解:https://blog.csdn.net/zlj1217/article/details/80928122 -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/consumer-simple/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 配置tomcat端口号 2 | server: 3 | port: 9000 4 | 5 | # 配置rabbitmq 6 | spring: 7 | rabbitmq: 8 | host: 127.0.0.1 #mq地址 9 | port: 5672 #端口 10 | username: guest #登录账号 11 | password: guest #登录密码 12 | virtual-host: / #虚拟机 13 | 14 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/producer-simple/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 配置tomcat端口号 2 | server: 3 | port: 9001 4 | 5 | # 配置rabbitmq 6 | spring: 7 | rabbitmq: 8 | host: 127.0.0.1 #mq地址 9 | port: 5672 #端口 10 | username: guest #登录账号 11 | password: guest #登录密码 12 | virtual-host: / #虚拟机 13 | 14 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-7/src/main/java/com/example/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | *

7 | * 原生操作的测试对象 8 | *

9 | * 10 | * @author MrWen 11 | **/ 12 | @Data 13 | public class User { 14 | private String name; 15 | private String sex; 16 | private Integer age; 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-6/src/main/java/com/example/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | 4 | import lombok.Data; 5 | 6 | /** 7 | *

8 | * 原生操作的测试对象 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @Data 14 | public class User { 15 | private String name; 16 | private String sex; 17 | private Integer age; 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/repository.java.ftl: -------------------------------------------------------------------------------- 1 | package ${repositoryPackage}; 2 | 3 | import ${package.Entity}.${entity}; 4 | 5 | /** 6 | *

7 | * ${table.comment!} 持久层 8 | *

9 | * 10 | * @author ${author} 11 | * @since ${date} 12 | */ 13 | public interface ${repositoryName} { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-12-02 13 | */ 14 | public interface IUserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-simple/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-30 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/service/IAdminService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.Admin; 5 | 6 | /** 7 | *

8 | * 管理员表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-12-02 13 | */ 14 | public interface IAdminService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-simple/src/main/java/com/example/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-30 13 | */ 14 | public interface IUserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/IRedisService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | /** 4 | *

5 | * redis相关的 6 | *

7 | * 8 | * @author MrWen 9 | **/ 10 | public interface IRedisService { 11 | 12 | /** 13 | * 自增操作 14 | * 15 | * @param delta 自增步长 16 | */ 17 | Long increment(String key, long delta); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/IRedisService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | /** 4 | *

5 | * redis相关的 6 | *

7 | * 8 | * @author MrWen 9 | **/ 10 | public interface IRedisService { 11 | 12 | /** 13 | * 自增操作 14 | * 15 | * @param delta 自增步长 16 | */ 17 | Long increment(String key, long delta); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/producer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # 配置tomcat端口号 2 | server: 3 | port: 9002 4 | 5 | # 配置rabbitmq 6 | spring: 7 | rabbitmq: 8 | host: 127.0.0.1 #mq地址 9 | port: 5672 #端口 10 | username: guest #登录账号 11 | password: guest #登录密码 12 | virtual-host: / #虚拟机 13 | #publisher-confirms: true # 开启消息发送确认机制,低版本 14 | publisher-confirm-type: correlated # 开启消息发送确认机制 15 | 16 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IUserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IUserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-simple/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/mapper/GoodsMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface GoodsMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/IGoodsService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IGoodsService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IUserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/mapper/GoodsMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface GoodsMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/IGoodsService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IGoodsService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface UserMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.User; 5 | 6 | /** 7 | *

8 | * 用户表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IUserService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-cache-redis/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = RedisApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | *

9 | * 用户 Mapper 接口 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @Repository 15 | public interface UserMapper extends BaseMapper { 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/mapper/SystemMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.System; 5 | 6 | /** 7 | *

8 | * 系统配置表格 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface SystemMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/mapper/GoodsMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface GoodsMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/mapper/SystemMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.System; 5 | 6 | /** 7 | *

8 | * 系统配置表格 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface SystemMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/mapper/GoodsMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface GoodsMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-cache-caffeine/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = CaffeineApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/ISystemService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.example.entity.System; 6 | 7 | /** 8 | *

9 | * 系统配置表格 服务类 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-11-28 14 | */ 15 | public interface ISystemService extends IService { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/mapper/SystemMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.System; 5 | 6 | /** 7 | *

8 | * 系统配置表格 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface SystemMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/service/IGoodsService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IGoodsService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/ISystemService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.example.entity.System; 6 | 7 | /** 8 | *

9 | * 系统配置表格 服务类 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-11-28 14 | */ 15 | public interface ISystemService extends IService { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/mapper/SystemMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.System; 5 | 6 | /** 7 | *

8 | * 系统配置表格 Mapper 接口 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface SystemMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/service/IGoodsService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.Goods; 5 | 6 | /** 7 | *

8 | * 商品基本信息表 服务类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2021-11-28 13 | */ 14 | public interface IGoodsService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /spring-boot-multi-threading/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = MultiThreadApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/service/ISystemService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.example.entity.System; 6 | 7 | /** 8 | *

9 | * 系统配置表格 服务类 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-11-28 14 | */ 15 | public interface ISystemService extends IService { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/service/ISystemService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.example.entity.System; 6 | 7 | /** 8 | *

9 | * 系统配置表格 服务类 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-11-28 14 | */ 15 | public interface ISystemService extends IService { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-redis-cache/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = RedisCacheApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-caffeine-cache/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = CaffeineCacheApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.User; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | *

9 | * 用户 Mapper 接口 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-12-02 14 | */ 15 | @Repository 16 | public interface UserMapper extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/mapper/AdminMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.Admin; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | *

9 | * 管理员表 Mapper 接口 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-12-02 14 | */ 15 | @Repository 16 | public interface AdminMapper extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-6/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = ElasticSearch6Application.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = MybatisPlusApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/ExcelApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class ExcelApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ExcelApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-cache-redis/src/main/java/com/example/RedisApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class RedisApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(RedisApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/java/com/example/LogbackApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class LogbackApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(LogbackApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = MybatisPlusP6spyApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/mapper/AdminMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.example.entity.Admin; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | *

9 | * 管理员表 Mapper 接口 10 | *

11 | * 12 | * @author MrWen 13 | * @since 2021-12-07 14 | */ 15 | @Repository 16 | public interface AdminMapper extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /spring-boot-cache-caffeine/src/main/java/com/example/CaffeineApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class CaffeineApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(CaffeineApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-consumer/src/main/java/com/example/dto/OrderStep.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | *

10 | * 顺序的步骤 11 | *

12 | * 13 | * @author MrWen 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class OrderStep { 20 | private long orderId; 21 | private String desc; 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-producer/src/main/java/com/example/dto/OrderStep.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | *

10 | * 顺序的步骤 11 | *

12 | * 13 | * @author MrWen 14 | */ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class OrderStep { 20 | private long orderId; 21 | private String desc; 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-validator/src/main/java/com/example/ValidatorApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class ValidatorApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ValidatorApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-cache-caffeine/src/main/java/com/example/dto/UserDto.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | *

10 | * 测试dto 11 | *

12 | * 13 | * @author MrWen 14 | **/ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class UserDto { 20 | 21 | private Long id; 22 | 23 | private String userName; 24 | 25 | private Integer age; 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-session-data-redis/src/main/java/com/example/SessionApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class SessionApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(SessionApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/config/base/IBaseEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.config.base; 2 | 3 | import com.baomidou.mybatisplus.annotation.IEnum; 4 | 5 | import java.io.Serializable; 6 | 7 | 8 | /** 9 | *

10 | * MP基础枚举注 11 | *

12 | * 13 | * @author MrWen 14 | **/ 15 | public interface IBaseEnum extends IEnum { 16 | 17 | /** 18 | * 获取描述 19 | * 20 | * @return 描述 21 | */ 22 | String getDescription(); 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-cache-caffeine/src/main/java/com/example/dto/ItemStock.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | *

10 | * 测试dto 11 | *

12 | * 13 | * @author MrWen 14 | **/ 15 | @Data 16 | @Builder 17 | @NoArgsConstructor 18 | @AllArgsConstructor 19 | public class ItemStock { 20 | 21 | private Long id; 22 | 23 | private Integer stock; 24 | 25 | private Integer sold; 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/test/java/com/example/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.junit.runner.RunWith; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.test.context.junit4.SpringRunner; 6 | 7 | /** 8 | *

9 | * 基础测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootTest(classes = MybatisPlusDynamicDatasourceApplication.class) 15 | @RunWith(SpringRunner.class) 16 | public class BaseTest { 17 | } 18 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-redis-cache/src/main/java/com/example/RedisCacheApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class RedisCacheApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(RedisCacheApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/java/com/example/canal/annotation/CanalTable.java: -------------------------------------------------------------------------------- 1 | package com.example.canal.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | *

10 | * 需要处理的table 11 | *

12 | * 13 | * @author MrWen 14 | */ 15 | @Target(ElementType.TYPE) 16 | @Retention(RetentionPolicy.RUNTIME) 17 | public @interface CanalTable { 18 | 19 | String value() default ""; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-7/src/test/java/com/eample/BaseTest.java: -------------------------------------------------------------------------------- 1 | package com.eample; 2 | 3 | import com.example.ElasticSearch7Application; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | /** 9 | *

10 | * 基础测试 11 | *

12 | * 13 | * @author MrWen 14 | **/ 15 | @SpringBootTest(classes = ElasticSearch7Application.class) 16 | @RunWith(SpringRunner.class) 17 | public class BaseTest { 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #官方忽略 2 | # Compiled class file 3 | *.class 4 | 5 | # Log file 6 | *.log 7 | 8 | # BlueJ files 9 | *.ctxt 10 | 11 | # Mobile Tools for Java (J2ME) 12 | .mtj.tmp/ 13 | 14 | # Package Files # 15 | *.jar 16 | *.war 17 | *.nar 18 | *.ear 19 | *.zip 20 | *.tar.gz 21 | *.rar 22 | 23 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 24 | hs_err_pid* 25 | 26 | #新增 27 | .classpath 28 | .project 29 | .settings 30 | target 31 | 32 | #idea 33 | *.iml 34 | .idea 35 | 36 | node_modules 37 | 38 | sql/test.sql 39 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-caffeine-cache/src/main/java/com/example/CaffeineCacheApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class CaffeineCacheApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(CaffeineCacheApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-swagger/spring-boot-swagger-simple/src/main/java/com/example/SwaggerSimpleApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class SwaggerSimpleApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(SwaggerSimpleApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-6/src/main/java/com/example/ElasticSearch6Application.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class ElasticSearch6Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ElasticSearch6Application.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-7/src/main/java/com/example/ElasticSearch7Application.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | @SpringBootApplication 14 | public class ElasticSearch7Application { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(ElasticSearch7Application.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/producer/src/main/java/com/example/RabbitMQProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | */ 13 | @SpringBootApplication 14 | public class RabbitMQProducerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(RabbitMQProducerApplication.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customSimpleTemplates/service.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Service}; 2 | 3 | import ${superServiceClassPackage}; 4 | import ${package.Entity}.${entity}; 5 | 6 | /** 7 | *

8 | * ${table.comment!} 服务类 9 | *

10 | * 11 | * @author ${author} 12 | * @since ${date} 13 | */ 14 | <#if kotlin> 15 | interface ${table.serviceName} : ${superServiceClass}<${entity}> 16 | <#else> 17 | public interface ${table.serviceName} extends ${superServiceClass}<${entity}> { 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/RabbitMQConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | */ 13 | @SpringBootApplication 14 | public class RabbitMQConsumerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(RabbitMQConsumerApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-cache-redis/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | 4 | 5 | spring: 6 | # redis配置 7 | redis: 8 | # redis地址 9 | host: 127.0.0.1 10 | # 端口 11 | port: 6379 12 | # 数据库索引 13 | database: 0 14 | # 连接超时时间(毫秒) 15 | timeout: 30000ms 16 | # jedis连接池 17 | jedis: 18 | pool: 19 | # 连接池最大连接数(使用负值表示没有限制) 20 | max-active: 100 21 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 22 | max-wait: -1 23 | # 连接池中的最小空闲连接 24 | min-idle: 1 25 | # 连接池中的最大空闲连接 26 | max-idle: 100 27 | 28 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/consumer-simple/src/main/java/com/example/RabbitMQSimpleConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | */ 13 | @SpringBootApplication 14 | public class RabbitMQSimpleConsumerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(RabbitMQSimpleConsumerApplication.class); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/producer-simple/src/main/java/com/example/RabbitMQSimpleProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | */ 13 | @SpringBootApplication 14 | public class RabbitMQSimpleProducerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(RabbitMQSimpleProducerApplication.class); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-consumer/src/main/java/com/example/RocketMQConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2022-01-06 17:10 13 | */ 14 | @SpringBootApplication 15 | public class RocketMQConsumerApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(RocketMQConsumerApplication.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-producer/src/main/java/com/example/RocketMQProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2022-01-06 17:10 13 | */ 14 | @SpringBootApplication 15 | public class RocketMQProducerApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(RocketMQProducerApplication.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/service/IAdminService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.example.entity.Admin; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | *

10 | * 管理员表 服务类 11 | *

12 | * 13 | * @author MrWen 14 | * @since 2021-12-07 15 | */ 16 | public interface IAdminService extends IService { 17 | 18 | /** 19 | * 获取所有从库的Admin 20 | * 21 | * @return 从库的Admin 22 | */ 23 | List selectSlaveAdmin(); 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-multi-threading/src/main/java/com/example/MultiThreadApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @EnableAsync//多线程 15 | @SpringBootApplication 16 | public class MultiThreadApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(MultiThreadApplication.class); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/java/com/example/CustomFileInfo.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | *

7 | * 自定义文件属性 8 | *

9 | * 10 | * @author MrWen 11 | **/ 12 | @Data 13 | public class CustomFileInfo { 14 | 15 | /** 16 | * 文件名称 17 | */ 18 | private String fileName; 19 | 20 | /** 21 | * 目录(相对路径) 22 | */ 23 | private String fileDir; 24 | 25 | public CustomFileInfo(String fileName, String fileDir) { 26 | this.fileName = fileName; 27 | this.fileDir = fileDir; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-cache-redis/src/main/java/com/example/constant/Constants.java: -------------------------------------------------------------------------------- 1 | package com.example.constant; 2 | 3 | /** 4 | *

5 | * 常量 6 | *

7 | * 8 | * @author MrWen 9 | **/ 10 | public class Constants { 11 | /** 12 | * redis缓存 锁前缀 13 | */ 14 | public static final String LOCK_SUFFIX = "MALL_LOCK"; 15 | 16 | 17 | /** 18 | * 获取redis缓存key 19 | * 20 | * @param prefix 前缀 21 | * @param value 后缀 22 | * @return redis缓存key 23 | */ 24 | public static String getRedisKey(String prefix, Object... value) { 25 | return String.format(prefix, value); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-caffeine-cache/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | 4 | 5 | spring: 6 | # spring cache整合 7 | cache: 8 | type: caffeine 9 | # 如果底层缓存管理器支持的话,要创建的以逗号分隔的缓存名称列表。通常,这将禁用动态创建额外缓存的能力。(不建议) 10 | #cache-names: user,info 11 | # 默认配置(如果要每个cache配置不同的参数,比如过期时长、最大容量。可以结合配置类 CaffeineConfig 一起操作) 12 | caffeine: 13 | # 配置详情;https://github.com/ben-manes/caffeine/wiki/Specification-zh-CN 14 | # maximumSize:缓存的最大条数,expireAfterWrite:最后一次写入后经过固定时间过期(integer类型之后跟上一个"d","h","m",或者"s"来分别表示天,小时,分钟或者秒) 15 | spec: maximumSize=500,expireAfterWrite=30m 16 | 17 | 18 | -------------------------------------------------------------------------------- /spring-boot-canal/README.md: -------------------------------------------------------------------------------- 1 | # canal 2 | 3 | ## 1 概述 4 | 5 | 阿里巴巴 MySQL binlog 增量订阅&消费组件 6 | 7 | 因为canal官方demo并没有给spring boot封装详情demo,所以这里就以spring boot封装以便处理数据。 8 | 9 | 10 | 11 | **使用注意:** 12 | 13 | 获取表名,优先级从左到右 **@CanalTable**-->**@TableName** 14 | 15 | canal拉取数据:以定时任务触发(启动类记得加**@EnableScheduling **),当然也可以像canal官方demo一样,用while一直循环获取 16 | 17 | 18 | 19 | ## 2 其它参考 20 | 21 | 官网文档:https://github.com/alibaba/canal/wiki 22 | 23 | spring boot canal starter 易用的canal 客户端:https://github.com/NormanGyllenhaal/canal-client 24 | 25 | 基于canal的mysql和elasticsearch实时同步方案,支持增量同步和全量同步:https://github.com/starcwang/canal_mysql_elasticsearch_sync 26 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/rocketmq-consumer-simple/src/main/java/com/example/RocketMQSimpleConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2022-01-06 16:17 13 | */ 14 | @SpringBootApplication 15 | public class RocketMQSimpleConsumerApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(RocketMQSimpleConsumerApplication.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-simple/src/main/java/com/example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.User; 5 | import com.example.mapper.UserMapper; 6 | import com.example.service.IUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 用户 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-30 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements IUserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/java/com/example/CanalApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @EnableScheduling//这里以定时任务触发,当然也可以想canal官方demo一样,用while一直循环获取 15 | @SpringBootApplication 16 | public class CanalApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(CanalApplication.class); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/rocketmq-producer-simple/src/main/java/com/example/RocketMQSimpleProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | *

8 | * 启动类 9 | *

10 | * 11 | * @author MrWen 12 | * @since 2022-01-06 16:11 13 | */ 14 | @SpringBootApplication 15 | public class RocketMQSimpleProducerApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(RocketMQSimpleProducerApplication.class); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/MybatisPlusApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class MybatisPlusApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(MybatisPlusApplication.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/java/com/example/canal/handler/CanalEntryHandler.java: -------------------------------------------------------------------------------- 1 | package com.example.canal.handler; 2 | 3 | /** 4 | *

5 | * canal数据处理接口 6 | *

7 | * 8 | * @author MrWen 9 | */ 10 | public interface CanalEntryHandler { 11 | 12 | /** 13 | * 新增 14 | * 15 | * @param t 新增数据 16 | */ 17 | void insert(T t); 18 | 19 | 20 | /** 21 | * 修改 22 | * 23 | * @param before 修改前数据 24 | * @param after 修改后数据 25 | */ 26 | void update(T before, T after); 27 | 28 | 29 | /** 30 | * 删除 31 | * 32 | * @param t 删除数据 33 | */ 34 | void delete(T t); 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-consumer/src/main/java/com/example/dto/BatchDto.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | *

12 | * 批量消息实体 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | public class BatchDto implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | private Integer id; 26 | 27 | private String message; 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-producer/src/main/java/com/example/dto/BatchDto.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | *

12 | * 批量消息实体 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | public class BatchDto implements Serializable { 22 | 23 | private static final long serialVersionUID = 1L; 24 | 25 | private Integer id; 26 | 27 | private String message; 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/main/java/com/example/MybatisPlusP6spyApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class MybatisPlusP6spyApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(MybatisPlusP6spyApplication.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-7/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | 4 | 5 | spring: 6 | data: 7 | #es配置 8 | elasticsearch: 9 | client: 10 | reactive: 11 | # 要连接到的Elasticsearch端点,多个用逗号分隔 12 | endpoints: localhost:9200 13 | # 客户机是否应该使用SSL连接到端点。 14 | #use-ssl: 15 | # 凭证用户名 16 | #username: 17 | # 凭证密码 18 | #password: 19 | # 连接超时。 20 | #connection-timeout: 10000 21 | # 读写套接字超时。 22 | #socket-timeout: 10000 23 | # 限制在需要聚合输入流时可以缓冲的字节数。 24 | #max-in-memory-size: 25 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.User; 5 | import com.example.mapper.UserMapper; 6 | import com.example.service.IUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 用户表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements IUserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.User; 5 | import com.example.mapper.UserMapper; 6 | import com.example.service.IUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 用户表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements IUserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-simple/src/main/java/com/example/MybatisPlusSimpleApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * mybatis-pluis 快速入门 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class MybatisPlusSimpleApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(MybatisPlusSimpleApplication.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.User; 5 | import com.example.mapper.UserMapper; 6 | import com.example.service.IUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 用户表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements IUserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.User; 5 | import com.example.mapper.UserMapper; 6 | import com.example.service.IUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 用户表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class UserServiceImpl extends ServiceImpl implements IUserService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/README.md: -------------------------------------------------------------------------------- 1 | # Mybatis-Plus 2 | 3 | ## 1 概述 4 | 5 | [MyBatis-Plus (opens new window)](https://github.com/baomidou/mybatis-plus)(简称 MP)是一个 [MyBatis (opens new window)](https://www.mybatis.org/mybatis-3/)的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。 6 | 7 | 8 | 9 | 10 | 11 | ## 2 其它参考 12 | 13 | Mybatis-Plus官网相关文档已经很完善,有问题强烈建议阅读官方文档 14 | 15 | 1. [Mybatis-Plus官网文档]:https://mp.baomidou.com/ 16 | 2. [代码生成器]:https://mp.baomidou.com/guide/generator-new.html 17 | 3. [多数据源dynamic-datasource项目]:https://github.com/baomidou/dynamic-datasource-spring-boot-starter 18 | 4. [多数据源dynamic-datasource详细文档]:https://www.kancloud.cn/tracy5546/dynamic-datasource/2264611 19 | 20 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/impl/GoodsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.Goods; 5 | import com.example.mapper.GoodsMapper; 6 | import com.example.service.IGoodsService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 商品基本信息表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class GoodsServiceImpl extends ServiceImpl implements IGoodsService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/impl/GoodsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.Goods; 5 | import com.example.mapper.GoodsMapper; 6 | import com.example.service.IGoodsService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 商品基本信息表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class GoodsServiceImpl extends ServiceImpl implements IGoodsService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/ShardingJdbc4Application.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class ShardingJdbc4Application { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ShardingJdbc4Application.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/ShardingJdbc5Application.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class ShardingJdbc5Application { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ShardingJdbc5Application.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/serviceImpl.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${repositoryPackage}.${repositoryName}; 4 | import ${package.Service}.${table.serviceName}; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | *

10 | * ${table.comment!} 服务实现类 11 | *

12 | * 13 | * @author ${author} 14 | * @since ${date} 15 | */ 16 | @Service 17 | public class ${table.serviceImplName} implements ${table.serviceName} { 18 | 19 | @Autowired 20 | private ${repositoryName} ${myRepository}; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/service/impl/GoodsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.Goods; 5 | import com.example.mapper.GoodsMapper; 6 | import com.example.service.IGoodsService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 商品基本信息表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class GoodsServiceImpl extends ServiceImpl implements IGoodsService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/service/impl/GoodsServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.Goods; 5 | import com.example.mapper.GoodsMapper; 6 | import com.example.service.IGoodsService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 商品基本信息表 服务实现类 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2021-11-28 16 | */ 17 | @Service 18 | public class GoodsServiceImpl extends ServiceImpl implements IGoodsService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/impl/SystemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.example.entity.System; 6 | import com.example.mapper.SystemMapper; 7 | import com.example.service.ISystemService; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * 系统配置表格 服务实现类 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-11-28 17 | */ 18 | @Service 19 | public class SystemServiceImpl extends ServiceImpl implements ISystemService { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/impl/SystemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.example.entity.System; 6 | import com.example.mapper.SystemMapper; 7 | import com.example.service.ISystemService; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * 系统配置表格 服务实现类 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-11-28 17 | */ 18 | @Service 19 | public class SystemServiceImpl extends ServiceImpl implements ISystemService { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/service/impl/SystemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.example.entity.System; 6 | import com.example.mapper.SystemMapper; 7 | import com.example.service.ISystemService; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * 系统配置表格 服务实现类 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-11-28 17 | */ 18 | @Service 19 | public class SystemServiceImpl extends ServiceImpl implements ISystemService { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/service/impl/SystemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.example.entity.System; 6 | import com.example.mapper.SystemMapper; 7 | import com.example.service.ISystemService; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * 系统配置表格 服务实现类 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-11-28 17 | */ 18 | @Service 19 | public class SystemServiceImpl extends ServiceImpl implements ISystemService { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/ShardingJdbc4SimpleApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class ShardingJdbc4SimpleApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ShardingJdbc4SimpleApplication.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/ShardingJdbc5SimpleApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class ShardingJdbc5SimpleApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ShardingJdbc5SimpleApplication.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-boot-logback/src/main/java/com/example/controller/LogController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | *

9 | * logback日志测试 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @Slf4j 15 | @RestController 16 | @RequestMapping("/log") 17 | public class LogController { 18 | 19 | 20 | @RequestMapping("/test") 21 | public void test() { 22 | log.debug("debug日志测试啦!"); 23 | log.info("info日志测试啦!"); 24 | log.warn("warn日志测试啦!"); 25 | log.error("error日志测试啦!"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8096 3 | spring: 4 | application: 5 | name: rocketmq-producer 6 | 7 | rocketmq: 8 | name-server: 127.0.0.1:9876 # rocketMQ的名称服务器,格式为:' host:port;host:port '。 9 | # 生产端配置 10 | producer: 11 | group: ${spring.application.name} # 生产着组名 12 | #access-key: access-key # rocketMQ服务端配置acl授权信息,没有则不需要 13 | #secret-key: secret-key # rocketMQ服务端配置acl授权信息,没有则不需要 14 | # 消费端配置 15 | # consumer: 16 | # access-key: access-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 17 | # secret-key: secret-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 18 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-producer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8094 3 | spring: 4 | application: 5 | name: rocketmq-producer 6 | 7 | rocketmq: 8 | name-server: 127.0.0.1:9876 # rocketMQ的名称服务器,格式为:' host:port;host:port '。 9 | # 生产端配置 10 | producer: 11 | group: ${spring.application.name} # 生产着组名 12 | #access-key: access-key # rocketMQ服务端配置acl授权信息,没有则不需要 13 | #secret-key: secret-key # rocketMQ服务端配置acl授权信息,没有则不需要 14 | # 消费端配置 15 | # consumer: 16 | # access-key: access-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 17 | # secret-key: secret-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 18 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/MybatisPlusDynamicDatasourceApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | *

9 | * 启动类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @SpringBootApplication 15 | @MapperScan("com.example.mapper") 16 | public class MybatisPlusDynamicDatasourceApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(MybatisPlusDynamicDatasourceApplication.class); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/repositoryImpl.java.ftl: -------------------------------------------------------------------------------- 1 | package ${repositoryImplPackage}; 2 | 3 | import ${package.Entity}.${entity}; 4 | import ${package.Mapper}.${table.mapperName}; 5 | import ${repositoryPackage}.${repositoryName}; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * ${table.comment!} 持久层实现类 12 | *

13 | * 14 | * @author ${author} 15 | * @since ${date} 16 | */ 17 | @Service 18 | public class ${repositoryImplName} implements ${repositoryName} { 19 | 20 | @Autowired 21 | private ${table.mapperName} ${myMapper}; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/rocketmq-consumer-simple/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8092 3 | spring: 4 | application: 5 | name: rocketmq-consumer-simple 6 | 7 | rocketmq: 8 | name-server: 127.0.0.1:9876 # rocketMQ的名称服务器,格式为:' host:port;host:port '。 9 | # 生产端配置 10 | producer: 11 | group: ${spring.application.name} # 生产着组名 12 | #access-key: access-key # rocketMQ服务端配置acl授权信息,没有则不需要 13 | #secret-key: secret-key # rocketMQ服务端配置acl授权信息,没有则不需要 14 | # 消费端配置 15 | # consumer: 16 | # access-key: access-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 17 | # secret-key: secret-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 18 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/rocketmq-producer-simple/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8093 3 | spring: 4 | application: 5 | name: rocketmq-producer-simple 6 | 7 | rocketmq: 8 | name-server: 127.0.0.1:9876 # rocketMQ的名称服务器,格式为:' host:port;host:port '。 9 | # 生产端配置 10 | producer: 11 | group: ${spring.application.name} # 生产着组名 12 | #access-key: access-key # rocketMQ服务端配置acl授权信息,没有则不需要 13 | #secret-key: secret-key # rocketMQ服务端配置acl授权信息,没有则不需要 14 | # 消费端配置 15 | # consumer: 16 | # access-key: access-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 17 | # secret-key: secret-key #如果开启了acl,一定要配置。否则集群模式下会正常,广播模式消费端会失效! 18 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-caffeine-cache/src/main/java/com/example/entity/Admin.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.time.LocalDateTime; 10 | 11 | /** 12 | *

13 | * 管理员表 14 | *

15 | * 16 | * @author MrWen 17 | * @since 2021-05-07 18 | */ 19 | @Data 20 | @Builder 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | public class Admin implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | private Long id; 28 | 29 | private String userName; 30 | 31 | private LocalDateTime lastLoginTime; 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-redis-cache/src/main/java/com/example/entity/Admin.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.time.LocalDateTime; 10 | 11 | /** 12 | *

13 | * 管理员表 14 | *

15 | * 16 | * @author MrWen 17 | * @since 2021-05-07 18 | */ 19 | @Data 20 | @Builder 21 | @NoArgsConstructor 22 | @AllArgsConstructor 23 | public class Admin implements Serializable { 24 | 25 | private static final long serialVersionUID = 1L; 26 | 27 | private Long id; 28 | 29 | private String userName; 30 | 31 | private LocalDateTime lastLoginTime; 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-consumer/src/main/java/com/example/dto/OrderPaidEvent.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | 11 | /** 12 | *

13 | * 订单支付事件 14 | *

15 | * 16 | * @author MrWen 17 | */ 18 | @Data 19 | @Builder 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | public class OrderPaidEvent implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | private String orderId; 27 | 28 | private BigDecimal paidMoney; 29 | 30 | private String msg; 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | 4 | import com.example.service.IUserService; 5 | import io.swagger.annotations.Api; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | *

12 | * 用户 前端控制器 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-12-02 17 | */ 18 | @RestController 19 | @RequestMapping("/user") 20 | @Api(tags = "用户") 21 | public class UserController { 22 | 23 | @Autowired 24 | private IUserService userService; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-producer/src/main/java/com/example/dto/OrderPaidEvent.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | import java.io.Serializable; 9 | import java.math.BigDecimal; 10 | 11 | /** 12 | *

13 | * 订单支付事件 14 | *

15 | * 16 | * @author MrWen 17 | */ 18 | @Data 19 | @Builder 20 | @NoArgsConstructor 21 | @AllArgsConstructor 22 | public class OrderPaidEvent implements Serializable { 23 | 24 | private static final long serialVersionUID = 1L; 25 | 26 | 27 | private String orderId; 28 | 29 | private BigDecimal paidMoney; 30 | 31 | private String msg; 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | 4 | import com.example.service.IAdminService; 5 | import io.swagger.annotations.Api; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | *

12 | * 管理员表 前端控制器 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-12-02 17 | */ 18 | @RestController 19 | @RequestMapping("/admin") 20 | @Api(tags = "管理员表") 21 | public class AdminController { 22 | 23 | @Autowired 24 | private IAdminService adminService; 25 | 26 | 27 | } 28 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/service/IEasyExcelService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | /** 6 | *

7 | * easyexcel示例 8 | *

9 | * 10 | * @author MrWen 11 | **/ 12 | public interface IEasyExcelService { 13 | 14 | /** 15 | * 1普通excel xls格式导出 能支持xlsx,xls,csv格式导出 16 | */ 17 | void printExcel1(); 18 | 19 | /** 20 | * 2模板导出(数据填充) 能支持xlsx,xls,csv格式导出 21 | */ 22 | void printExcel2(); 23 | 24 | /** 25 | * 3excel导入 能支持xlsx,xls,csv格式 26 | * 参考:https://www.yuque.com/easyexcel/doc/read 27 | * 28 | * @param file excel文件(测试数据:printExcel1接口的导出结果即可) 29 | */ 30 | void importExcel(MultipartFile file); 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.User; 5 | import com.example.mapper.UserMapper; 6 | import com.example.service.IUserService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * 用户 服务实现类 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-12-02 17 | */ 18 | @Service 19 | public class UserServiceImpl extends ServiceImpl implements IUserService { 20 | 21 | @Autowired 22 | private UserMapper userMapper; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/controller/AdminController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | 4 | import com.example.service.IAdminService; 5 | import io.swagger.annotations.Api; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | *

12 | * 管理员表 前端控制器 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-12-07 17 | */ 18 | @RestController 19 | @RequestMapping("/admin") 20 | @Api(tags = "管理员表") 21 | public class AdminController { 22 | 23 | @Autowired 24 | private IAdminService adminService; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-mq-rabbitmq 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-mq-rocketmq 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/mapper.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${superMapperClassPackage}; 4 | import ${package.Entity}.${entity}; 5 | import org.springframework.stereotype.Repository; 6 | <#if mapperAnnotation> 7 | import org.apache.ibatis.annotations.Mapper; 8 | 9 | 10 | /** 11 | *

12 | * ${table.comment!} Mapper 接口 13 | *

14 | * 15 | * @author ${author} 16 | * @since ${date} 17 | */ 18 | <#if mapperAnnotation> 19 | @Mapper 20 | 21 | <#if kotlin> 22 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 23 | <#else> 24 | @Repository 25 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customSimpleTemplates/mapper.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Mapper}; 2 | 3 | import ${superMapperClassPackage}; 4 | import ${package.Entity}.${entity}; 5 | import org.springframework.stereotype.Repository; 6 | <#if mapperAnnotation> 7 | import org.apache.ibatis.annotations.Mapper; 8 | 9 | 10 | /** 11 | *

12 | * ${table.comment!} Mapper 接口 13 | *

14 | * 15 | * @author ${author} 16 | * @since ${date} 17 | */ 18 | <#if mapperAnnotation> 19 | @Mapper 20 | 21 | <#if kotlin> 22 | interface ${table.mapperName} : ${superMapperClass}<${entity}> 23 | <#else> 24 | @Repository 25 | public interface ${table.mapperName} extends ${superMapperClass}<${entity}> { 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-elasticsearch 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-mybatis-plus 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/service/impl/AdminServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.example.entity.Admin; 5 | import com.example.mapper.AdminMapper; 6 | import com.example.service.IAdminService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * 管理员表 服务实现类 13 | *

14 | * 15 | * @author MrWen 16 | * @since 2021-12-02 17 | */ 18 | @Service 19 | public class AdminServiceImpl extends ServiceImpl implements IAdminService { 20 | 21 | @Autowired 22 | private AdminMapper adminMapper; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-sharding-jdbc 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /spring-boot-session-data-redis/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | 4 | 5 | spring: 6 | # session配置 7 | session: 8 | # session存储方式 9 | store-type: redis 10 | # 过期时间,单位s 11 | timeout: 1800 12 | redis: 13 | # 立即写入会话存储 14 | flush-mode: immediate 15 | # redis配置 16 | redis: 17 | # redis地址 18 | host: 127.0.0.1 19 | # 端口 20 | port: 6379 21 | # 数据库索引 22 | database: 0 23 | # 连接超时时间(毫秒) 24 | timeout: 30000ms 25 | # jedis连接池 26 | jedis: 27 | pool: 28 | # 连接池最大连接数(使用负值表示没有限制) 29 | max-active: 100 30 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 31 | max-wait: -1 32 | # 连接池中的最小空闲连接 33 | min-idle: 1 34 | # 连接池中的最大空闲连接 35 | max-idle: 100 36 | 37 | -------------------------------------------------------------------------------- /spring-boot-swagger/spring-boot-swagger-simple/src/main/java/com/example/dto/User.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.AllArgsConstructor; 6 | import lombok.Builder; 7 | import lombok.Data; 8 | import lombok.NoArgsConstructor; 9 | 10 | /** 11 | *

12 | * 用户 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | @Data 18 | @Builder 19 | @NoArgsConstructor 20 | @AllArgsConstructor 21 | @ApiModel(value = "User对象", description = "用户") 22 | public class User { 23 | 24 | @ApiModelProperty("姓名") 25 | private String name; 26 | 27 | @ApiModelProperty("年龄") 28 | private Integer age; 29 | 30 | @ApiModelProperty("性别:0 未知, 1男, 2 女") 31 | private Integer gender; 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | ../../pom.xml 10 | 11 | 4.0.0 12 | 13 | spring-boot-rabbitmq 14 | 15 | 16 | 11 17 | 11 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | ../../pom.xml 10 | 11 | 4.0.0 12 | 13 | spring-boot-rocketmq 14 | 15 | 16 | 11 17 | 11 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-caffeine-cache/src/main/java/com/example/service/ICacheService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | 4 | import com.example.entity.Admin; 5 | 6 | /** 7 | *

8 | * 缓存测试 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | public interface ICacheService { 14 | 15 | /** 16 | * 详情 17 | * 18 | * @param id 主键 19 | * @return Admin对象 20 | */ 21 | Admin getById(Long id); 22 | 23 | 24 | /** 25 | * 保存 26 | * 27 | * @param admin admin 28 | * @return admin 29 | */ 30 | Admin save(Admin admin); 31 | 32 | /** 33 | * 保存 34 | * 35 | * @param admin admin 36 | * @return admin 37 | */ 38 | Admin update(Admin admin); 39 | 40 | /** 41 | * 删除 42 | * 43 | * @param id 主键 44 | */ 45 | void deleteById(Long id); 46 | } 47 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-redis-cache/src/main/java/com/example/service/ICacheService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | 4 | import com.example.entity.Admin; 5 | 6 | /** 7 | *

8 | * 缓存测试 9 | *

10 | * 11 | * @author MrWen 12 | **/ 13 | public interface ICacheService { 14 | 15 | /** 16 | * 详情 17 | * 18 | * @param id 主键 19 | * @return Admin对象 20 | */ 21 | Admin getById(Long id); 22 | 23 | 24 | /** 25 | * 保存 26 | * 27 | * @param admin admin 28 | * @return admin 29 | */ 30 | Admin save(Admin admin); 31 | 32 | /** 33 | * 保存 34 | * 35 | * @param admin admin 36 | * @return admin 37 | */ 38 | Admin update(Admin admin); 39 | 40 | /** 41 | * 删除 42 | * 43 | * @param id 主键 44 | */ 45 | void deleteById(Long id); 46 | } 47 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | ../../pom.xml 10 | 11 | 4.0.0 12 | 13 | spring-boot-rabbitmq-simple 14 | 15 | 16 | 11 17 | 11 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | ../../pom.xml 10 | 11 | 4.0.0 12 | 13 | spring-boot-rocketmq-simple 14 | 15 | 16 | 11 17 | 11 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/test/java/com/example/mapper/UserMapperTest.java: -------------------------------------------------------------------------------- 1 | package com.example.mapper; 2 | 3 | import com.example.BaseTest; 4 | import com.example.entity.User; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | /** 9 | *

10 | * 测试 11 | *

12 | * 13 | * @author MrWen 14 | **/ 15 | public class UserMapperTest extends BaseTest { 16 | 17 | @Autowired 18 | private UserMapper userMapper; 19 | 20 | @Test 21 | public void selectAll() { 22 | /* 23 | 控制台会输出: 24 | Consume Time:7 ms 2023-02-22 00:06:47 25 | Execute SQL:SELECT id,name,age,gender,email,manager_id FROM t_user WHERE id=1 26 | */ 27 | User user = userMapper.selectById(1L); 28 | System.out.println(user); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | ../../pom.xml 10 | 11 | 4.0.0 12 | 13 | spring-boot-sharding-jdbc-4.1.1 14 | 15 | 16 | 11 17 | 11 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/resources/spy.properties: -------------------------------------------------------------------------------- 1 | modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory 2 | # 自定义日志打印 3 | logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger 4 | #日志输出到控制台 5 | appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger 6 | # 使用日志系统记录 sql 7 | #appender=com.p6spy.engine.spy.appender.Slf4JLogger 8 | # 设置 p6spy driver 代理 9 | deregisterdrivers=true 10 | # 取消JDBC URL前缀 11 | useprefix=true 12 | # 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset. 13 | #excludecategories=info,debug,result,commit,resultset 14 | # 日期格式 15 | dateformat=yyyy-MM-dd HH:mm:ss 16 | # 实际驱动可多个 17 | driverlist=com.mysql.cj.jdbc.Driver 18 | # 是否开启慢SQL记录 19 | outagedetection=true 20 | # 慢SQL记录标准 2 秒 21 | outagedetectioninterval=2 22 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/service/impl/RedisServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.example.service.IRedisService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.redis.core.StringRedisTemplate; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * redis相关的 12 | *

13 | * 14 | * @author MrWen 15 | **/ 16 | @Slf4j 17 | @Service 18 | public class RedisServiceImpl implements IRedisService { 19 | 20 | 21 | @Autowired 22 | private StringRedisTemplate stringRedisTemplate; 23 | 24 | @Override 25 | public Long increment(String key, long delta) { 26 | return stringRedisTemplate.opsForValue().increment(key, delta); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/service/impl/RedisServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.example.service.IRedisService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.redis.core.StringRedisTemplate; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * redis相关的 12 | *

13 | * 14 | * @author MrWen 15 | **/ 16 | @Slf4j 17 | @Service 18 | public class RedisServiceImpl implements IRedisService { 19 | 20 | 21 | @Autowired 22 | private StringRedisTemplate stringRedisTemplate; 23 | 24 | @Override 25 | public Long increment(String key, long delta) { 26 | return stringRedisTemplate.opsForValue().increment(key, delta); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /spring-boot-swagger/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-swagger 13 | pom 14 | 15 | spring-boot-swagger-simple 16 | 17 | 18 | 19 | 11 20 | 11 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/consumer-simple/src/main/java/com/example/consumer/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.example.consumer; 2 | 3 | import org.springframework.amqp.rabbit.annotation.Queue; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | *

9 | * 消费着 10 | *

11 | * 12 | * @author MrWen 13 | */ 14 | @Component 15 | public class Consumer { 16 | 17 | /** 18 | * 消息监听方法 19 | * queuesToDeclare: 声明队列 20 | * durable: 是否为持久化队列 21 | */ 22 | @RabbitListener(queuesToDeclare = @Queue(name = "work-queue", durable = "true")) 23 | public void handlerMessage(String msg) { 24 | System.out.println("=====消费者===: " + msg); 25 | try { 26 | Thread.sleep(5000); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-cache/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | spring-boot-cache 13 | pom 14 | 15 | spring-boot-redis-cache 16 | spring-boot-caffeine-cache 17 | 18 | 19 | 20 | 11 21 | 11 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/main/java/com/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import lombok.Data; 8 | 9 | /** 10 | *

11 | * 用户 12 | *

13 | * 14 | * @author MrWen 15 | **/ 16 | @Data 17 | @TableName("t_user") 18 | public class User { 19 | @TableId(value = "id", type = IdType.ASSIGN_ID) 20 | private Long id; 21 | 22 | @TableField("name") 23 | private String name; 24 | 25 | @TableField("age") 26 | private Integer age; 27 | 28 | @TableField("gender") 29 | private Integer gender; 30 | 31 | @TableField("email") 32 | private String email; 33 | 34 | @TableField("manager_id") 35 | private Long managerId; 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-redis-cache/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 7777 3 | 4 | 5 | spring: 6 | # spring cache整合 7 | cache: 8 | type: redis 9 | redis: 10 | #允许缓存空值,默认true(能防止缓存穿透,也叫暴力缓存。) 11 | cache-null-values: true 12 | # 过期时间(这里是30min)。缺省情况下,表项永远不会过期。单位毫秒 13 | time-to-live: 1800000 14 | # key前缀 15 | key-prefix: 'cache:' 16 | # 当写入Redis时是否使用key前缀,默认true 17 | use-key-prefix: true 18 | 19 | # redis配置 20 | redis: 21 | # redis地址 22 | host: 127.0.0.1 23 | # 端口 24 | port: 6379 25 | # 数据库索引 26 | database: 0 27 | # 连接超时时间(毫秒) 28 | timeout: 30000ms 29 | # jedis连接池 30 | jedis: 31 | pool: 32 | # 连接池最大连接数(使用负值表示没有限制) 33 | max-active: 100 34 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 35 | max-wait: -1 36 | # 连接池中的最小空闲连接 37 | min-idle: 1 38 | # 连接池中的最大空闲连接 39 | max-idle: 100 40 | 41 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/java/com/example/test/service/AdminService.java: -------------------------------------------------------------------------------- 1 | package com.example.test.service; 2 | 3 | import com.example.canal.handler.CanalEntryHandler; 4 | import com.example.test.entity.Admin; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | *

10 | * 模式canal同步mysql测试 11 | *

12 | * 13 | * @author MrWen 14 | * @since 2021-12-02 15 | */ 16 | @Slf4j 17 | @Service 18 | public class AdminService implements CanalEntryHandler { 19 | 20 | @Override 21 | public void insert(Admin admin) { 22 | log.info("AdminService.insert---->admin={}", admin); 23 | } 24 | 25 | @Override 26 | public void update(Admin before, Admin after) { 27 | log.info("AdminService.update---->before={} ,after={}", before, after); 28 | } 29 | 30 | @Override 31 | public void delete(Admin admin) { 32 | log.info("AdminService.delete---->admin={}", admin); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/main/resources/spy.properties: -------------------------------------------------------------------------------- 1 | modulelist=com.baomidou.mybatisplus.extension.p6spy.MybatisPlusLogFactory,com.p6spy.engine.outage.P6OutageFactory 2 | # 自定义日志打印,这里使用的是mybatisPlus扩展的,如果非mybatisPlus项目,建议拷贝一份,没有任何其它依赖 3 | logMessageFormat=com.baomidou.mybatisplus.extension.p6spy.P6SpyLogger 4 | #日志输出到控制台,这里使用的是mybatisPlus扩展的,如果非mybatisPlus项目,建议拷贝一份,没有任何其它依赖 5 | appender=com.baomidou.mybatisplus.extension.p6spy.StdoutLogger 6 | # 使用日志系统记录 sql 7 | #appender=com.p6spy.engine.spy.appender.Slf4JLogger 8 | # 设置 p6spy driver 代理 9 | deregisterdrivers=true 10 | # 取消JDBC URL前缀 11 | useprefix=true 12 | # 配置记录 Log 例外,可去掉的结果集有error,info,batch,debug,statement,commit,rollback,result,resultset. 13 | #excludecategories=info,debug,result,commit,resultset 14 | # 日期格式 15 | dateformat=yyyy-MM-dd HH:mm:ss 16 | # 实际驱动可多个 17 | driverlist=com.mysql.cj.jdbc.Driver 18 | # 是否开启慢SQL记录 19 | outagedetection=true 20 | # 慢SQL记录标准 2 秒 21 | outagedetectioninterval=2 22 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/config/CustomIdGenerator.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; 4 | import lombok.extern.slf4j.Slf4j; 5 | 6 | import java.util.concurrent.atomic.AtomicLong; 7 | 8 | 9 | /** 10 | *

11 | * 自定义ID生成器, 仅作为示范(实际项目中 , 可以用雪花算法,或参考默认的DefaultIdentifierGenerator,继承重写它) 12 | *

13 | * 14 | * @author MrWen 15 | **/ 16 | @Slf4j 17 | public class CustomIdGenerator implements IdentifierGenerator { 18 | 19 | 20 | private final AtomicLong al = new AtomicLong(100); 21 | 22 | @Override 23 | public Long nextId(Object entity) { 24 | //可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成. 25 | String bizKey = entity.getClass().getName(); 26 | log.info("bizKey:{}", bizKey); 27 | final long id = al.getAndAdd(1); 28 | log.info("为{}生成主键值->:{}", bizKey, id); 29 | return id; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-session-data-redis/src/main/java/com/example/controller/SessionController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | import org.springframework.web.bind.annotation.*; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpSession; 7 | 8 | /** 9 | *

10 | * session测试 11 | *

12 | * 13 | * @author MrWen 14 | */ 15 | @RestController 16 | @RequestMapping("/session") 17 | public class SessionController { 18 | 19 | @GetMapping("/save/{message}") 20 | public String save(@PathVariable("message") String message, HttpServletRequest request) { 21 | HttpSession session = request.getSession(); 22 | session.setAttribute("test", message); 23 | return "success"; 24 | } 25 | 26 | 27 | @GetMapping("/detail") 28 | public String detail(HttpServletRequest request) { 29 | HttpSession session = request.getSession(); 30 | return (String) session.getAttribute("test"); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/work/Consumer1.java: -------------------------------------------------------------------------------- 1 | package com.example.work; 2 | 3 | import org.springframework.amqp.rabbit.annotation.Queue; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | *

9 | * work工作队列模式的消费者-只有一个消费者能接收到消息(竞争的消费者模式) 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @Component 15 | public class Consumer1 { 16 | 17 | /** 18 | * 消息监听方法 19 | * queuesToDeclare: 声明队列 20 | * durable: 是否为持久化队列 21 | */ 22 | @RabbitListener(queuesToDeclare = @Queue(name = "work-queue", durable = "true")) 23 | public void handlerMessage(String msg) { 24 | System.out.println("=====消费者1: " + msg); 25 | try { 26 | Thread.sleep(5000); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | //模拟消费失败,触发重试 31 | // int i = 1 / 0; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/work/Consumer2.java: -------------------------------------------------------------------------------- 1 | package com.example.work; 2 | 3 | import org.springframework.amqp.rabbit.annotation.Queue; 4 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | *

9 | * work工作队列模式的消费者-只有一个消费者能接收到消息(竞争的消费者模式) 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | @Component 15 | public class Consumer2 { 16 | 17 | /** 18 | * 消息监听方法 19 | * queuesToDeclare: 声明队列 20 | * durable: 是否为持久化队列 21 | */ 22 | @RabbitListener(queuesToDeclare = @Queue(name = "work-queue", durable = "true")) 23 | public void handlerMessage(String msg) { 24 | System.out.println("=====消费者2: " + msg); 25 | try { 26 | Thread.sleep(5000); 27 | } catch (Exception e) { 28 | e.printStackTrace(); 29 | } 30 | //模拟消费失败,触发重试 31 | // int i = 1 / 0; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-p6spy-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | 5 | # 数据源配置 6 | spring: 7 | jackson: 8 | date-format: yyyy-MM-dd HH:mm:ss 9 | time-zone: GMT+8 10 | datasource: 11 | type: com.alibaba.druid.pool.DruidDataSource 12 | # 原来 13 | # driverClassName: com.mysql.cj.jdbc.Driver 14 | # 使用p6spy后需要修改成的样子,还需要配置spy.properties 15 | driverClassName: com.p6spy.engine.spy.P6SpyDriver 16 | druid: 17 | # 原来 18 | # url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 19 | # 使用p6spy后需要修改成的样子,还需要配置spy.properties(注:有可能启动失败,就把useSSL=false) 20 | url: jdbc:p6spy:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 21 | username: root 22 | password: root 23 | #其它配置省略,详情请查看 spring-boot-mybatis-plus-demo 24 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/util/CommonUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.util; 2 | 3 | import org.springframework.web.context.request.RequestContextHolder; 4 | import org.springframework.web.context.request.ServletRequestAttributes; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.util.Objects; 9 | 10 | /** 11 | *

12 | * 通用util 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | public class CommonUtil { 18 | 19 | /** 20 | * 获取request 21 | */ 22 | public static HttpServletRequest getRequest() { 23 | return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); 24 | } 25 | 26 | /** 27 | * 获取response 28 | */ 29 | public static HttpServletResponse getResponse() { 30 | return ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getResponse(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /spring-boot-multi-threading/README.md: -------------------------------------------------------------------------------- 1 | # Spring Boot多线程 2 | 3 | ## 1 概述 4 | 5 | 以自定义线程池控制Spring Boot的多线程 6 | 7 | 8 | 9 | **多线程使用:** 10 | 11 | 1. 在启动类加上**@EnableAsync**注解 12 | 2. 在对应的方法加上**@Async()**注解,也可以是【建议】**@Async("default")**,其中default就是配置类**ThreadPoolTaskConfig**对应的线程池 13 | 14 | 15 | 16 | ## 2 @Async失效原因及解决方案 17 | 18 | 原因: 19 | 20 | 1. 没有在@SpringBootApplication启动类当中添加注解@EnableAsync注解。 21 | 2. 异步方法使用注解@Async的返回值只能为void或者Future。 22 | 3. 没有走Spring的代理类。因为@Transactional和@Async注解的实现都是基于Spring的AOP,而AOP的实现是基于动态代理模式实现的。那么注解失效的原因就很明显了,有可能因为**调用方法的是对象本身而不是代理对象**,因为没有经过Spring容器。**【简而言之:不能由本类内其它函数调用,必须是外部使用者调用。】** 23 | 24 | 解决方案(基于第三点) 25 | 26 | 1. 从上下文中获取Bean 27 | 2. 使用懒加载自己注入自己 28 | 3. 示例:**ThreadService** 29 | 30 | 31 | 32 | 33 | 34 | ## 3 其它参考 35 | 36 | 线程池:Java 线程池学习总结、拿来即用的 Java 线程池最佳实践:https://snailclimb.gitee.io/javaguide/#/./docs/java/concurrent/java%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93?id=%e4%b8%83-%e7%ba%bf%e7%a8%8b%e6%b1%a0%e5%a4%a7%e5%b0%8f%e7%a1%ae%e5%ae%9a 37 | 38 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customSimpleTemplates/serviceImpl.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.ServiceImpl}; 2 | 3 | import ${superServiceImplClassPackage}; 4 | import ${package.Entity}.${entity}; 5 | import ${package.Mapper}.${table.mapperName}; 6 | import ${package.Service}.${table.serviceName}; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | *

12 | * ${table.comment!} 服务实现类 13 | *

14 | * 15 | * @author ${author} 16 | * @since ${date} 17 | */ 18 | @Service 19 | <#if kotlin> 20 | open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} { 21 | 22 | } 23 | <#else> 24 | public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} { 25 | 26 | @Autowired 27 | private ${table.mapperName} ${myMapper}; 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /spring-boot-validator/src/main/java/com/example/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | import com.example.entity.User; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import javax.validation.Valid; 13 | 14 | /** 15 | *

16 | * 测试 17 | *

18 | * 19 | * @author MrWen 20 | **/ 21 | @Slf4j 22 | @RestController 23 | @RequestMapping("/user") 24 | @Api(tags = "用户测试") 25 | public class UserController { 26 | 27 | 28 | @PostMapping("/save") 29 | @ApiOperation("对象属性校验") 30 | public String save(@RequestBody @Valid User user) { 31 | log.info("save...user={}", user); 32 | return "save success"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-excel/README.md: -------------------------------------------------------------------------------- 1 | # excel操作示例 2 | 3 | ## 概述 4 | 5 | ### Excel的两种版本 6 | 7 | 目前世面上的Excel分为两个大的版本Excel2003和Excel2007及以上两个版本; 8 | 两者之间的区别如下: 9 | 10 | ![1585643739275](assets/1585643739275.png) 11 | 12 | Excel2003 是一个特有的二进制格式,其核心结构是复合文档类型的结构,存储数据量较小; 13 | 14 | Excel2007 的核心结构是 XML 类型的结构,采用的是基于 XML 的压缩方式,使其占用的空间更小,操作效率更高 15 | 16 | ### POI操作Excel高低版本区别 17 | 18 | 在POI包中有如下几个主要对象和excel的几个对象对应: 19 | 20 | | 对应excel名称 | 低版本中的类名 | 高版本中的类名 | 21 | | :------------ | :------------- | :------------- | 22 | | 工作簿 | HSSFWorkbook | XSSFWorkbook | 23 | | 工作表 | HSSFSheet | XSSFSheet | 24 | | 行 | HSSFRow | XSSFRow | 25 | | 单元格 | HSSFCell | XSSFCell | 26 | | 单元格样式 | HSSFCellStyle | XSSFCellStyle | 27 | 28 | 29 | 30 | 31 | 32 | ## 推荐 33 | 34 | **强烈推荐使用easyexcel,理由:** 35 | 36 | 1. 操作简单快捷 37 | 2. 解决原生POI在SAX模式下的内存溢出的问题 38 | 3. 文档完善 39 | 40 | easyexcel地址:https://github.com/alibaba/easyexcel 41 | 42 | easyexcel文档:https://www.yuque.com/easyexcel/doc/easyexcel -------------------------------------------------------------------------------- /spring-boot-swagger/spring-boot-swagger-simple/src/main/java/com/example/controller/SwaggerTestController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | import com.example.dto.User; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import io.swagger.annotations.ApiParam; 7 | import org.springframework.http.ResponseEntity; 8 | import org.springframework.web.bind.annotation.*; 9 | 10 | /** 11 | *

12 | * swagger测试 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | @RestController 18 | @RequestMapping("/test") 19 | @Api(tags = "swagger测试") 20 | public class SwaggerTestController { 21 | 22 | 23 | @ApiOperation(value = "向客人问好") 24 | @GetMapping("/sayHi") 25 | public ResponseEntity sayHi(@ApiParam("姓名") @RequestParam(value = "name") String name) { 26 | return ResponseEntity.ok("Hi:" + name); 27 | } 28 | 29 | 30 | @ApiOperation("新增") 31 | @PostMapping("/save") 32 | public User list(@RequestBody User user) { 33 | return user; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/java/com/example/test/entity/Admin.java: -------------------------------------------------------------------------------- 1 | package com.example.test.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableName; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Builder; 6 | import lombok.Data; 7 | import lombok.NoArgsConstructor; 8 | 9 | import java.time.LocalDateTime; 10 | import java.util.Date; 11 | 12 | /** 13 | *

14 | * 管理员表 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-12-02 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | //@CanalTable("t_admin")//优先这个 25 | @TableName("t_admin")//CanalTable不存在,才这个 26 | public class Admin { 27 | 28 | private Long id; 29 | 30 | private String userName; 31 | 32 | private String avatar; 33 | 34 | private LocalDateTime createTime; 35 | 36 | private String createName; 37 | 38 | private Date updateTime; 39 | 40 | private String updateName; 41 | 42 | private Integer version; 43 | 44 | private Boolean deleted; 45 | 46 | private Integer tenantId; 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | *

11 | * MP配置文件 12 | *

13 | * 14 | * @author MrWen 15 | */ 16 | @Configuration 17 | public class MybatisPlusConfig { 18 | 19 | 20 | /** 21 | * 分页插件, 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型 22 | */ 23 | @Bean 24 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 25 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 26 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 27 | return interceptor; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.baomidou.mybatisplus.annotation.DbType; 4 | import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; 5 | import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | /** 10 | *

11 | * MP配置文件 12 | *

13 | * 14 | * @author MrWen 15 | */ 16 | @Configuration 17 | public class MybatisPlusConfig { 18 | 19 | 20 | /** 21 | * 分页插件, 对于单一数据库类型来说,都建议配置该值,避免每次分页都去抓取数据库类型 22 | */ 23 | @Bean 24 | public MybatisPlusInterceptor mybatisPlusInterceptor() { 25 | MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); 26 | interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); 27 | return interceptor; 28 | } 29 | 30 | 31 | } 32 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | spring-boot-demo 7 | com.example 8 | 1.0-SNAPSHOT 9 | ../../pom.xml 10 | 11 | 4.0.0 12 | 13 | spring-boot-sharding-jdbc-5.0.0 14 | pom 15 | 16 | sharding-jdbc-5.0.0-simple-db-table 17 | sharding-jdbc-5.0.0-db-table 18 | 19 | 20 | 21 | 11 22 | 11 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/enums/GenderEnum.java: -------------------------------------------------------------------------------- 1 | package com.example.enums; 2 | 3 | import com.example.config.base.IBaseEnum; 4 | 5 | /** 6 | *

7 | * 性别枚举 8 | *

9 | * 10 | * @author MrWen 11 | **/ 12 | public enum GenderEnum implements IBaseEnum { 13 | 14 | UNKNOWN(0, "未知"), 15 | BOY(1, "男"), 16 | GIRL(2, "女"); 17 | 18 | private final int value; 19 | private final String desc; 20 | 21 | GenderEnum(int value, String desc) { 22 | this.value = value; 23 | this.desc = desc; 24 | } 25 | 26 | @Override 27 | public String getDescription() { 28 | return this.desc; 29 | } 30 | 31 | /** 32 | * mp会以这个为主 33 | */ 34 | @Override 35 | public Integer getValue() { 36 | return this.value; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "GenderEnum{" + 42 | "value=" + value + 43 | ", desc='" + desc + '\'' + 44 | '}'; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | # 端口 3 | port: 7877 4 | 5 | spring: 6 | profiles: 7 | # sharding-jdbc配置 8 | active: shardingjdbc4_simple 9 | jackson: 10 | # 日期格式器 jackson格式 11 | date-format: yyyy-MM-dd HH:mm:ss 12 | # 格林威冶标准时间 + 8 (北京时间) 13 | time-zone: GMT+8 14 | 15 | #日志配置 16 | logging: 17 | level: 18 | root: info 19 | com.example: debug 20 | # swagger 2.9.2 版本报错问题 21 | io.swagger.models.parameters.AbstractSerializableParameter: error 22 | 23 | # mybatis plus配置 24 | mybatis-plus: 25 | global-config: 26 | db-config: 27 | #数据库ID自增 28 | id-type: AUTO 29 | #逻辑未删除 默认0 字段需要在@TableLogic注解 30 | logic-not-delete-value: 0 31 | #逻辑删除 默认1 字段需要在@TableLogic注解 32 | logic-delete-value: 1 33 | #包路径扫描 34 | type-aliases-package: com.example.**.entity 35 | configuration: 36 | #驼峰命名 37 | map-underscore-to-camel-case: true 38 | #xml文件路径 39 | mapper-locations: classpath:mapper/*.xml 40 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | # 端口 3 | port: 7879 4 | 5 | spring: 6 | profiles: 7 | # sharding-jdbc配置 8 | active: shardingjdbc5_simple 9 | jackson: 10 | # 日期格式器 jackson格式 11 | date-format: yyyy-MM-dd HH:mm:ss 12 | # 格林威冶标准时间 + 8 (北京时间) 13 | time-zone: GMT+8 14 | 15 | #日志配置 16 | logging: 17 | level: 18 | root: info 19 | com.example: debug 20 | # swagger 2.9.2 版本报错问题 21 | io.swagger.models.parameters.AbstractSerializableParameter: error 22 | 23 | # mybatis plus配置 24 | mybatis-plus: 25 | global-config: 26 | db-config: 27 | #数据库ID自增 28 | id-type: AUTO 29 | #逻辑未删除 默认0 字段需要在@TableLogic注解 30 | logic-not-delete-value: 0 31 | #逻辑删除 默认1 字段需要在@TableLogic注解 32 | logic-delete-value: 1 33 | #包路径扫描 34 | type-aliases-package: com.example.**.entity 35 | configuration: 36 | #驼峰命名 37 | map-underscore-to-camel-case: true 38 | #xml文件路径 39 | mapper-locations: classpath:mapper/*.xml 40 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/dto/DemoData.java: -------------------------------------------------------------------------------- 1 | package com.example.dto; 2 | 3 | import com.alibaba.excel.annotation.ExcelIgnore; 4 | import com.alibaba.excel.annotation.ExcelProperty; 5 | import com.alibaba.excel.annotation.format.DateTimeFormat; 6 | import com.alibaba.excel.annotation.write.style.HeadStyle; 7 | import com.alibaba.excel.enums.poi.FillPatternTypeEnum; 8 | import lombok.Data; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | * 基础数据类 14 | * 15 | * @author Jiaju Zhuang 16 | **/ 17 | @Data 18 | // 头背景设置颜色设置 19 | @HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 23) 20 | public class DemoData { 21 | @ExcelProperty("字符串标题") 22 | private String string; 23 | 24 | @ExcelProperty("日期标题") 25 | private Date date; 26 | 27 | @DateTimeFormat("yyyy年MM月dd日HH时mm分ss秒") 28 | @ExcelProperty(value = "格式化日期标题") 29 | private Date dateFrom; 30 | 31 | @ExcelProperty("数字标题") 32 | private Double doubleData; 33 | 34 | /** 35 | * 忽略这个字段 36 | */ 37 | @ExcelIgnore 38 | private String ignore; 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/util/DataUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.util; 2 | 3 | import com.example.dto.DemoData; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | /** 10 | *

11 | * 获取导出模拟数据 12 | *

13 | * 14 | * @author MrWen 15 | * @since 2022-02-05 13:01 16 | */ 17 | public class DataUtil { 18 | 19 | /** 20 | * 获取数据(默认长度10) 21 | * 22 | * @return 对应长度的数据 23 | */ 24 | public static List data() { 25 | return data(10); 26 | } 27 | 28 | /** 29 | * 获取数据 30 | * 31 | * @param size list长度 32 | * @return 对应长度的数据 33 | */ 34 | public static List data(int size) { 35 | List list = new ArrayList<>(size); 36 | for (int i = 0; i < size; i++) { 37 | DemoData data = new DemoData(); 38 | data.setString("字符串" + i); 39 | data.setDate(new Date()); 40 | data.setDateFrom(new Date()); 41 | data.setDoubleData(0.56); 42 | list.add(data); 43 | } 44 | return list; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /spring-boot-canal/src/main/java/com/example/canal/properties/CanalClientProperties.java: -------------------------------------------------------------------------------- 1 | package com.example.canal.properties; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | *

8 | * canal客户端属性 9 | *

10 | * 11 | * @author MrWen 12 | */ 13 | @Data 14 | @ConfigurationProperties(prefix = "canal") 15 | public class CanalClientProperties { 16 | /** 17 | * ip地址 18 | */ 19 | private String host = "127.0.0.1"; 20 | 21 | /** 22 | * 端口 23 | */ 24 | private Integer port = 11111; 25 | 26 | /** 27 | * 描述 28 | */ 29 | private String destination = "example"; 30 | 31 | /** 32 | * 账号 33 | */ 34 | private String username = "canal"; 35 | 36 | /** 37 | * 密码 38 | */ 39 | private String password = "canal"; 40 | 41 | /** 42 | * 获取指定数量的数据 43 | */ 44 | private Integer batchSize = 1000; 45 | 46 | /** 47 | * 是否开启ack确认 48 | * true: 如果永远无法消费,将会死循环!! 49 | * false: 消息会丢失,照成消息不同步 50 | * 建议:false,把错误信息收集,后续人工处理。 51 | */ 52 | private Boolean acknowledgeMode = false; 53 | } 54 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/service/impl/AdminServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.baomidou.dynamic.datasource.annotation.DS; 4 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 5 | import com.example.entity.Admin; 6 | import com.example.mapper.AdminMapper; 7 | import com.example.service.IAdminService; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | *

15 | * 管理员表 服务实现类 16 | *

17 | * 18 | * @author MrWen 19 | * @since 2021-12-07 20 | */ 21 | @Service 22 | public class AdminServiceImpl extends ServiceImpl implements IAdminService { 23 | 24 | @Autowired 25 | private AdminMapper adminMapper; 26 | 27 | /** 28 | * 其实这里,用无注解或自定义注解形式,更加方便 29 | * 详情参考:https://www.kancloud.cn/tracy5546/dynamic-datasource/2327437 30 | */ 31 | @DS("slave") 32 | @Override 33 | public List selectSlaveAdmin() { 34 | return this.adminMapper.selectList(null); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /spring-boot-validator/src/main/java/com/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | import org.hibernate.validator.constraints.Length; 7 | 8 | import javax.validation.constraints.*; 9 | 10 | @Data 11 | @ApiModel("用户") 12 | public class User { 13 | @ApiModelProperty("用户id") 14 | @NotNull(message = "用户id不能为空") 15 | private Integer id; 16 | 17 | @ApiModelProperty("用户名") 18 | @NotEmpty(message = "用户名不能为空") 19 | @Length(min = 4, max = 30, message = "用户名只能在4~30位之间") 20 | private String username; 21 | 22 | @ApiModelProperty("年龄") 23 | @Min(message = "年龄最小为18岁", value = 18) 24 | @Max(message = "年龄最大为80岁", value = 80) 25 | @NotNull(message = "年龄不能为空") 26 | private int age; 27 | 28 | 29 | @ApiModelProperty("手机号") 30 | @Pattern(regexp = "^1[35678]\\d{9}$", message = "手机号格式不正确") 31 | @NotBlank(message = "不能为空") 32 | private String phone; 33 | 34 | 35 | @ApiModelProperty("邮箱") 36 | @NotBlank(message = "邮箱不能为空") 37 | @Email(message = "请输入正确的邮箱") 38 | private String email; 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq-simple/producer-simple/src/test/java/com/example/ProducerSimpleTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.junit.Test; 5 | import org.junit.runner.RunWith; 6 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.context.junit4.SpringRunner; 10 | 11 | /** 12 | *

13 | * 生产者 14 | *

15 | * 16 | * @author MrWen 17 | */ 18 | @Slf4j 19 | @RunWith(SpringRunner.class) 20 | @SpringBootTest(classes = RabbitMQSimpleProducerApplication.class) 21 | public class ProducerSimpleTest { 22 | @Autowired 23 | private RabbitTemplate rabbitTemplate; 24 | 25 | @Test 26 | public void sendMessage() { 27 | for (int i = 0; i < 10; i++) { 28 | /** 29 | * String exchange: 交换机 30 | * String routingKey: 路由key(队列名称) 31 | * Object message: 消息内容 32 | */ 33 | rabbitTemplate.convertAndSend("", "work-queue", "工作队列模式的消息!" + i); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/util/CommonUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.util; 2 | 3 | import cn.hutool.core.date.DateUtil; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | *

9 | * 通用工具类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | public class CommonUtil { 15 | 16 | /** 17 | * 时间转年分格式 18 | * 19 | * @param date 2021-11-28 15:41:26 20 | * @return 2021 21 | */ 22 | public static String date2YearStr(Date date) { 23 | return DateUtil.format(date, "yyyy"); 24 | } 25 | 26 | /** 27 | * 时间转季度格式 28 | * 29 | * @param date 2021-11-28 15:41:26 30 | * @return 10_12 31 | */ 32 | public static String date2QuarterStr(Date date) { 33 | int quarter = DateUtil.quarter(date); 34 | switch (quarter) { 35 | case 1: 36 | return "01_03"; 37 | case 2: 38 | return "04_06"; 39 | case 3: 40 | return "07_09"; 41 | case 4: 42 | return "10_12"; 43 | default: 44 | return ""; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/util/CommonUtil.java: -------------------------------------------------------------------------------- 1 | package com.example.util; 2 | 3 | import cn.hutool.core.date.DateUtil; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | *

9 | * 通用工具类 10 | *

11 | * 12 | * @author MrWen 13 | **/ 14 | public class CommonUtil { 15 | 16 | /** 17 | * 时间转年分格式 18 | * 19 | * @param date 2021-11-28 15:41:26 20 | * @return 2021 21 | */ 22 | public static String date2YearStr(Date date) { 23 | return DateUtil.format(date, "yyyy"); 24 | } 25 | 26 | /** 27 | * 时间转季度格式 28 | * 29 | * @param date 2021-11-28 15:41:26 30 | * @return 10_12 31 | */ 32 | public static String date2QuarterStr(Date date) { 33 | int quarter = DateUtil.quarter(date); 34 | switch (quarter) { 35 | case 1: 36 | return "01_03"; 37 | case 2: 38 | return "04_06"; 39 | case 3: 40 | return "07_09"; 41 | case 4: 42 | return "10_12"; 43 | default: 44 | return ""; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/entity/Admin.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.example.config.base.BaseEntity; 8 | import io.swagger.annotations.ApiModel; 9 | import io.swagger.annotations.ApiModelProperty; 10 | import lombok.*; 11 | 12 | /** 13 | *

14 | * 管理员表 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-12-02 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @EqualsAndHashCode(callSuper = true) 25 | @TableName("t_admin") 26 | @ApiModel(value = "Admin对象", description = "管理员表") 27 | public class Admin extends BaseEntity { 28 | 29 | @ApiModelProperty("主键") 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Long id; 32 | 33 | @ApiModelProperty("管理员名称") 34 | @TableField("user_name") 35 | private String userName; 36 | 37 | @ApiModelProperty("头像图片") 38 | @TableField("avatar") 39 | private String avatar; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/java/com/example/CustomFreemarkerTemplateEngine.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | import com.baomidou.mybatisplus.generator.config.OutputFile; 5 | import com.baomidou.mybatisplus.generator.config.po.TableInfo; 6 | import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; 7 | import org.jetbrains.annotations.NotNull; 8 | 9 | import java.io.File; 10 | import java.util.Map; 11 | 12 | /** 13 | *

14 | * 自定义Freemarker 模板引擎实现文件输出 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | public class CustomFreemarkerTemplateEngine extends FreemarkerTemplateEngine { 20 | 21 | @Override 22 | protected void outputCustomFile(@NotNull Map customFile, @NotNull TableInfo tableInfo, @NotNull Map objectMap) { 23 | customFile.forEach((key, value) -> { 24 | CustomFileInfo customFileInfo = (CustomFileInfo) objectMap.get(key); 25 | String fileName = String.format((customFileInfo.getFileDir() + File.separator + "%s"), customFileInfo.getFileName()); 26 | outputFile(new File(fileName), objectMap, value); 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/config/MyMetaObjectHandler.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; 4 | import org.apache.ibatis.reflection.MetaObject; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | *

10 | * MyBatis Plus 数据填充 元数据处理类 用于自动 createTime, updateTime, createUser, updateUser 等字段 11 | *

12 | * 13 | * @author MrWen 14 | **/ 15 | public class MyMetaObjectHandler implements MetaObjectHandler { 16 | 17 | /** 18 | * 插入时填充 19 | */ 20 | @Override 21 | public void insertFill(MetaObject metaObject) { 22 | setFieldValByName("createName", "testInsertName", metaObject); 23 | setFieldValByName("updateName", "testInsertName", metaObject); 24 | setFieldValByName("createTime", new Date(), metaObject); 25 | setFieldValByName("updateTime", new Date(), metaObject); 26 | } 27 | 28 | /** 29 | * 修改时填充 30 | */ 31 | @Override 32 | public void updateFill(MetaObject metaObject) { 33 | setFieldValByName("updateName", "testUpdateName2", metaObject); 34 | setFieldValByName("updateTime", new Date(), metaObject); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/entity/System.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import io.swagger.annotations.ApiModel; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.*; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 系统配置表格 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-11-28 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @EqualsAndHashCode(callSuper = false) 25 | @TableName("t_system") 26 | @ApiModel(value = "System对象", description = "系统配置表格") 27 | public class System extends BaseEntity implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | @ApiModelProperty(value = "主键") 32 | @TableId(value = "id", type = IdType.AUTO) 33 | private Long id; 34 | 35 | @ApiModelProperty(value = "系统配置名") 36 | private String keyName; 37 | 38 | @ApiModelProperty(value = "系统配置值") 39 | private String keyValue; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/entity/System.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import io.swagger.annotations.ApiModel; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.*; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 系统配置表格 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-11-28 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @EqualsAndHashCode(callSuper = false) 25 | @TableName("t_system") 26 | @ApiModel(value = "System对象", description = "系统配置表格") 27 | public class System extends BaseEntity implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | @ApiModelProperty(value = "主键") 32 | @TableId(value = "id", type = IdType.AUTO) 33 | private Long id; 34 | 35 | @ApiModelProperty(value = "系统配置名") 36 | private String keyName; 37 | 38 | @ApiModelProperty(value = "系统配置值") 39 | private String keyValue; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/rocketmq-consumer-simple/src/main/java/com/example/service/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 5 | import org.apache.rocketmq.spring.core.RocketMQListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Random; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | *

13 | * 消费者 14 | *

15 | * 16 | * @author MrWen 17 | * @since 2022-01-06 16:29 18 | */ 19 | @Slf4j 20 | @Component 21 | @RocketMQMessageListener( 22 | topic = "simple",//主题 23 | consumerGroup = "simple-consumer-group"//消费组 24 | ) 25 | public class Consumer implements RocketMQListener { 26 | 27 | 28 | @Override 29 | public void onMessage(String message) { 30 | Random random = new Random(); 31 | try { 32 | //模拟业务逻辑处理中... 33 | TimeUnit.SECONDS.sleep(random.nextInt(10)); 34 | log.info("Receive message: {} ThreadName: {}", message, Thread.currentThread().getName()); 35 | } catch (Exception e) { 36 | e.printStackTrace(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/entity/Admin.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.example.config.base.BaseEntity; 8 | import io.swagger.annotations.ApiModel; 9 | import io.swagger.annotations.ApiModelProperty; 10 | import lombok.*; 11 | 12 | /** 13 | *

14 | * 管理员表 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-12-07 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @EqualsAndHashCode(callSuper = true) 25 | @TableName("t_admin") 26 | @ApiModel(value = "Admin对象", description = "管理员表") 27 | public class Admin extends BaseEntity { 28 | 29 | @ApiModelProperty("主键") 30 | @TableId(value = "id", type = IdType.AUTO) 31 | private Long id; 32 | 33 | @ApiModelProperty("管理员名称") 34 | @TableField("user_name") 35 | private String userName; 36 | 37 | @ApiModelProperty("头像图片") 38 | @TableField("avatar") 39 | private String avatar; 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/config/base/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.config.base; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | /** 12 | *

13 | * 基础属性 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Data 19 | public class BaseEntity { 20 | 21 | @TableField(fill = FieldFill.INSERT) 22 | @ApiModelProperty(value = "创建时间") 23 | private Date createTime; 24 | 25 | @TableField(fill = FieldFill.INSERT) 26 | @ApiModelProperty(value = "创建者") 27 | private String createName; 28 | 29 | @TableField(fill = FieldFill.INSERT_UPDATE) 30 | @ApiModelProperty(value = "更新时间") 31 | private Date updateTime; 32 | 33 | @TableField(fill = FieldFill.INSERT_UPDATE) 34 | @ApiModelProperty(value = "修改者") 35 | private String updateName; 36 | 37 | @TableLogic 38 | @TableField(select = false) 39 | @ApiModelProperty(value = "逻辑删除") 40 | private Boolean deleted; 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | 12 | /** 13 | *

14 | * 基础属性 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-11-28 19 | */ 20 | @Data 21 | public class BaseEntity { 22 | 23 | @TableField(fill = FieldFill.INSERT) 24 | @ApiModelProperty(value = "创建时间") 25 | private Date createTime; 26 | 27 | @TableField(fill = FieldFill.INSERT) 28 | @ApiModelProperty(value = "创建者") 29 | private String createName; 30 | 31 | @TableField(fill = FieldFill.INSERT_UPDATE) 32 | @ApiModelProperty(value = "更新时间") 33 | private Date updateTime; 34 | 35 | @TableField(fill = FieldFill.INSERT_UPDATE) 36 | @ApiModelProperty(value = "修改者") 37 | private String updateName; 38 | 39 | @TableLogic 40 | @TableField(select = false) 41 | @ApiModelProperty(value = "逻辑删除") 42 | private Boolean deleted; 43 | } 44 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/entity/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import io.swagger.annotations.ApiModelProperty; 7 | import lombok.Data; 8 | 9 | import java.util.Date; 10 | 11 | 12 | /** 13 | *

14 | * 基础属性 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-11-28 19 | */ 20 | @Data 21 | public class BaseEntity { 22 | 23 | @TableField(fill = FieldFill.INSERT) 24 | @ApiModelProperty(value = "创建时间") 25 | private Date createTime; 26 | 27 | @TableField(fill = FieldFill.INSERT) 28 | @ApiModelProperty(value = "创建者") 29 | private String createName; 30 | 31 | @TableField(fill = FieldFill.INSERT_UPDATE) 32 | @ApiModelProperty(value = "更新时间") 33 | private Date updateTime; 34 | 35 | @TableField(fill = FieldFill.INSERT_UPDATE) 36 | @ApiModelProperty(value = "修改者") 37 | private String updateName; 38 | 39 | @TableLogic 40 | @TableField(select = false) 41 | @ApiModelProperty(value = "逻辑删除") 42 | private Boolean deleted; 43 | } 44 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/service/IPoiService.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import org.springframework.web.multipart.MultipartFile; 4 | 5 | /** 6 | *

7 | * poi示例 8 | *

9 | * 10 | * @author MrWen 11 | * @since 2022-02-05 18:10 12 | */ 13 | public interface IPoiService { 14 | 15 | /** 16 | * 1普通excel xls格式导出 17 | */ 18 | void printExcel1(); 19 | 20 | /** 21 | * 2模板导出 22 | * xls格式--HSSFWorkbook 23 | * xlsx格式--XSSFWorkbook 24 | */ 25 | void printExcel2(); 26 | 27 | /** 28 | * 3.1百万数据打印输出,不能模板导出 29 | * 样式不能太多(最多64000) 用SXSSFWorkbook这个实体类 必须是.xlsx 30 | */ 31 | void printExcel3(); 32 | 33 | /** 34 | * 3.2百万数据打印输出csv格式 35 | */ 36 | void printCsv(); 37 | 38 | 39 | /** 40 | * excel导出(少量数据) 41 | * 数据量少的时候可以用。简单方便(10万以下呗) 42 | * 一次全部加载到内存中,数据量大时会直接OOM,反正加载不完(测试:100万数据直接导入) 43 | * 44 | * @param file 测试数据:printExcel1或printExcel3接口的导出结果即可 45 | */ 46 | void importExcel(MultipartFile file); 47 | 48 | /** 49 | * 百万数据-大数据导入(只支持xlsx格式) 50 | * 解析是一条条解析,并不是全部加载到内存中。所以不会有OOM问题 51 | * 52 | * @param file 测试数据:printExcel1或printExcel3接口的导出结果即可 53 | */ 54 | void importExcel2(MultipartFile file); 55 | 56 | 57 | } 58 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/README.md: -------------------------------------------------------------------------------- 1 | # RabbitMQ 2 | 3 | ## 1 如何保障消息可靠生产(消息100%投递成功) 4 | 5 | **方案:消息落库,对消息状态进行打标** 6 | 7 | **步骤:** 8 | 9 | 1. 把消息发送MQ一份,同时存储到数据库(Redis)一份。开启消息发送确定机制,然后进行消息的状态控制,发送成功1,发送失败0。 10 | 2. 必须结合应答ACK(确认字符)来完成。对于那些如果没有发送成功的消息,可以采用定时器进行轮询发送。 11 | 12 | **示例** 13 | 14 | [application.yaml](spring-boot-rabbitmq/producer/src/main/resources/application.yml) 15 | 16 | [定义生产者确认回调对象](spring-boot-rabbitmq/producer/src/main/java/com/example/config/ProducerAckConfirmCallback.java) 17 | 18 | 19 | 20 | 21 | 22 | ## 2 消息可靠消费 23 | 24 | **步骤:** 25 | 26 | 1. 消费者开始手动ack消息确定 27 | 2. 尝试消息重投 28 | 3. 对重投还是消费失败的消息拒绝确认 29 | 4. 把拒绝确认的消息扔到死信队列中,并记录到数据库,再做好消息预警 30 | 31 | **示例** 32 | 33 | [application.yaml](spring-boot-rabbitmq/consumer/src/main/resources/application.yml) 34 | 35 | 需要开启下面的配置 36 | 37 | ```properties 38 | spring.rabbitmq.listener.acknowledge-mode=manual #消费者开启手动ack消息确认 39 | spring.rabbitmq.listener.default-requeue-rejected=false #设置为false,会重发消息到死信队列 40 | ``` 41 | 42 | **Consumer示例** 43 | 44 | 消费端手动确认[AckConsumer](spring-boot-rabbitmq/consumer/src/main/java/com/example/ack/AckConsumer.java) 45 | 46 | 死信队列[DeadLetterConsumer](spring-boot-rabbitmq/consumer/src/main/java/com/example/ack/DeadLetterConsumer.java) 47 | 48 | 49 | 50 | 51 | 52 | ## 3:待补充 53 | 54 | 1. 延时消息 55 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/mapper.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <#if enableCache> 6 | 7 | 8 | 9 | 10 | <#if baseResultMap> 11 | 12 | 13 | <#list table.fields as field> 14 | <#if field.keyFlag><#--生成主键排在第一位--> 15 | 16 | 17 | 18 | <#list table.commonFields as field><#--生成公共字段 --> 19 | 20 | 21 | <#list table.fields as field> 22 | <#if !field.keyFlag><#--生成普通字段 --> 23 | 24 | 25 | 26 | 27 | 28 | 29 | <#if baseColumnList> 30 | 31 | 32 | <#list table.commonFields as field> 33 | ${field.columnName}, 34 | 35 | ${table.fieldNames} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customSimpleTemplates/mapper.xml.ftl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | <#if enableCache> 6 | 7 | 8 | 9 | 10 | <#if baseResultMap> 11 | 12 | 13 | <#list table.fields as field> 14 | <#if field.keyFlag><#--生成主键排在第一位--> 15 | 16 | 17 | 18 | <#list table.commonFields as field><#--生成公共字段 --> 19 | 20 | 21 | <#list table.fields as field> 22 | <#if !field.keyFlag><#--生成普通字段 --> 23 | 24 | 25 | 26 | 27 | 28 | 29 | <#if baseColumnList> 30 | 31 | 32 | <#list table.commonFields as field> 33 | ${field.columnName}, 34 | 35 | ${table.fieldNames} 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/fanout/SmsConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.fanout; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * Fanout/subscribe发布订阅模式-生产者通过交换机,同时向多个消费者发送消息: 交换机模式采用(type=fanout) 13 | * 所有消费者都能收到消息 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class SmsConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | */ 27 | @RabbitListener(bindings = @QueueBinding( 28 | value = @Queue(name = "${fanout.sms.queue}", durable = "true"), 29 | exchange = @Exchange(name = "${fanout.exchange}", type = ExchangeTypes.FANOUT))) 30 | public void handlerMessage(String msg) { 31 | System.out.println("发布订阅模式:fanout Sms接收到的消息是: " + msg); 32 | try { 33 | Thread.sleep(5000); 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/fanout/WeixinConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.fanout; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * Fanout/subscribe发布订阅模式-生产者通过交换机,同时向多个消费者发送消息: 交换机模式采用(type=fanout) 13 | * 所有消费者都能收到消息 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class WeixinConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | */ 27 | @RabbitListener(bindings = @QueueBinding( 28 | value = @Queue(name = "${fanout.weixin.queue}", durable = "true"), 29 | exchange = @Exchange(name = "${fanout.exchange}", type = ExchangeTypes.FANOUT))) 30 | public void handlerMessage(String msg) { 31 | System.out.println("发布订阅模式:fanout Weixin接收到的消息是: " + msg); 32 | try { 33 | Thread.sleep(5000); 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-caffeine-cache/src/test/java/com/example/service/CacheTest.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.example.BaseTest; 4 | import com.example.entity.Admin; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | /** 11 | *

12 | * 缓存测试 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | public class CacheTest extends BaseTest { 18 | 19 | @Autowired 20 | private ICacheService cacheService; 21 | 22 | 23 | @Test 24 | public void test1() throws InterruptedException { 25 | Admin admin = Admin.builder() 26 | .id(2L) 27 | .userName("柳岩") 28 | .lastLoginTime(LocalDateTime.now()) 29 | .build(); 30 | this.cacheService.save(admin); 31 | System.out.println("this.cacheService.getById(2L) = " + this.cacheService.getById(2L)); 32 | 33 | 34 | admin.setUserName("柳岩233"); 35 | this.cacheService.update(admin); 36 | System.out.println("this.cacheService.getById(2L) = " + this.cacheService.getById(2L)); 37 | 38 | //删除再查询,缓存会有null的序列号值。 39 | this.cacheService.deleteById(2L); 40 | System.out.println("this.cacheService.getById(2L) = " + this.cacheService.getById(2L)); 41 | 42 | Thread.sleep(30000); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /spring-boot-cache/spring-boot-redis-cache/src/test/java/com/example/service/CacheTest.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import com.example.BaseTest; 4 | import com.example.entity.Admin; 5 | import org.junit.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | /** 11 | *

12 | * 缓存测试 13 | *

14 | * 15 | * @author MrWen 16 | **/ 17 | public class CacheTest extends BaseTest { 18 | 19 | @Autowired 20 | private ICacheService cacheService; 21 | 22 | 23 | @Test 24 | public void test1() throws InterruptedException { 25 | Admin admin = Admin.builder() 26 | .id(2L) 27 | .userName("柳岩") 28 | .lastLoginTime(LocalDateTime.now()) 29 | .build(); 30 | this.cacheService.save(admin); 31 | System.out.println("this.cacheService.getById(2L) = " + this.cacheService.getById(2L)); 32 | 33 | 34 | admin.setUserName("柳岩233"); 35 | this.cacheService.update(admin); 36 | System.out.println("this.cacheService.getById(2L) = " + this.cacheService.getById(2L)); 37 | 38 | //删除再查询,缓存会有null的序列号值。 39 | this.cacheService.deleteById(2L); 40 | System.out.println("this.cacheService.getById(2L) = " + this.cacheService.getById(2L)); 41 | 42 | Thread.sleep(30000); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Primary; 10 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 11 | 12 | /** 13 | *

14 | * 解决雪花算法ID到前端之后精度丢失问题 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Configuration 20 | public class JacksonConfig { 21 | 22 | @Bean 23 | @Primary 24 | @ConditionalOnMissingBean(ObjectMapper.class) 25 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 26 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 27 | 28 | // 全局配置序列化返回 JSON 处理 29 | SimpleModule simpleModule = new SimpleModule(); 30 | //JSON Long ==> String 31 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); 32 | objectMapper.registerModule(simpleModule); 33 | return objectMapper; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-6/src/main/java/com/example/dao/ProductDao.java: -------------------------------------------------------------------------------- 1 | package com.example.dao; 2 | 3 | import com.example.entity.Product; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * spring data elasticsearch的ORM操作 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Repository 19 | public interface ProductDao extends ElasticsearchRepository { 20 | 21 | 22 | /** 23 | * 通过分类名称查询结果 24 | * 25 | * @param category 分类名称 26 | * @return 查询结果 27 | */ 28 | List findByCategory(String category); 29 | 30 | /** 31 | * 分类及价格大于等于的结果集 32 | * 33 | * @param category 分类名称 34 | * @param price 大于等于的商品价格 35 | * @return 查询结果 36 | */ 37 | List findByCategoryAndPriceGreaterThanEqual(String category, Double price); 38 | 39 | 40 | /** 41 | * 分页查询,分类及价格大于等于的结果集 42 | * 43 | * @param category 分类名称 44 | * @param price 大于等于的商品价格 45 | * @param pageable 分页查询 46 | * @return 分页结果 47 | */ 48 | Page findByCategoryAndPriceGreaterThanEqual(String category, Double price, Pageable pageable); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-elasticsearch/spring-boot-elasticsearch-7/src/main/java/com/example/dao/ProductDao.java: -------------------------------------------------------------------------------- 1 | package com.example.dao; 2 | 3 | import com.example.entity.Product; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * spring data elasticsearch的ORM操作 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Repository 19 | public interface ProductDao extends ElasticsearchRepository { 20 | 21 | 22 | /** 23 | * 通过分类名称查询结果 24 | * 25 | * @param category 分类名称 26 | * @return 查询结果 27 | */ 28 | List findByCategory(String category); 29 | 30 | /** 31 | * 分类及价格大于等于的结果集 32 | * 33 | * @param category 分类名称 34 | * @param price 大于等于的商品价格 35 | * @return 查询结果 36 | */ 37 | List findByCategoryAndPriceGreaterThanEqual(String category, Double price); 38 | 39 | 40 | /** 41 | * 分页查询,分类及价格大于等于的结果集 42 | * 43 | * @param category 分类名称 44 | * @param price 大于等于的商品价格 45 | * @param pageable 分页查询 46 | * @return 分页结果 47 | */ 48 | Page findByCategoryAndPriceGreaterThanEqual(String category, Double price, Pageable pageable); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import io.swagger.annotations.ApiModel; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.*; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 用户表 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-11-28 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @EqualsAndHashCode(callSuper = false) 25 | @TableName("t_user") 26 | @ApiModel(value = "User对象", description = "用户表") 27 | public class User extends BaseEntity implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * 如果需要使用 sharding-jdbc的雪花id,IdType只能是AUTO,设置INPUT会报错(缺失时报错) 33 | * 当然也可以使用mybatis-plus的雪花算法 IdType.ASSIGN_ID,且强烈推荐,理由如下 34 | * 1:使用sharding-jdbc的雪花id,IdType.AUT时,只有当插入对象ID不为空,仍让会自动填充。 35 | * 2:mybatis-plus的雪花算法,IdType.ASSIGN_ID,只有当插入对象ID 为空,才自动填充。 36 | */ 37 | @TableId(value = "id", type = IdType.AUTO) 38 | @ApiModelProperty(value = "主键") 39 | private Long id; 40 | 41 | @ApiModelProperty(value = "用户名称") 42 | private String userName; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import io.swagger.annotations.ApiModel; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.*; 9 | 10 | import java.io.Serializable; 11 | 12 | /** 13 | *

14 | * 用户表 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2021-11-28 19 | */ 20 | @Data 21 | @Builder 22 | @NoArgsConstructor 23 | @AllArgsConstructor 24 | @EqualsAndHashCode(callSuper = false) 25 | @TableName("t_user") 26 | @ApiModel(value = "User对象", description = "用户表") 27 | public class User extends BaseEntity implements Serializable { 28 | 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * 如果需要使用 sharding-jdbc的雪花id,IdType只能是AUTO,设置INPUT会报错(缺失时报错) 33 | * 当然也可以使用mybatis-plus的雪花算法 IdType.ASSIGN_ID,且强烈推荐,理由如下 34 | * 1:使用sharding-jdbc的雪花id,IdType.AUT时,只有当插入对象ID不为空,仍让会自动填充。 35 | * 2:mybatis-plus的雪花算法,IdType.ASSIGN_ID,只有当插入对象ID 为空,才自动填充。 36 | */ 37 | @TableId(value = "id", type = IdType.AUTO) 38 | @ApiModelProperty(value = "主键") 39 | private Long id; 40 | 41 | @ApiModelProperty(value = "用户名称") 42 | private String userName; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Primary; 10 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 11 | 12 | /** 13 | *

14 | * 解决雪花算法ID到前端之后精度丢失问题 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Configuration 20 | public class JacksonConfig { 21 | 22 | @Bean 23 | @Primary 24 | @ConditionalOnMissingBean(ObjectMapper.class) 25 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 26 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 27 | 28 | // 全局配置序列化返回 JSON 处理 29 | SimpleModule simpleModule = new SimpleModule(); 30 | //JSON Long ==> String 31 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); 32 | objectMapper.registerModule(simpleModule); 33 | return objectMapper; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/java/com/example/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Primary; 10 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 11 | 12 | /** 13 | *

14 | * 解决雪花算法ID到前端之后精度丢失问题 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Configuration 20 | public class JacksonConfig { 21 | 22 | @Bean 23 | @Primary 24 | @ConditionalOnMissingBean(ObjectMapper.class) 25 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 26 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 27 | 28 | // 全局配置序列化返回 JSON 处理 29 | SimpleModule simpleModule = new SimpleModule(); 30 | //JSON Long ==> String 31 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); 32 | objectMapper.registerModule(simpleModule); 33 | return objectMapper; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-simple-db-table/src/main/java/com/example/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Primary; 10 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 11 | 12 | /** 13 | *

14 | * 解决雪花算法ID到前端之后精度丢失问题 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Configuration 20 | public class JacksonConfig { 21 | @Bean 22 | @Primary 23 | @ConditionalOnMissingBean(ObjectMapper.class) 24 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 25 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 26 | 27 | // 全局配置序列化返回 JSON 处理 28 | SimpleModule simpleModule = new SimpleModule(); 29 | //JSON Long ==> String 30 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); 31 | objectMapper.registerModule(simpleModule); 32 | return objectMapper; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-simple-db-table/src/main/java/com/example/config/JacksonConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fasterxml.jackson.databind.module.SimpleModule; 5 | import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; 6 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Primary; 10 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; 11 | 12 | /** 13 | *

14 | * 解决雪花算法ID到前端之后精度丢失问题 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Configuration 20 | public class JacksonConfig { 21 | @Bean 22 | @Primary 23 | @ConditionalOnMissingBean(ObjectMapper.class) 24 | public ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { 25 | ObjectMapper objectMapper = builder.createXmlMapper(false).build(); 26 | 27 | // 全局配置序列化返回 JSON 处理 28 | SimpleModule simpleModule = new SimpleModule(); 29 | //JSON Long ==> String 30 | simpleModule.addSerializer(Long.class, ToStringSerializer.instance); 31 | objectMapper.registerModule(simpleModule); 32 | return objectMapper; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq-simple/rocketmq-producer-simple/src/test/java/com/example/ProducerSimpleTest.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.rocketmq.client.producer.SendResult; 5 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 6 | import org.junit.Test; 7 | import org.junit.runner.RunWith; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.boot.test.context.SpringBootTest; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | 12 | /** 13 | *

14 | * rabbitmq测试 15 | *

16 | * 17 | * @author MrWen 18 | * @since 2022-01-06 16:37 19 | */ 20 | @Slf4j 21 | @RunWith(SpringRunner.class) 22 | @SpringBootTest(classes = RocketMQSimpleProducerApplication.class) 23 | public class ProducerSimpleTest { 24 | 25 | @Autowired 26 | private RocketMQTemplate rocketMQTemplate; 27 | 28 | 29 | @Test 30 | public void sendMessage() { 31 | String key = "simple"; 32 | for (int i = 0; i < 50; i++) { 33 | String message = "发送同步消息,msg=" + i; 34 | /* 35 | 第一个参数,主题名:标签 topicName:tags 36 | 第二个参数:发送对象 37 | */ 38 | SendResult sendResult = this.rocketMQTemplate.syncSend(key, message); 39 | log.info("MQ发送同步消息成功,key={} msg={},sendResult={}", key, message, sendResult); 40 | } 41 | } 42 | 43 | 44 | } 45 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/config/base/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.config.base; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import com.baomidou.mybatisplus.annotation.Version; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.Data; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | *

14 | * 基础属性 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Data 20 | public class BaseEntity { 21 | 22 | @TableField(fill = FieldFill.INSERT) 23 | @ApiModelProperty(value = "创建时间") 24 | private Date createTime; 25 | 26 | @TableField(fill = FieldFill.INSERT) 27 | @ApiModelProperty(value = "创建者") 28 | private String createName; 29 | 30 | @TableField(fill = FieldFill.INSERT_UPDATE) 31 | @ApiModelProperty(value = "更新时间") 32 | private Date updateTime; 33 | 34 | @TableField(fill = FieldFill.INSERT_UPDATE) 35 | @ApiModelProperty(value = "修改者") 36 | private String updateName; 37 | 38 | @Version 39 | @ApiModelProperty(value = "乐观锁版本号") 40 | private Integer version; 41 | 42 | @TableLogic 43 | @TableField(select = false) 44 | @ApiModelProperty(value = "逻辑删除") 45 | private Boolean deleted; 46 | 47 | @ApiModelProperty(value = "租户id") 48 | private Integer tenantId; 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/direct/InfoConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.direct; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * Routing 路由模式-交换机和队列进行绑定,并且指定routing key,当发送消息到交换机后,交换机会根据routing key将消息发送到对应的队列 13 | * 符合路由(routing key,固定)的消费者收到 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class InfoConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | * key:路由key 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(name = "${direct.info.queue}", durable = "true"), // 队列 30 | exchange = @Exchange(name = "${direct.exchange}", type = ExchangeTypes.DIRECT),// 交换机 31 | key = {"info"} // 路由key 32 | )) 33 | public void handlerMessage(String msg) { 34 | System.out.println("info--->接受到的消息是:" + msg); 35 | try { 36 | Thread.sleep(5000); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/direct/AllConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.direct; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * Routing 路由模式-交换机和队列进行绑定,并且指定routing key,当发送消息到交换机后,交换机会根据routing key将消息发送到对应的队列 13 | * 符合路由(routing key,固定)的消费者收到 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class AllConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | * key:路由key 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(name = "${direct.all.queue}", durable = "true"), // 队列 30 | exchange = @Exchange(name = "${direct.exchange}", type = ExchangeTypes.DIRECT),// 交换机 31 | key = {"info", "error"} // 路由key 32 | )) 33 | public void handlerMessage(String msg) { 34 | System.out.println("all--->接受到的消息是:" + msg); 35 | try { 36 | Thread.sleep(5000); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/direct/ErrorConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.direct; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * Routing 路由模式-交换机和队列进行绑定,并且指定routing key,当发送消息到交换机后,交换机会根据routing key将消息发送到对应的队列 13 | * 符合路由(routing key,固定)的消费者收到 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class ErrorConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | * key:路由key 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(name = "${direct.error.queue}", durable = "true"), // 队列 30 | exchange = @Exchange(name = "${direct.exchange}", type = ExchangeTypes.DIRECT),// 交换机 31 | key = {"error"} // 路由key 32 | )) 33 | public void handlerMessage(String msg) { 34 | System.out.println("error--->接受到的消息是:" + msg); 35 | try { 36 | Thread.sleep(5000); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | # 端口 3 | port: 7876 4 | 5 | spring: 6 | profiles: 7 | # sharding-jdbc配置 8 | active: shardingjdbc4 9 | jackson: 10 | # 日期格式器 jackson格式 11 | date-format: yyyy-MM-dd HH:mm:ss 12 | # 格林威冶标准时间 + 8 (北京时间) 13 | time-zone: GMT+8 14 | # redis配置 15 | redis: 16 | # 连接超时时间(毫秒) 17 | timeout: 30000ms 18 | jedis: 19 | pool: 20 | # 连接池最大连接数(使用负值表示没有限制) 21 | max-active: 100 22 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 23 | max-wait: -1 24 | # 连接池中的最小空闲连接 25 | min-idle: 1 26 | # 连接池中的最大空闲连接 27 | max-idle: 100 28 | host: 127.0.0.1 29 | port: 6379 30 | database: 2 31 | 32 | #日志配置 33 | logging: 34 | level: 35 | root: info 36 | com.example: debug 37 | # swagger 2.9.2 版本报错问题 38 | io.swagger.models.parameters.AbstractSerializableParameter: error 39 | 40 | # mybatis plus配置 41 | mybatis-plus: 42 | global-config: 43 | db-config: 44 | #数据库ID自增 45 | id-type: AUTO 46 | #逻辑未删除 默认0 字段需要在@TableLogic注解 47 | logic-not-delete-value: 0 48 | #逻辑删除 默认1 字段需要在@TableLogic注解 49 | logic-delete-value: 1 50 | #包路径扫描 51 | type-aliases-package: com.example.**.entity 52 | configuration: 53 | #驼峰命名 54 | map-underscore-to-camel-case: true 55 | #xml文件路径 56 | mapper-locations: classpath:mapper/*.xml 57 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-5.0.0/sharding-jdbc-5.0.0-db-table/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | # 端口 3 | port: 7878 4 | 5 | spring: 6 | profiles: 7 | # sharding-jdbc配置 8 | active: shardingjdbc5 9 | jackson: 10 | # 日期格式器 jackson格式 11 | date-format: yyyy-MM-dd HH:mm:ss 12 | # 格林威冶标准时间 + 8 (北京时间) 13 | time-zone: GMT+8 14 | # redis配置 15 | redis: 16 | # 连接超时时间(毫秒) 17 | timeout: 30000ms 18 | jedis: 19 | pool: 20 | # 连接池最大连接数(使用负值表示没有限制) 21 | max-active: 100 22 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 23 | max-wait: -1 24 | # 连接池中的最小空闲连接 25 | min-idle: 1 26 | # 连接池中的最大空闲连接 27 | max-idle: 100 28 | host: 127.0.0.1 29 | port: 6379 30 | database: 2 31 | 32 | #日志配置 33 | logging: 34 | level: 35 | root: info 36 | com.example: debug 37 | # swagger 2.9.2 版本报错问题 38 | io.swagger.models.parameters.AbstractSerializableParameter: error 39 | 40 | # mybatis plus配置 41 | mybatis-plus: 42 | global-config: 43 | db-config: 44 | #数据库ID自增 45 | id-type: AUTO 46 | #逻辑未删除 默认0 字段需要在@TableLogic注解 47 | logic-not-delete-value: 0 48 | #逻辑删除 默认1 字段需要在@TableLogic注解 49 | logic-delete-value: 1 50 | #包路径扫描 51 | type-aliases-package: com.example.**.entity 52 | configuration: 53 | #驼峰命名 54 | map-underscore-to-camel-case: true 55 | #xml文件路径 56 | mapper-locations: classpath:mapper/*.xml 57 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/topic/FullLogConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.topic; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * topic 通配符/主题模式-交换机和队列进行绑定,并且通配符方式routing key,当发送消息到交换机后,交换机会根据routing key将消息发送到对应的队列 13 | * 符合路由(routing key,通配符)的消费者收到 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class FullLogConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | * key:路由key,通配符 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(name = "${topic.full.queue}", durable = "true"),// 队列 30 | exchange = @Exchange(name = "${topic.exchange}", type = ExchangeTypes.TOPIC),// 交换机 31 | key = {"#"}// 路由key,通配符 32 | )) 33 | public void handlerMessage(String msg) { 34 | System.out.println("log.full--->接受到的消息是:" + msg); 35 | try { 36 | Thread.sleep(5000); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/README.md: -------------------------------------------------------------------------------- 1 | # RocketMQ 2 | 3 | ## 1 如何保障消息可靠生产(消息100%投递成功) 4 | 5 | 官网描述,参考最佳实践:https://github.com/apache/rocketmq/blob/master/docs/cn/best_practice.md 6 | 7 | #### 3 日志的打印 8 | 9 | 消息发送成功或者失败要打印消息日志,务必要打印SendResult和key字段。**send消息方法只要不抛异常,就代表发送成功**。发送成功会有多个状态,在sendResult里定义。以下对每个状态进行说明: 10 | 11 | - **SEND_OK** 12 | 13 | 消息发送成功。要注意的是消息发送成功也不意味着它是可靠的。要确保不会丢失任何消息,还应启用**同步Master服务器或同步刷盘,即SYNC_MASTER或SYNC_FLUSH。** 14 | 15 | - **FLUSH_DISK_TIMEOUT** 16 | 17 | 消息发送成功但是服务器刷盘超时。此时消息已经进入服务器队列(内存),只有服务器宕机,消息才会丢失。消息存储配置参数中可以设置刷盘方式和同步刷盘时间长度,如果Broker服务器设置了刷盘方式为同步刷盘,即FlushDiskType=SYNC_FLUSH(默认为异步刷盘方式),当Broker服务器未在同步刷盘时间内(默认为5s)完成刷盘,则将返回该状态——刷盘超时。 18 | 19 | - **FLUSH_SLAVE_TIMEOUT** 20 | 21 | 消息发送成功,但是服务器同步到Slave时超时。此时消息已经进入服务器队列,只有服务器宕机,消息才会丢失。如果Broker服务器的角色是同步Master,即SYNC_MASTER(默认是异步Master即ASYNC_MASTER),并且从Broker服务器未在同步刷盘时间(默认为5秒)内完成与主服务器的同步,则将返回该状态——数据同步到Slave服务器超时。 22 | 23 | - **SLAVE_NOT_AVAILABLE** 24 | 25 | 消息发送成功,但是此时Slave不可用。如果Broker服务器的角色是同步Master,即SYNC_MASTER(默认是异步Master服务器即ASYNC_MASTER),但没有配置slave Broker服务器,则将返回该状态——无Slave服务器可用。 26 | 27 | **小结:** 28 | 29 | **只要sendResult为SEND_OK状态,且同步Master服务器或同步刷盘,就可确认成功。** 30 | 31 | 32 | 33 | ## 2 消息可靠消费 34 | 35 | 相对RabbitMQ,RocketMQ的可靠消费并不需要我们做过多的处理。会自动把消费失败的消息扔到死信队列中。只需要做好消息预警即可。 36 | 37 | [Consumer示例](spring-boot-rocketmq/rocketmq-consumer/src/main/java/com/example/service/ConsumerCluster.java) 38 | 39 | 40 | 41 | 42 | 43 | ## 3: 参考资料 44 | 45 | 官方中文文档:https://github.com/apache/rocketmq/tree/master/docs/cn -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/topic/InfoLogConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.topic; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * topic 通配符/主题模式-交换机和队列进行绑定,并且通配符方式routing key,当发送消息到交换机后,交换机会根据routing key将消息发送到对应的队列 13 | * 符合路由(routing key,通配符)的消费者收到 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class InfoLogConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | * key:路由key,通配符 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(name = "${topic.info.queue}", durable = "true"),// 队列 30 | exchange = @Exchange(name = "${topic.exchange}", type = ExchangeTypes.TOPIC),// 交换机 31 | key = {"*.log.info"}// 路由key,通配符 32 | )) 33 | public void handlerMessage(String msg) { 34 | System.out.println("log.info--->接受到的消息是:" + msg); 35 | try { 36 | Thread.sleep(5000); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/consumer/src/main/java/com/example/topic/ErrorLogConsumer.java: -------------------------------------------------------------------------------- 1 | package com.example.topic; 2 | 3 | import org.springframework.amqp.core.ExchangeTypes; 4 | import org.springframework.amqp.rabbit.annotation.Exchange; 5 | import org.springframework.amqp.rabbit.annotation.Queue; 6 | import org.springframework.amqp.rabbit.annotation.QueueBinding; 7 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 8 | import org.springframework.stereotype.Component; 9 | 10 | /** 11 | *

12 | * topic 通配符/主题模式-交换机和队列进行绑定,并且通配符方式routing key,当发送消息到交换机后,交换机会根据routing key将消息发送到对应的队列 13 | * 符合路由(routing key,通配符)的消费者收到 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Component 19 | public class ErrorLogConsumer { 20 | 21 | /** 22 | * 消息监听方法 23 | * bindings: 完成队列与交换机的绑定 24 | * Queue: 队列属性 25 | * exchange:交换机属性 26 | * key:路由key,通配符 27 | */ 28 | @RabbitListener(bindings = @QueueBinding( 29 | value = @Queue(name = "${topic.error.queue}", durable = "true"),// 队列 30 | exchange = @Exchange(name = "${topic.exchange}", type = ExchangeTypes.TOPIC),// 交换机 31 | key = {"*.log.error"}// 路由key,通配符 32 | )) 33 | public void handlerMessage(String msg) { 34 | System.out.println("log.error--->接受到的消息是:" + msg); 35 | try { 36 | Thread.sleep(5000); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/java/com/example/entity/base/BaseEntity.java: -------------------------------------------------------------------------------- 1 | package com.example.entity.base; 2 | 3 | import com.baomidou.mybatisplus.annotation.FieldFill; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableLogic; 6 | import com.baomidou.mybatisplus.annotation.Version; 7 | import io.swagger.annotations.ApiModelProperty; 8 | import lombok.Data; 9 | 10 | import java.util.Date; 11 | 12 | /** 13 | *

14 | * 基础属性,这个根据实际项目,放到公共包中,这里只做演示 15 | *

16 | * 17 | * @author MrWen 18 | **/ 19 | @Data 20 | public class BaseEntity { 21 | 22 | @TableField(fill = FieldFill.INSERT) 23 | @ApiModelProperty(value = "创建时间") 24 | private Date createTime; 25 | 26 | @TableField(fill = FieldFill.INSERT) 27 | @ApiModelProperty(value = "创建者") 28 | private String createName; 29 | 30 | @TableField(fill = FieldFill.INSERT_UPDATE) 31 | @ApiModelProperty(value = "更新时间") 32 | private Date updateTime; 33 | 34 | @TableField(fill = FieldFill.INSERT_UPDATE) 35 | @ApiModelProperty(value = "修改者") 36 | private String updateName; 37 | 38 | @Version 39 | @ApiModelProperty(value = "乐观锁版本号") 40 | private Integer version; 41 | 42 | @TableLogic 43 | @TableField(select = false) 44 | @ApiModelProperty(value = "逻辑删除") 45 | private Boolean deleted; 46 | 47 | @ApiModelProperty(value = "租户id") 48 | private Integer tenantId; 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-swagger/README.md: -------------------------------------------------------------------------------- 1 | # swagger 2 | 3 | ## 1 概述 4 | 5 | ### 1.1 概述 6 | 7 | ```tex 8 | 相信无论是前端还是后端开发,都或多或少地被接口文档折磨过。前端经常抱怨后端给的接口文档与实际情况不一致。后端又觉得编写及维护接口文档会耗费不少精力,经常来不及更新。其实无论是前端调用后端,还是后端调用后端,都期望有一个好的接口文档。但是这个接口文档对于程序员来说,就跟注释一样,经常会抱怨别人写的代码没有写注释,然而自己写起代码起来,最讨厌的,也是写注释。所以仅仅只通过强制来规范大家是不够的,随着时间推移,版本迭代,接口文档往往很容易就跟不上代码了。 9 | 10 | 使用Swagger你只需要按照它的规范去定义接口及接口相关的信息。再通过Swagger衍生出来的一系列项目和工具,就可以做到生成各种格式的接口文档,生成多种语言的客户端和服务端的代码,以及在线接口调试页面等等。这样,如果按照新的开发模式,在开发新版本或者迭代版本的时候,只需要更新Swagger描述文件,就可以自动生成接口文档和客户端服务端代码,做到调用端代码、服务端代码以及接口文档的一致性。 11 | 12 | 前后端开发人员可以查看接口文档,为前后端开发人员的开发统一接口,方便后续的前后端联调对接工作。 13 | ``` 14 | 15 | 16 | 17 | ### 1.2 swagger常用注解 18 | 19 | | 注解 | 说明 | 20 | | ------------------ | -------------------------------------------------------- | 21 | | @Api | 用在请求的类上,例如Controller,表示对类的说明 | 22 | | @ApiModel | 用在类上,通常是实体类,表示一个返回响应数据的信息 | 23 | | @ApiModelProperty | 用在属性上,描述响应类的属性 | 24 | | @ApiOperation | 用在请求的方法上,说明方法的用途、作用 | 25 | | @ApiImplicitParams | 用在请求的方法上,表示一组参数说明 | 26 | | @ApiImplicitParam | 用在@ApiImplicitParams注解中,指定一个请求参数的各个方面 | 27 | | @ApiParam | 用在 Rest 接口上或 Rest 接口参数前边 | 28 | 29 | 参考资料: https://blog.csdn.net/dejunyang/article/details/89527176 30 | 31 | 32 | 33 | ## 2 其它参考 34 | 35 | 项目更多Demo 36 | 37 | [swagger-bootstrap-ui-demo]:https://gitee.com/xiaoym/swagger-bootstrap-ui-demo 38 | 39 | -------------------------------------------------------------------------------- /spring-boot-excel/src/main/java/com/example/controller/EasyExcelController.java: -------------------------------------------------------------------------------- 1 | package com.example.controller; 2 | 3 | import com.example.service.IEasyExcelService; 4 | import io.swagger.annotations.Api; 5 | import io.swagger.annotations.ApiOperation; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.*; 8 | import org.springframework.web.multipart.MultipartFile; 9 | 10 | 11 | /** 12 | *

13 | * easyexcel示例 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @RestController 19 | @RequestMapping("/easy/excel") 20 | @Api(tags = "easyExcel框架测试") 21 | public class EasyExcelController { 22 | 23 | @Autowired 24 | private IEasyExcelService easyExcelService; 25 | 26 | /** 27 | * 支持xlsx,xls,csv格式导出 28 | */ 29 | @GetMapping("/printExcel1") 30 | @ApiOperation("1普通excel导出") 31 | public void printExcel1() { 32 | easyExcelService.printExcel1(); 33 | } 34 | 35 | @GetMapping("/printExcel2") 36 | @ApiOperation("2模板导出(数据填充)") 37 | public void printExcel2() { 38 | easyExcelService.printExcel2(); 39 | } 40 | 41 | /** 42 | * file测试数据:printExcel1接口的导出结果即可 43 | * 参考:https://www.yuque.com/easyexcel/doc/read 44 | */ 45 | @PostMapping("/importExcel") 46 | @ApiOperation("3excel导入") 47 | public String importExcel(@RequestParam("file") MultipartFile file) { 48 | easyExcelService.importExcel(file); 49 | return "success"; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customComplexTemplates/controller.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import ${package.Service}.${table.serviceName}; 5 | import io.swagger.annotations.Api; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | <#if restControllerStyle> 9 | import org.springframework.web.bind.annotation.RestController; 10 | <#else> 11 | import org.springframework.stereotype.Controller; 12 | 13 | <#if superControllerClassPackage??> 14 | import ${superControllerClassPackage}; 15 | 16 | 17 | /** 18 | *

19 | * ${table.comment!} 前端控制器 20 | *

21 | * 22 | * @author ${author} 23 | * @since ${date} 24 | */ 25 | <#if restControllerStyle> 26 | @RestController 27 | <#else> 28 | @Controller 29 | 30 | @RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}") 31 | <#if kotlin> 32 | class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}() 33 | <#else> 34 | @Api(tags = "${table.comment!}") 35 | <#if superControllerClass??> 36 | public class ${table.controllerName} extends ${superControllerClass} { 37 | <#else> 38 | public class ${table.controllerName} { 39 | 40 | 41 | @Autowired 42 | private ${table.serviceName} ${myService}; 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-generate/src/main/resources/customSimpleTemplates/controller.java.ftl: -------------------------------------------------------------------------------- 1 | package ${package.Controller}; 2 | 3 | 4 | import ${package.Service}.${table.serviceName}; 5 | import io.swagger.annotations.Api; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | <#if restControllerStyle> 9 | import org.springframework.web.bind.annotation.RestController; 10 | <#else> 11 | import org.springframework.stereotype.Controller; 12 | 13 | <#if superControllerClassPackage??> 14 | import ${superControllerClassPackage}; 15 | 16 | 17 | /** 18 | *

19 | * ${table.comment!} 前端控制器 20 | *

21 | * 22 | * @author ${author} 23 | * @since ${date} 24 | */ 25 | <#if restControllerStyle> 26 | @RestController 27 | <#else> 28 | @Controller 29 | 30 | @RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}") 31 | <#if kotlin> 32 | class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}() 33 | <#else> 34 | @Api(tags = "${table.comment!}") 35 | <#if superControllerClass??> 36 | public class ${table.controllerName} extends ${superControllerClass} { 37 | <#else> 38 | public class ${table.controllerName} { 39 | 40 | 41 | @Autowired 42 | private ${table.serviceName} ${myService}; 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /spring-boot-sharding-jdbc/spring-boot-sharding-jdbc-4.1.1/sharding-jdbc-4.1.1-db-table/src/main/java/com/example/config/sharding/algorithm/PreciseModuloShardingDatabaseAlgorithm.java: -------------------------------------------------------------------------------- 1 | package com.example.config.sharding.algorithm; 2 | 3 | import cn.hutool.core.date.DateUtil; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm; 6 | import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue; 7 | 8 | import java.util.Collection; 9 | import java.util.Date; 10 | 11 | /** 12 | *

13 | * 分库,精确分片算法类名称,用于=和IN 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Slf4j 19 | public class PreciseModuloShardingDatabaseAlgorithm implements PreciseShardingAlgorithm { 20 | 21 | private final static Date DATE_2022 = DateUtil.parseDate("2022-01-01"); 22 | 23 | /** 24 | * 自定义分表算法,用于=和IN,(必填) 25 | * 26 | * @param databaseNames 实际数据库名 ds0,ds1 27 | * @param shardingValue 字库属性 PreciseShardingValue(logicTableName=t_goods, columnName=create_time,value=2021-11-28 15:41:26) 28 | * @return 具体结果(那张表) 29 | */ 30 | @Override 31 | public String doSharding(final Collection databaseNames, final PreciseShardingValue shardingValue) { 32 | //2020-2021 在 ds0 2022-2023在ds1,这里直接写死,只做演示 33 | Date date = shardingValue.getValue(); 34 | if (date.compareTo(DATE_2022) >= 0) { 35 | return "ds1"; 36 | } else { 37 | return "ds0"; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-boot-mq-rabbitmq/spring-boot-rabbitmq/producer/src/main/java/com/example/service/impl/RabbitMQServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.service.impl; 2 | 3 | import com.example.service.RabbitMQService; 4 | import org.springframework.amqp.rabbit.connection.CorrelationData; 5 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * RabbitMQ生产端常用方法整合 12 | *

13 | * 14 | * @author MrWen 15 | **/ 16 | @Service 17 | public class RabbitMQServiceImpl implements RabbitMQService { 18 | 19 | @Autowired 20 | private RabbitTemplate rabbitTemplate; 21 | 22 | @Override 23 | public void sendMessageByWork(String queue, Object msg) { 24 | rabbitTemplate.convertAndSend("", queue, msg); 25 | } 26 | 27 | @Override 28 | public void sendMessageByWork(String queue, Object msg, String ackId) { 29 | rabbitTemplate.convertAndSend("", queue, msg, new CorrelationData(ackId)); 30 | } 31 | 32 | @Override 33 | public void sendMessageByExchange(String exchange, String routingKey, Object msg) { 34 | rabbitTemplate.convertAndSend(exchange, routingKey == null ? "" : routingKey, msg); 35 | } 36 | 37 | @Override 38 | public void sendMessageByExchange(String exchange, String routingKey, Object msg, String ackId) { 39 | rabbitTemplate.convertAndSend(exchange, routingKey == null ? "" : routingKey, msg, new CorrelationData(ackId)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.example.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableField; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | import com.baomidou.mybatisplus.annotation.TableName; 7 | import com.example.config.base.BaseEntity; 8 | import com.example.enums.GenderEnum; 9 | import io.swagger.annotations.ApiModel; 10 | import io.swagger.annotations.ApiModelProperty; 11 | import lombok.*; 12 | 13 | /** 14 | *

15 | * 用户 16 | *

17 | * 18 | * @author MrWen 19 | * @since 2021-12-02 20 | */ 21 | @Data 22 | @Builder 23 | @NoArgsConstructor 24 | @AllArgsConstructor 25 | @EqualsAndHashCode(callSuper = true) 26 | @TableName("t_user") 27 | @ApiModel(value = "User对象", description = "用户") 28 | public class User extends BaseEntity { 29 | 30 | @ApiModelProperty("主键") 31 | @TableId(value = "id", type = IdType.ASSIGN_ID) 32 | private Long id; 33 | 34 | @ApiModelProperty("姓名") 35 | @TableField("name") 36 | private String name; 37 | 38 | @ApiModelProperty("年龄") 39 | @TableField("age") 40 | private Integer age; 41 | 42 | @ApiModelProperty("性别:0 未知, 1男, 2 女") 43 | @TableField("gender") 44 | private GenderEnum gender; 45 | 46 | @ApiModelProperty("邮箱") 47 | @TableField("email") 48 | private String email; 49 | 50 | @ApiModelProperty("直属上级id") 51 | @TableField("manager_id") 52 | private Long managerId; 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-demo/src/main/java/com/example/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | /** 14 | *

15 | * swagger配置,这里不使用swagger测试。直接用测试类 16 | *

17 | * 18 | * @author MrWen 19 | **/ 20 | @Configuration 21 | @EnableSwagger2 22 | public class SwaggerConfig { 23 | 24 | @Bean 25 | public Docket buildDocket() { 26 | return new Docket(DocumentationType.SWAGGER_2) 27 | .apiInfo(buildApiInf()) 28 | .select() 29 | .apis(RequestHandlerSelectors.basePackage("com.example.controller")) 30 | .paths(PathSelectors.any()) 31 | .build(); 32 | } 33 | 34 | private ApiInfo buildApiInf() { 35 | return new ApiInfoBuilder() 36 | .title("mp测试") 37 | .version("1.0") 38 | .description("mp测试") 39 | .termsOfServiceUrl("http://www.example.com") 40 | .build(); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /spring-boot-mq-rocketmq/spring-boot-rocketmq/rocketmq-consumer/src/main/java/com/example/service/ConsumerBroadcast.java: -------------------------------------------------------------------------------- 1 | package com.example.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.rocketmq.spring.annotation.MessageModel; 5 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 6 | import org.apache.rocketmq.spring.core.RocketMQListener; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | *

13 | * 广播模式消费,每个消费者消费的消息都是相同的 14 | *

15 | * 16 | * @author MrWen 17 | **/ 18 | @Slf4j 19 | @Component 20 | @RocketMQMessageListener(topic = "Consumer_Broadcast",//主题 21 | consumerGroup = "Consumer_Broadcast_group",//消费组 唯一 22 | messageModel = MessageModel.BROADCASTING //消费模式 默认CLUSTERING集群 BROADCASTING:广播(接收所有信息) 23 | ) 24 | public class ConsumerBroadcast implements RocketMQListener { 25 | 26 | //todo 广播消费模式宽带消费仍然确保消息至少被消费一次,但是没有提供重发选项。 27 | 28 | /** 29 | * 消费者 30 | * 程序报错则进行重试 31 | * 32 | * @param message 接收的消息 33 | */ 34 | @Override 35 | public void onMessage(String message) { 36 | try { 37 | //模拟业务逻辑处理中... 38 | log.info("ConsumerBroadcast 广播模式消费 message: {} ", message); 39 | TimeUnit.SECONDS.sleep(10); 40 | //模拟出错,触发重试 41 | // int i = 1 / 0; 42 | } catch (Exception e) { 43 | e.printStackTrace(); 44 | throw new RuntimeException(e.getMessage()); 45 | } 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /spring-boot-mybatis-plus/spring-boot-mybatis-plus-dynamic-datasource-demo/src/main/java/com/example/config/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.example.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import springfox.documentation.builders.ApiInfoBuilder; 6 | import springfox.documentation.builders.PathSelectors; 7 | import springfox.documentation.builders.RequestHandlerSelectors; 8 | import springfox.documentation.service.ApiInfo; 9 | import springfox.documentation.spi.DocumentationType; 10 | import springfox.documentation.spring.web.plugins.Docket; 11 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 12 | 13 | /** 14 | *

15 | * swagger配置,这里不使用swagger测试。直接用测试类 16 | *

17 | * 18 | * @author MrWen 19 | **/ 20 | @Configuration 21 | @EnableSwagger2 22 | public class SwaggerConfig { 23 | 24 | @Bean 25 | public Docket buildDocket() { 26 | return new Docket(DocumentationType.SWAGGER_2) 27 | .apiInfo(buildApiInf()) 28 | .select() 29 | .apis(RequestHandlerSelectors.basePackage("com.example.controller")) 30 | .paths(PathSelectors.any()) 31 | .build(); 32 | } 33 | 34 | private ApiInfo buildApiInf() { 35 | return new ApiInfoBuilder() 36 | .title("mp测试") 37 | .version("1.0") 38 | .description("mp测试") 39 | .termsOfServiceUrl("http://www.example.com") 40 | .build(); 41 | } 42 | 43 | } 44 | --------------------------------------------------------------------------------