├── .gitignore ├── LICENSE ├── README.md ├── netty-protobuf-client ├── .gitignore ├── doc │ └── readme.md ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── netty │ │ └── client │ │ ├── NettyClientApplication.java │ │ ├── channel │ │ └── ChannelInit.java │ │ ├── config │ │ └── ClientProperties.java │ │ ├── controller │ │ └── HttpProtobufApi.java │ │ ├── handler │ │ └── MessageHandler.java │ │ ├── protocol │ │ └── MessageBuf.java │ │ ├── server │ │ ├── ITcpClient.java │ │ └── TcpClient.java │ │ └── utils │ │ └── MessageBuilder.java │ └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ └── application.yml ├── netty-protobuf-server ├── .gitignore ├── doc │ ├── message.proto │ ├── protobuf3.md │ └── protoc-3.20.1-rc-1-win64.zip ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── netty │ │ └── server │ │ ├── NettyServerApplication.java │ │ ├── channel │ │ └── ChannelInit.java │ │ ├── config │ │ └── ServerProperties.java │ │ ├── handler │ │ └── MessageHandler.java │ │ ├── protocol │ │ └── MessageBuf.java │ │ ├── server │ │ ├── ITcpServer.java │ │ └── TcpServer.java │ │ ├── store │ │ └── ChannelStore.java │ │ └── utils │ │ └── MessageBuilder.java │ └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ └── application.yml ├── netty-tcp-client ├── .gitignore ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── netty │ │ └── client │ │ ├── NettyClientApplication.java │ │ ├── channel │ │ └── ChannelInit.java │ │ ├── config │ │ └── ClientProperties.java │ │ ├── controller │ │ └── HttpApi.java │ │ ├── handler │ │ └── MessageHandler.java │ │ └── server │ │ ├── ITcpClient.java │ │ └── TcpClient.java │ └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ └── application.yml ├── netty-tcp-server ├── .gitignore ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── netty │ │ └── server │ │ ├── NettyServerApplication.java │ │ ├── channel │ │ └── ChannelInit.java │ │ ├── config │ │ └── ServerProperties.java │ │ ├── handler │ │ └── MessageHandler.java │ │ ├── server │ │ ├── ITcpServer.java │ │ └── TcpServer.java │ │ └── store │ │ └── ChannelStore.java │ └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ └── application.yml ├── netty-websocket-client ├── .gitignore ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── netty │ │ └── client │ │ ├── NettyClientApplication.java │ │ ├── channel │ │ └── ChannelInit.java │ │ ├── config │ │ └── ClientProperties.java │ │ ├── controller │ │ └── HttpApi.java │ │ ├── handler │ │ └── MessageHandler.java │ │ └── server │ │ ├── IWebsocketClient.java │ │ └── WebsocketClient.java │ └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ └── application.yml ├── netty-websocket-server ├── .gitignore ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── netty │ │ └── server │ │ ├── NettyServerApplication.java │ │ ├── channel │ │ └── ChannelInit.java │ │ ├── config │ │ └── ServerProperties.java │ │ ├── handler │ │ ├── MessageHandler.java │ │ └── WebsocketMessageHandler.java │ │ ├── server │ │ ├── ITcpServer.java │ │ └── TcpServer.java │ │ └── store │ │ ├── ChannelStore.java │ │ └── WebSocketSession.java │ └── resources │ ├── META-INF │ └── additional-spring-configuration-metadata.json │ └── application.yml ├── springboot-aop-logger ├── .gitignore ├── pom.xml ├── readme.md └── src │ └── main │ ├── java │ └── com │ │ └── springboot │ │ └── cli │ │ ├── WebApplication.java │ │ ├── annotation │ │ └── CustomLog.java │ │ ├── aspect │ │ └── LogAspect.java │ │ ├── controller │ │ └── IndexController.java │ │ └── model │ │ └── SysLog.java │ └── resources │ └── application.yml ├── springboot-async ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── AsyncApplication.java │ │ │ ├── async │ │ │ └── AsyncTask.java │ │ │ └── config │ │ │ └── ExecutorConfig.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-captcha ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ └── utils │ │ │ └── CaptchaUtils.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-demo ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── executors │ │ │ └── ExecutorsDemo.java │ │ │ ├── lock │ │ │ ├── OptimisticDemo.java │ │ │ ├── Reentrant.java │ │ │ ├── ReentrantLockDemo.java │ │ │ ├── ReentrantLockTest.java │ │ │ ├── ReentrantReadWriteDemo.java │ │ │ ├── SellDemo.java │ │ │ ├── SpinLock.java │ │ │ ├── SpinLockSellDemo.java │ │ │ └── SynchronizedDemo.java │ │ │ └── thread │ │ │ ├── CallableDemo.java │ │ │ ├── RunnableDemo.java │ │ │ ├── ThreadDemo.java │ │ │ └── ThreadTest.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-druid ├── .gitignore ├── pom.xml ├── readme.md ├── sql │ └── example.sql └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── dao │ │ │ └── UserMapper.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ └── service │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── mapper │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-elasticsearch ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── config │ │ │ └── RestClientConfig.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ └── service │ │ │ ├── EsUserService.java │ │ │ └── impl │ │ │ └── EsUserServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-email ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── config │ │ │ └── EMailConfig.java │ │ │ ├── controller │ │ │ └── EmailController.java │ │ │ └── email │ │ │ └── EmailService.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ └── emailTemplate.html │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-excel-export ├── .gitignore ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── exel │ │ │ └── demo │ │ │ ├── DemoApplication.java │ │ │ ├── controller │ │ │ └── ExportController.java │ │ │ ├── entity │ │ │ ├── Course.java │ │ │ └── User.java │ │ │ ├── test │ │ │ └── Test.java │ │ │ └── utils │ │ │ ├── ExelUtils.java │ │ │ ├── MockDataUtils.java │ │ │ └── WordUtils.java │ └── resources │ │ ├── application.yml │ │ └── exportTemplate │ │ ├── simple.docx │ │ ├── user_course_tem.xlsx │ │ └── ~$simple.docx │ └── test │ └── java │ └── com │ └── exel │ └── demo │ └── DemoApplicationTests.java ├── springboot-exception ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── exception │ │ │ └── MyException.java │ │ │ ├── handler │ │ │ └── ControllerExceptionHandler.java │ │ │ └── utils │ │ │ └── ResponseResult.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-jwt ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── JwtDomeApplication.java │ │ │ ├── config │ │ │ ├── AuthInterceptor.java │ │ │ ├── PasswordEncoder.java │ │ │ ├── SwaggerConfig.java │ │ │ └── WebMvcConfig.java │ │ │ ├── controller │ │ │ └── TokenController.java │ │ │ └── jwt │ │ │ ├── AuthStorage.java │ │ │ ├── JwtUser.java │ │ │ └── TokenProvider.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-kafka ├── .gitignore ├── consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── ConsumerApplication.java │ │ │ └── KafkaConsumer │ │ │ └── KafkaConsumer.java │ │ └── resources │ │ └── application.yml ├── pom.xml ├── producer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── KafkaProducer │ │ │ └── KafkaProducer.java │ │ │ ├── ProducerApplication.java │ │ │ └── controller │ │ │ └── ProducerController.java │ │ └── resources │ │ └── application.yml └── readme.md ├── springboot-minio ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── config │ │ │ └── MinioProperties.java │ │ │ ├── controller │ │ │ └── MinioController.java │ │ │ └── minio │ │ │ └── MinioHandler.java │ └── resources │ │ ├── META-INF │ │ └── additional-spring-configuration-metadata.json │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-mongodb ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ └── service │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── MongodbApplicationTests.java ├── springboot-mybatis-plus-generator ├── .gitignore ├── README.MD ├── pom.xml ├── sql │ └── parent_list.sql └── src │ └── main │ ├── java │ └── com │ │ └── example │ │ └── mybatis_generation │ │ ├── MybatisGenerationApplication.java │ │ ├── controller │ │ └── JsonDataController.java │ │ ├── dao │ │ ├── JsonDataMapper.java │ │ └── JsonDataMapper.xml │ │ ├── domain │ │ └── JsonData.java │ │ ├── service │ │ ├── IJsonDataService.java │ │ └── impl │ │ │ └── JsonDataServiceImpl.java │ │ └── utils │ │ └── GlobalConfigs.java │ └── resources │ └── application.yml ├── springboot-mybatis-plus ├── .gitignore ├── README.MD ├── pom.xml ├── sql │ └── example.sql └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── MybatisApplication.java │ │ │ ├── controller │ │ │ ├── AreaController.java │ │ │ └── UserController.java │ │ │ ├── dao │ │ │ ├── AreaMapper.java │ │ │ └── UserMapper.java │ │ │ ├── domain │ │ │ ├── Area.java │ │ │ └── User.java │ │ │ ├── service │ │ │ ├── IAreaService.java │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ ├── AreaServiceImpl.java │ │ │ │ └── UserServiceImpl.java │ │ │ └── utils │ │ │ └── GenerationUtils.java │ └── resources │ │ ├── application.yml │ │ └── mapper │ │ ├── AreaMapper.xml │ │ └── UserMapper.xml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── MybatisGenerationApplicationTests.java ├── springboot-rabbitMQ ├── .gitignore ├── common │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── springboot │ │ └── cli │ │ └── mq │ │ └── RabbitDefine.java ├── consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── ConsumerApplication.java │ │ │ └── consumer │ │ │ └── RabbitConsumer.java │ │ └── resources │ │ └── application.yml ├── pom.xml ├── producer │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── springboot │ │ │ │ └── cli │ │ │ │ ├── ProducerApplication.java │ │ │ │ ├── config │ │ │ │ ├── RabbitDeadConfig.java │ │ │ │ ├── RabbitDelayConfig.java │ │ │ │ ├── RabbitDirectConfig.java │ │ │ │ ├── RabbitFanoutConfig.java │ │ │ │ ├── RabbitTopicConfig.java │ │ │ │ └── RabbitTtlDirectConfig.java │ │ │ │ └── producer │ │ │ │ └── RabbitProducer.java │ │ └── resources │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── springboot │ │ └── cli │ │ └── ProducerTest.java └── readme.md ├── springboot-redis ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── config │ │ │ ├── RedisConfig.java │ │ │ └── SessionConfig.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ ├── service │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── utils │ │ │ └── RedisUtils.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-redisson ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── cache │ │ │ └── ProductCache.java │ │ │ ├── config │ │ │ ├── RedissonConfig.java │ │ │ └── RedissonProperties.java │ │ │ └── domain │ │ │ └── Product.java │ └── resources │ │ ├── META-INF │ │ └── additional-spring-configuration-metadata.json │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-scheduler ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── SchedulerApplication.java │ │ │ ├── config │ │ │ └── ExecutorConfig.java │ │ │ └── scheduler │ │ │ ├── ScheduleRunner.java │ │ │ ├── ScheduleService.java │ │ │ └── task │ │ │ ├── Test1TaskImpl.java │ │ │ ├── Test2TaskImpl.java │ │ │ ├── Test3TaskImpl.java │ │ │ ├── Test4TaskImpl.java │ │ │ └── Test5TaskImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-security-captcha ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── domain │ │ │ └── MyUser.java │ │ │ ├── exception │ │ │ └── CaptchaInvalidException.java │ │ │ ├── security │ │ │ ├── AuthUser.java │ │ │ ├── UserDetailsServiceImpl.java │ │ │ ├── WebSecurityConfig.java │ │ │ └── hander │ │ │ │ ├── LoginFailure.java │ │ │ │ ├── LoginSuccess.java │ │ │ │ └── LogoutSuccess.java │ │ │ └── utils │ │ │ ├── CaptchaUtils.java │ │ │ ├── RequestUtils.java │ │ │ └── SecurityUtils.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── index.html │ │ └── login.html │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-security-jwt ├── .gitignore ├── html │ ├── index.html │ ├── info.html │ ├── js │ │ └── jquery-3.6.0.js │ └── readme.md ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── domain │ │ │ └── MyUser.java │ │ │ ├── security │ │ │ ├── JwtFilter.java │ │ │ ├── SecurityConfig.java │ │ │ ├── hander │ │ │ │ ├── AccessFailure.java │ │ │ │ ├── JwtAuthFailure.java │ │ │ │ └── LogoutSuccess.java │ │ │ └── jwt │ │ │ │ └── JwtProvider.java │ │ │ ├── service │ │ │ ├── UserService.java │ │ │ └── impl │ │ │ │ └── UserServiceImpl.java │ │ │ └── utils │ │ │ ├── ResponseResult.java │ │ │ ├── SecurityUtils.java │ │ │ └── SpringContextUtils.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-security-thymeleaf ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── domain │ │ │ └── MyUser.java │ │ │ ├── security │ │ │ ├── AuthUser.java │ │ │ ├── UserDetailsServiceImpl.java │ │ │ ├── WebSecurityConfig.java │ │ │ └── hander │ │ │ │ ├── LoginFailure.java │ │ │ │ ├── LoginSuccess.java │ │ │ │ └── LogoutSuccess.java │ │ │ └── utils │ │ │ └── SecurityUtils.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── index.html │ │ └── login.html │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-security ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ └── security │ │ │ └── WebSecurityConfig.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-shiro-jwt ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── LoginController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ ├── shiro │ │ │ ├── CorsFilter.java │ │ │ ├── JwtRealm.java │ │ │ ├── ShiroConfig.java │ │ │ ├── ShiroDefaultSubjectFactory.java │ │ │ ├── ShiroFilter.java │ │ │ └── jwt │ │ │ │ ├── JwtProvider.java │ │ │ │ └── JwtToken.java │ │ │ └── utils │ │ │ ├── ResponseResult.java │ │ │ └── ShiroUtils.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-shiro ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── config │ │ │ ├── ShiroConfig.java │ │ │ └── UserRealm.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ └── utils │ │ │ └── ShiroUtils.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── index.html │ │ ├── login.html │ │ ├── table.html │ │ ├── unAuth.html │ │ └── userInfo.html │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-swagger ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── config │ │ │ └── SwaggerConfig.java │ │ │ ├── controller │ │ │ └── UserController.java │ │ │ └── entity │ │ │ └── User.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-thymeleaf ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ ├── IndexController.java │ │ │ └── LoginController.java │ │ │ ├── domain │ │ │ └── User.java │ │ │ └── service │ │ │ ├── IUserService.java │ │ │ └── impl │ │ │ └── UserServiceImpl.java │ └── resources │ │ ├── application.yml │ │ └── templates │ │ ├── index.html │ │ ├── login.html │ │ └── userInfo.html │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── JwtDomeApplicationTests.java ├── springboot-upload ├── .gitignore ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── MLinksFileApplication.java │ │ │ ├── confg │ │ │ └── MyExceptionHandler.java │ │ │ ├── controller │ │ │ └── IoFileController.java │ │ │ └── utils │ │ │ ├── FileUtils.java │ │ │ └── ResponseResult.java │ └── resources │ │ └── application.yaml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── MLinksFileApplicationTests.java ├── springboot-validator ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ ├── controller │ │ │ └── IndexController.java │ │ │ ├── dto │ │ │ └── UserVo.java │ │ │ ├── exception │ │ │ └── ExceptionHandlerAdvice.java │ │ │ └── utils │ │ │ └── ResponseResult.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springboot-web ├── .gitignore ├── pom.xml ├── readme.md └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── springboot │ │ │ └── cli │ │ │ ├── WebApplication.java │ │ │ └── controller │ │ │ └── IndexController.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── com │ └── springboot │ └── cli │ └── DomeApplicationTests.java ├── springcloud-gateway ├── .gitignore ├── LICENSE ├── README.md ├── gateway │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── cli │ │ │ └── gateway │ │ │ ├── GatewayAppliction.java │ │ │ ├── config │ │ │ └── GatewayFilter.java │ │ │ └── utils │ │ │ ├── RequestUtils.java │ │ │ └── ResponseResult.java │ │ └── resources │ │ └── bootstrap.yml ├── pom.xml ├── server-1 │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── cli │ │ │ └── server │ │ │ ├── Server1Appliction.java │ │ │ └── controller │ │ │ └── IndexController.java │ │ └── resources │ │ └── bootstrap.yml └── server-2 │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── cli │ │ └── server │ │ ├── Server2Appliction.java │ │ └── controller │ │ └── IndexController.java │ └── resources │ └── bootstrap.yml ├── springcloud-hystrix ├── .gitignore ├── LICENSE ├── README.md ├── common │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── com │ │ └── cli │ │ └── common │ │ └── utils │ │ └── ResponseResult.java ├── consumer │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── cli │ │ │ └── consumer │ │ │ ├── ConsumerServer.java │ │ │ ├── controller │ │ │ └── ConsumerController.java │ │ │ └── openfeign │ │ │ ├── ProviderApi.java │ │ │ └── impl │ │ │ └── ProviderApiImpl.java │ │ └── resources │ │ └── bootstrap.yml ├── pom.xml └── provider │ ├── pom.xml │ └── src │ └── main │ ├── java │ └── com │ │ └── cli │ │ └── provider │ │ ├── ProviderServer.java │ │ └── controller │ │ └── IndexController.java │ └── resources │ └── bootstrap.yml └── springcloud-nacos ├── .gitignore ├── LICENSE ├── README.md ├── consumer ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── cli │ │ └── consumer │ │ ├── ConsumerServer.java │ │ ├── controller │ │ └── ConsumerController.java │ │ └── openfeign │ │ └── ProviderApi.java │ └── resources │ └── bootstrap.yml ├── pom.xml └── provider ├── pom.xml └── src └── main ├── java └── com │ └── cli │ └── provider │ ├── ProviderServer.java │ └── controller │ └── IndexController.java └── resources └── bootstrap.yml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | !**/src/main/**/target/ 4 | !**/src/test/**/target/ 5 | 6 | ### web-ui ### 7 | web-ui/.vscode 8 | web-ui/node_modules/ 9 | web-ui/dist/ 10 | web-ui/npm-debug.log* 11 | web-ui/yarn-debug.log* 12 | web-ui/yarn-error.log* 13 | web-ui/package-lock.json 14 | web-ui/tests/**/coverage/ 15 | 16 | ### springboot ### 17 | */.idea/ 18 | */.idea 19 | */target 20 | */*.log 21 | */*.tmp 22 | */*.gz 23 | */*.iml 24 | */.mvn 25 | */*.ipr 26 | */**/application-test.yml 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 梁其定 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /netty-protobuf-client/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /netty-protobuf-client/doc/readme.md: -------------------------------------------------------------------------------- 1 | # tcp protobuf 测试客户端 2 | 3 | > 用于模拟发送protobuf 协议的消息 4 | ## 接口 5 | 1. 登录 6 | /login?username=admin&password=123456 7 | 2. 发送消息 8 | /send?msgId=1&type=1&data=hello 9 | 3. 连接 10 | /connect?ip=192.168.0.99&port=20000 11 | 4. 重连 12 | /reconnect 13 | 5. 发送json 14 | ```json 15 | Request URL: http://localhost:9999/send/json 16 | Request Method: POST 17 | Request Headers: 18 | { 19 | "Content-Type":"application/json" 20 | } 21 | Request Body: 22 | { 23 | "msgId": 1, 24 | "type": 1, 25 | "data": { 26 | "message":"hello" 27 | } 28 | } 29 | ———————————————— 30 | 版权声明:本文为CSDN博主「全栈小定」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 31 | 原文链接:https://blog.csdn.net/dingdingdandang/article/details/124262130 32 | ``` -------------------------------------------------------------------------------- /netty-protobuf-client/readme.md: -------------------------------------------------------------------------------- 1 | # 基于netty的 protobuf客户端 2 | 3 | ## 环境 4 | 5 | 6 | 7 | | # | 环境 | 版本 | 说明 | 8 | | ---- | ---- | -------------- | --------------- | 9 | | 1 | JDK | openJdk 11.0.8 | 建议JDK11及以上 | 10 | 11 | 12 | 13 | ## 项目结构 14 | 15 | ``` 16 | ├──channel 管道 17 | ├──config 服务配置 18 | ├──controller http测试api 19 | ├──handler 消息处理器 20 | ├──protocol 协议文件 21 | ├──server 服务配置 22 | ├──utils 工具包 23 | ├──NettyClientApplication.java 主启动类 24 | ``` 25 | 26 | ## 测试接口 27 | 28 | > 基础地址 http://localhost:9999 29 | 30 | ```go 31 | 1. 登录 32 | /login?username=admin&password=123456 33 | 2. 发送消息 34 | /send?msgId=1&type=1&data=hello 35 | 3. 连接 36 | /connect?ip=192.168.0.99&port=20000 37 | 4. 重连 38 | /reconnect 39 | 5. 发送json 40 | ```json 41 | Request URL: http://localhost:9999/send/json 42 | Request Method: POST 43 | Request Headers: 44 | { 45 | "Content-Type":"application/json" 46 | } 47 | Request Body: 48 | { 49 | "msgId": 1, 50 | "type": 1, 51 | "data": { 52 | "message":"hello" 53 | } 54 | } 55 | ``` 56 | 57 | -------------------------------------------------------------------------------- /netty-protobuf-client/src/main/java/com/netty/client/NettyClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.netty.client; 2 | 3 | 4 | import com.netty.client.server.TcpClient; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.boot.ApplicationArguments; 7 | import org.springframework.boot.ApplicationRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | 12 | /** 13 | * @author qiding 14 | */ 15 | @SpringBootApplication 16 | @RequiredArgsConstructor 17 | public class NettyClientApplication implements ApplicationRunner { 18 | 19 | private final TcpClient tcpClient; 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NettyClientApplication.class, args); 23 | } 24 | 25 | @Override 26 | public void run(ApplicationArguments args) throws Exception { 27 | tcpClient.start(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /netty-protobuf-client/src/main/java/com/netty/client/config/ClientProperties.java: -------------------------------------------------------------------------------- 1 | package com.netty.client.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 服务配置 9 | * 10 | * @author qiding 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = ClientProperties.PREFIX) 14 | @Data 15 | public class ClientProperties { 16 | 17 | public static final String PREFIX = "netty"; 18 | 19 | /** 20 | * 客户端ip 21 | */ 22 | private Integer clientPort; 23 | 24 | /** 25 | * 默认连接的服务器ip 26 | */ 27 | private String serverIp; 28 | 29 | /** 30 | * 默认连接的服务器端口 31 | */ 32 | private Integer serverPort; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /netty-protobuf-client/src/main/java/com/netty/client/server/ITcpClient.java: -------------------------------------------------------------------------------- 1 | package com.netty.client.server; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | /** 6 | * @author qiding 7 | */ 8 | public interface ITcpClient { 9 | 10 | 11 | /** 12 | * 主启动程序,初始化参数 13 | * 14 | * @throws Exception 初始化异常 15 | */ 16 | void start() throws Exception; 17 | 18 | 19 | /** 20 | * 重启 21 | * 22 | * @throws Exception e 23 | */ 24 | void reconnect() throws Exception; 25 | 26 | 27 | /** 28 | * 优雅的结束服务器 29 | * 30 | * @throws InterruptedException 提前中断异常 31 | */ 32 | @PreDestroy 33 | void destroy() throws InterruptedException; 34 | } 35 | -------------------------------------------------------------------------------- /netty-protobuf-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "tcp.client-port", 5 | "type": "java.lang.String", 6 | "description": "客户端端口 tcp.client-port." 7 | }, 8 | { 9 | "name": "tcp.server-ip", 10 | "type": "java.lang.String", 11 | "description": "默认连接的服务器ip tcp.server-ip." 12 | }, 13 | { 14 | "name": "tcp.server-port", 15 | "type": "java.lang.String", 16 | "description": "默认连接的服务器端口 tcp.server-port." 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /netty-protobuf-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | application: 6 | name: tcp-client 7 | 8 | # tcp 9 | netty: 10 | client-port: 19999 11 | server-ip: 127.0.0.1 12 | server-port: 20000 13 | 14 | # 日记配置 15 | logging: 16 | level: 17 | com.netty: debug -------------------------------------------------------------------------------- /netty-protobuf-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /netty-protobuf-server/doc/protoc-3.20.1-rc-1-win64.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangqiding/springboot-cli/8c6927c300602c1afc79cb49a124bbf065d13f25/netty-protobuf-server/doc/protoc-3.20.1-rc-1-win64.zip -------------------------------------------------------------------------------- /netty-protobuf-server/src/main/java/com/netty/server/NettyServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.netty.server; 2 | 3 | 4 | import com.netty.server.server.TcpServer; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.boot.ApplicationArguments; 7 | import org.springframework.boot.ApplicationRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | /** 12 | * 13 | * @author qiding 14 | */ 15 | @SpringBootApplication 16 | @RequiredArgsConstructor 17 | public class NettyServerApplication implements ApplicationRunner { 18 | 19 | private final TcpServer tcpServer; 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NettyServerApplication.class, args); 23 | } 24 | 25 | @Override 26 | public void run(ApplicationArguments args) throws Exception { 27 | tcpServer.start(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /netty-protobuf-server/src/main/java/com/netty/server/config/ServerProperties.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 服务配置 9 | * 10 | * @author qiding 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = ServerProperties.PREFIX) 14 | @Data 15 | public class ServerProperties { 16 | 17 | public static final String PREFIX = "netty.server"; 18 | 19 | /** 20 | * 服务器ip 21 | */ 22 | private String ip; 23 | 24 | /** 25 | * 服务器端口 26 | */ 27 | private Integer port; 28 | 29 | /** 30 | * 传输模式linux上开启会有更高的性能 31 | */ 32 | private boolean useEpoll; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /netty-protobuf-server/src/main/java/com/netty/server/server/ITcpServer.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.server; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | /** 6 | * @author qiding 7 | */ 8 | public interface ITcpServer { 9 | 10 | 11 | /** 12 | * 主启动程序,初始化参数 13 | * 14 | * @throws Exception 初始化异常 15 | */ 16 | void start() throws Exception; 17 | 18 | 19 | /** 20 | * 优雅的结束服务器 21 | * 22 | * @throws InterruptedException 提前中断异常 23 | */ 24 | @PreDestroy 25 | void destroy() throws InterruptedException; 26 | } 27 | -------------------------------------------------------------------------------- /netty-protobuf-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "netty.server.host", 5 | "type": "java.lang.String", 6 | "description": "监听的ip." 7 | }, 8 | { 9 | "name": "netty.server.port", 10 | "type": "java.lang.String", 11 | "description": "监听的端口." 12 | }, 13 | { 14 | "name": "netty.server.use-epoll", 15 | "type": "java.lang.String", 16 | "description": "传输模式linux上开启会有更高的性能." 17 | } 18 | ] } -------------------------------------------------------------------------------- /netty-protobuf-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: tcp-server 4 | 5 | # tcp 6 | netty: 7 | server: 8 | host: 127.0.0.1 9 | port: 20000 10 | # 传输模式linux上开启会有更高的性能 11 | use-epoll: false 12 | 13 | # 日记配置 14 | logging: 15 | level: 16 | # 开启debug日记打印 17 | com.netty: debug -------------------------------------------------------------------------------- /netty-tcp-client/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /netty-tcp-client/readme.md: -------------------------------------------------------------------------------- 1 | # 基于netty的基础Tcp客户端 2 | 3 | ## 简介 4 | 5 | netty是jboss提供的一个java开源框架,netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可用性的网络服务器和客户端程序。 6 | 7 | ## 环境 8 | 9 | | # | 环境 | 版本 | 说明 | 10 | | ---- | ---- | -------------- | --------------- | 11 | | 1 | JDK | openJdk 11.0.8 | 建议JDK11及以上 | 12 | 13 | ## 项目结构 14 | 15 | ``` 16 | ├──channel 管道配置 17 | ├──handler 消息处理器 18 | ├──server 服务配置 19 | ├──store 频道存储 20 | ├──utils 工具包 21 | ├──NettyClientApplication.java 主启动类 22 | ``` 23 | 24 | ## 接口 25 | 26 | > 基础地址:http://localhost:9999 27 | 28 | ```go 29 | # 1. 发送消息 30 | /send?message=hello 31 | # 2. 连接 32 | /connect?ip=192.168.0.99&port=20000 33 | # 3. 重连 34 | /reconnect 35 | # 5. 发送json 36 | ```json 37 | Request URL: http://localhost:9999/send/json 38 | Request Method: POST 39 | Request Headers: 40 | { 41 | "Content-Type":"application/json" 42 | } 43 | Request Body: 44 | { 45 | "msgId": 1, 46 | "type": 1, 47 | "data": { 48 | "message":"hello" 49 | } 50 | } 51 | ``` 52 | 53 | -------------------------------------------------------------------------------- /netty-tcp-client/src/main/java/com/netty/client/NettyClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.netty.client; 2 | 3 | 4 | import com.netty.client.server.TcpClient; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.boot.ApplicationArguments; 7 | import org.springframework.boot.ApplicationRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | 12 | /** 13 | * @author qiding 14 | */ 15 | @SpringBootApplication 16 | @RequiredArgsConstructor 17 | public class NettyClientApplication implements ApplicationRunner { 18 | 19 | private final TcpClient tcpClient; 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NettyClientApplication.class, args); 23 | } 24 | 25 | @Override 26 | public void run(ApplicationArguments args) throws Exception { 27 | tcpClient.start(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /netty-tcp-client/src/main/java/com/netty/client/config/ClientProperties.java: -------------------------------------------------------------------------------- 1 | package com.netty.client.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 读取YML中的服务配置 9 | * 10 | * @author ding 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = ClientProperties.PREFIX) 14 | @Data 15 | public class ClientProperties { 16 | 17 | public static final String PREFIX = "netty"; 18 | 19 | /** 20 | * 客户端ip 21 | */ 22 | private Integer clientPort; 23 | 24 | /** 25 | * 默认连接的服务器ip 26 | */ 27 | private String serverIp; 28 | 29 | /** 30 | * 默认连接的服务器端口 31 | */ 32 | private Integer serverPort; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /netty-tcp-client/src/main/java/com/netty/client/server/ITcpClient.java: -------------------------------------------------------------------------------- 1 | package com.netty.client.server; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | /** 6 | * @author qiding 7 | */ 8 | public interface ITcpClient { 9 | 10 | 11 | /** 12 | * 主启动程序,初始化参数 13 | * 14 | * @throws Exception 初始化异常 15 | */ 16 | void start() throws Exception; 17 | 18 | 19 | /** 20 | * 重启 21 | * 22 | * @throws Exception e 23 | */ 24 | void reconnect() throws Exception; 25 | 26 | 27 | /** 28 | * 优雅的结束服务器 29 | * 30 | * @throws InterruptedException 提前中断异常 31 | */ 32 | @PreDestroy 33 | void destroy() throws InterruptedException; 34 | } 35 | -------------------------------------------------------------------------------- /netty-tcp-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "tcp.client-port", 5 | "type": "java.lang.String", 6 | "description": "客户端端口 tcp.client-port." 7 | }, 8 | { 9 | "name": "tcp.server-ip", 10 | "type": "java.lang.String", 11 | "description": "默认连接的服务器ip tcp.server-ip." 12 | }, 13 | { 14 | "name": "tcp.server-port", 15 | "type": "java.lang.String", 16 | "description": "默认连接的服务器端口 tcp.server-port." 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /netty-tcp-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | application: 6 | name: tcp-client 7 | 8 | # tcp 9 | netty: 10 | client-port: 19999 11 | server-ip: 127.0.0.1 12 | server-port: 20000 13 | 14 | # 日记配置 15 | logging: 16 | level: 17 | com.netty: debug -------------------------------------------------------------------------------- /netty-tcp-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /netty-tcp-server/readme.md: -------------------------------------------------------------------------------- 1 | # 基于netty的基础Tcp服务器 2 | 3 | ## 简介 4 | 5 | - netty是jboss提供的一个java开源框架,netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可用性的网络服务器和客户端程序。 6 | - 本项目是基于Netty搭建的基础项目模板。 7 | 8 | ## 环境 9 | 10 | | # | 环境 | 版本 | 说明 | 11 | | ---- | ---- | -------------- | --------------- | 12 | | 1 | JDK | openJdk 11.0.8 | 建议JDK11及以上 | 13 | 14 | ## 项目结构 15 | 16 | ``` 17 | ├──channel 管道配置 18 | ├──handler 消息处理器 19 | ├──server 服务配置 20 | ├──store 频道存储 21 | ├──NettyServerApplication.java 主启动类 22 | ``` 23 | -------------------------------------------------------------------------------- /netty-tcp-server/src/main/java/com/netty/server/NettyServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.netty.server; 2 | 3 | 4 | import com.netty.server.server.TcpServer; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.boot.ApplicationArguments; 7 | import org.springframework.boot.ApplicationRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | 12 | /** 13 | * @author ding 14 | */ 15 | @SpringBootApplication 16 | @RequiredArgsConstructor 17 | public class NettyServerApplication implements ApplicationRunner { 18 | 19 | private final TcpServer tcpServer; 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NettyServerApplication.class, args); 23 | } 24 | 25 | @Override 26 | public void run(ApplicationArguments args) throws Exception { 27 | tcpServer.start(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /netty-tcp-server/src/main/java/com/netty/server/config/ServerProperties.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 读取YML中的服务配置 9 | * 10 | * @author ding 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = ServerProperties.PREFIX) 14 | @Data 15 | public class ServerProperties { 16 | 17 | public static final String PREFIX = "netty.server"; 18 | 19 | /** 20 | * 服务器ip 21 | */ 22 | private String ip; 23 | 24 | /** 25 | * 服务器端口 26 | */ 27 | private Integer port; 28 | 29 | /** 30 | * 传输模式linux上开启会有更高的性能 31 | */ 32 | private boolean useEpoll; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /netty-tcp-server/src/main/java/com/netty/server/server/ITcpServer.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.server; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | /** 6 | * @author qiding 7 | */ 8 | public interface ITcpServer { 9 | 10 | 11 | /** 12 | * 主启动程序,初始化参数 13 | * 14 | * @throws Exception 初始化异常 15 | */ 16 | void start() throws Exception; 17 | 18 | 19 | /** 20 | * 优雅的结束服务器 21 | * 22 | * @throws InterruptedException 提前中断异常 23 | */ 24 | @PreDestroy 25 | void destroy() throws InterruptedException; 26 | } 27 | -------------------------------------------------------------------------------- /netty-tcp-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "netty.server.host", 5 | "type": "java.lang.String", 6 | "description": "监听的ip." 7 | }, 8 | { 9 | "name": "netty.server.port", 10 | "type": "java.lang.String", 11 | "description": "监听的端口." 12 | }, 13 | { 14 | "name": "netty.server.use-epoll", 15 | "type": "java.lang.String", 16 | "description": "传输模式linux上开启会有更高的性能." 17 | } 18 | ] } -------------------------------------------------------------------------------- /netty-tcp-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: tcp-server 4 | 5 | # tcp 6 | netty: 7 | server: 8 | host: 127.0.0.1 9 | port: 20000 10 | # 传输模式linux上开启会有更高的性能 11 | use-epoll: false 12 | 13 | # 日记配置 14 | logging: 15 | level: 16 | # 开启debug日记打印 17 | com.netty: debug -------------------------------------------------------------------------------- /netty-websocket-client/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /netty-websocket-client/readme.md: -------------------------------------------------------------------------------- 1 | # 基于netty的websoket客户端 2 | 3 | ## 简介 4 | 5 | - netty是jboss提供的一个java开源框架,netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可用性的网络服务器和客户端程序。 6 | - 本项目是基于Netty搭建的基础项目模板。 7 | 8 | ## 环境 9 | 10 | | # | 环境 | 版本 | 说明 | 11 | | ---- | ---- | -------------- | --------------- | 12 | | 1 | JDK | openJdk 11.0.8 | 建议JDK11及以上 | 13 | 14 | ## 项目结构 15 | 16 | ``` 17 | ├──channel 管道 18 | ├──config 服务配置 19 | ├──handler 消息处理器 20 | ├──server 服务配置 21 | ├──store 频道存储 22 | ├──NettyClientApplication.java 主启动类 23 | ``` 24 | 25 | ## api 26 | 27 | > 基础地址 http://localhost:9999 28 | 29 | ```go 30 | # 1. 发送消息 31 | /send?message=hello 32 | # 2. 连接 33 | /connect?ip=192.168.0.99&port=20000 34 | # 3. 重连 35 | /reconnect 36 | # 5. 发送json 37 | ```json 38 | Request URL: http://localhost:9999/send/json 39 | Request Method: POST 40 | Request Headers: 41 | { 42 | "Content-Type":"application/json" 43 | } 44 | Request Body: 45 | { 46 | "msgId": 1, 47 | "type": 1, 48 | "data": { 49 | "message":"hello" 50 | } 51 | } 52 | ``` 53 | 54 | -------------------------------------------------------------------------------- /netty-websocket-client/src/main/java/com/netty/client/NettyClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.netty.client; 2 | 3 | 4 | import com.netty.client.server.WebsocketClient; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.boot.ApplicationArguments; 7 | import org.springframework.boot.ApplicationRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | 12 | /** 13 | * @author ding 14 | */ 15 | @SpringBootApplication 16 | @RequiredArgsConstructor 17 | public class NettyClientApplication implements ApplicationRunner { 18 | 19 | private final WebsocketClient tcpClient; 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NettyClientApplication.class, args); 23 | } 24 | 25 | @Override 26 | public void run(ApplicationArguments args){ 27 | tcpClient.start(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /netty-websocket-client/src/main/java/com/netty/client/config/ClientProperties.java: -------------------------------------------------------------------------------- 1 | package com.netty.client.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 服务配置 9 | * 10 | * @author qiding 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = ClientProperties.PREFIX) 14 | @Data 15 | public class ClientProperties { 16 | 17 | public static final String PREFIX = "netty"; 18 | 19 | /** 20 | * 客户端ip 21 | */ 22 | private Integer clientPort; 23 | 24 | /** 25 | * 默认连接的服务器ip 26 | */ 27 | private String serverIp; 28 | 29 | /** 30 | * 默认连接的服务器端口 31 | */ 32 | private Integer serverPort; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /netty-websocket-client/src/main/java/com/netty/client/server/IWebsocketClient.java: -------------------------------------------------------------------------------- 1 | package com.netty.client.server; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | /** 6 | * @author qiding 7 | */ 8 | public interface IWebsocketClient { 9 | 10 | 11 | /** 12 | * 主启动程序,初始化参数 13 | * 14 | * @throws Exception 初始化异常 15 | */ 16 | void start() throws Exception; 17 | 18 | 19 | /** 20 | * 重启 21 | * 22 | * @throws Exception e 23 | */ 24 | void reconnect() throws Exception; 25 | 26 | 27 | /** 28 | * 优雅的结束服务器 29 | * 30 | * @throws InterruptedException 提前中断异常 31 | */ 32 | @PreDestroy 33 | void destroy() throws InterruptedException; 34 | } 35 | -------------------------------------------------------------------------------- /netty-websocket-client/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "tcp.client-port", 5 | "type": "java.lang.String", 6 | "description": "客户端端口 tcp.client-port." 7 | }, 8 | { 9 | "name": "tcp.server-ip", 10 | "type": "java.lang.String", 11 | "description": "默认连接的服务器ip tcp.server-ip." 12 | }, 13 | { 14 | "name": "tcp.server-port", 15 | "type": "java.lang.String", 16 | "description": "默认连接的服务器端口 tcp.server-port." 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /netty-websocket-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | application: 6 | name: tcp-client 7 | 8 | # tcp 9 | netty: 10 | client-port: 19999 11 | server-ip: 127.0.0.1 12 | server-port: 20000 13 | 14 | # 日记配置 15 | logging: 16 | level: 17 | com.netty: debug -------------------------------------------------------------------------------- /netty-websocket-server/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /netty-websocket-server/readme.md: -------------------------------------------------------------------------------- 1 | # 基于netty的websocket服务器 2 | 3 | ## 简介 4 | 5 | - netty是jboss提供的一个java开源框架,netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可用性的网络服务器和客户端程序。 6 | - 本项目是基于Netty搭建的基础项目模板。 7 | 8 | ## 环境 9 | 10 | | # | 环境 | 版本 | 说明 | 11 | | ---- | ---- | -------------- | --------------- | 12 | | 1 | JDK | openJdk 11.0.8 | 建议JDK11及以上 | 13 | 14 | 15 | 16 | ## 项目结构 17 | 18 | ``` 19 | ├──channel 管道 20 | ├──config 服务核心配置 21 | ├──handler 消息处理器 22 | ├──server 服务配置 23 | ├──store 频道存储 24 | ├──NettyServerApplication.java 主启动类 25 | ``` 26 | 27 | -------------------------------------------------------------------------------- /netty-websocket-server/src/main/java/com/netty/server/NettyServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.netty.server; 2 | 3 | 4 | import com.netty.server.server.TcpServer; 5 | import lombok.RequiredArgsConstructor; 6 | import org.springframework.boot.ApplicationArguments; 7 | import org.springframework.boot.ApplicationRunner; 8 | import org.springframework.boot.SpringApplication; 9 | import org.springframework.boot.autoconfigure.SpringBootApplication; 10 | 11 | 12 | /** 13 | * @author qiding 14 | */ 15 | @SpringBootApplication 16 | @RequiredArgsConstructor 17 | public class NettyServerApplication implements ApplicationRunner { 18 | 19 | private final TcpServer tcpServer; 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(NettyServerApplication.class, args); 23 | } 24 | 25 | @Override 26 | public void run(ApplicationArguments args) throws Exception { 27 | tcpServer.start(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /netty-websocket-server/src/main/java/com/netty/server/config/ServerProperties.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * 服务配置 9 | * 10 | * @author qiding 11 | */ 12 | @Configuration 13 | @ConfigurationProperties(prefix = ServerProperties.PREFIX) 14 | @Data 15 | public class ServerProperties { 16 | 17 | public static final String PREFIX = "netty.server"; 18 | 19 | /** 20 | * 服务器ip 21 | */ 22 | private String ip; 23 | 24 | /** 25 | * 服务器端口 26 | */ 27 | private Integer port; 28 | 29 | /** 30 | * 传输模式linux上开启会有更高的性能 31 | */ 32 | private boolean useEpoll; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /netty-websocket-server/src/main/java/com/netty/server/server/ITcpServer.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.server; 2 | 3 | import javax.annotation.PreDestroy; 4 | 5 | /** 6 | * @author qiding 7 | */ 8 | public interface ITcpServer { 9 | 10 | 11 | /** 12 | * 主启动程序,初始化参数 13 | * 14 | * @throws Exception 初始化异常 15 | */ 16 | void start() throws Exception; 17 | 18 | 19 | /** 20 | * 优雅的结束服务器 21 | * 22 | * @throws InterruptedException 提前中断异常 23 | */ 24 | @PreDestroy 25 | void destroy() throws InterruptedException; 26 | } 27 | -------------------------------------------------------------------------------- /netty-websocket-server/src/main/java/com/netty/server/store/WebSocketSession.java: -------------------------------------------------------------------------------- 1 | package com.netty.server.store; 2 | 3 | import io.netty.channel.ChannelId; 4 | import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; 5 | 6 | import java.util.HashMap; 7 | 8 | /** 9 | * 管理websocket握手会话 10 | * 11 | * @author qiding 12 | */ 13 | public class WebSocketSession { 14 | 15 | private final static HashMap CHANNEL_SHAKER = new HashMap<>(); 16 | 17 | /** 18 | * 添加 19 | */ 20 | public static void setChannelShaker(ChannelId channelId, WebSocketServerHandshaker handShaker) { 21 | CHANNEL_SHAKER.put(channelId, handShaker); 22 | } 23 | 24 | /** 25 | * 获取 26 | */ 27 | public static WebSocketServerHandshaker getChannelShaker(ChannelId channelId) { 28 | return CHANNEL_SHAKER.get(channelId); 29 | } 30 | 31 | /** 32 | * 释放 33 | */ 34 | public static void clear(ChannelId channelId) { 35 | CHANNEL_SHAKER.remove(channelId); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /netty-websocket-server/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "netty.server.host", 5 | "type": "java.lang.String", 6 | "description": "监听的ip." 7 | }, 8 | { 9 | "name": "netty.server.port", 10 | "type": "java.lang.String", 11 | "description": "监听的端口." 12 | }, 13 | { 14 | "name": "netty.server.use-epoll", 15 | "type": "java.lang.String", 16 | "description": "传输模式linux上开启会有更高的性能." 17 | } 18 | ] } -------------------------------------------------------------------------------- /netty-websocket-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: tcp-server 4 | 5 | # tcp 6 | netty: 7 | server: 8 | host: 127.0.0.1 9 | port: 20000 10 | use-epoll: false 11 | 12 | # 日记配置 13 | logging: 14 | level: 15 | # 开启debug日记打印 16 | com.netty: debug -------------------------------------------------------------------------------- /springboot-aop-logger/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-aop-logger/readme.md: -------------------------------------------------------------------------------- 1 | #### 访问 2 | > 浏览器输入 3 | 4 | ``` 5 | http://localhost:9999/test?msg=hello 6 | ``` 7 | -------------------------------------------------------------------------------- /springboot-aop-logger/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | public class WebApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(WebApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-aop-logger/src/main/java/com/springboot/cli/annotation/CustomLog.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * 自定义注解 7 | * 8 | * @author : ding 9 | */ 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Target(value = {ElementType.METHOD}) 12 | @Documented 13 | public @interface CustomLog { 14 | 15 | /** 16 | * value 描述 17 | */ 18 | String value() default ""; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot-aop-logger/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | import com.springboot.cli.annotation.CustomLog; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @RestController 11 | public class IndexController { 12 | 13 | /** 14 | * 基础web 15 | */ 16 | @GetMapping("/test") 17 | @CustomLog("基础web") 18 | public String test(String msg) { 19 | return "欢迎使用 springboot-cli !"; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-aop-logger/src/main/java/com/springboot/cli/model/SysLog.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.model; 2 | 3 | 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * 日记实体 11 | * 12 | * @author ding 13 | */ 14 | @Data 15 | @Accessors(chain = true) 16 | public class SysLog implements Serializable { 17 | 18 | private static final long serialVersionUID = -6309732882044872298L; 19 | 20 | /** 21 | * 日记id 22 | */ 23 | private Long logId; 24 | 25 | /** 26 | * 用户id 27 | */ 28 | private Long userId; 29 | 30 | /** 31 | * 包名 32 | */ 33 | private String packageName; 34 | 35 | /** 36 | * 执行时间 37 | */ 38 | private Long executionTime; 39 | 40 | /** 41 | * 方法名 42 | */ 43 | private String method; 44 | 45 | /** 46 | * 参数 47 | */ 48 | private String params; 49 | 50 | /** 51 | * 说明 52 | */ 53 | private String desc; 54 | 55 | /** 56 | * 创建日期 57 | */ 58 | private Date createTime; 59 | } 60 | -------------------------------------------------------------------------------- /springboot-aop-logger/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-async/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-async/readme.md: -------------------------------------------------------------------------------- 1 | ## 使用 2 | 3 | - 运行测试类`DomeApplicationTests.java`中的test用例 -------------------------------------------------------------------------------- /springboot-async/src/main/java/com/springboot/cli/AsyncApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | /** 9 | * @author ding 10 | */ 11 | @SpringBootApplication 12 | @Slf4j 13 | public class AsyncApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(AsyncApplication.class, args); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/com/springboot/cli/async/AsyncTask.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.async; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.scheduling.annotation.Async; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * 使用 @Async开启异步执行 9 | * 10 | * @author ding 11 | */ 12 | @Component 13 | @Slf4j 14 | public class AsyncTask { 15 | 16 | @Async("testExecutor") 17 | public void run() { 18 | log.info("当前线程名称为:{}", Thread.currentThread().getName()); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-async/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-async/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import com.springboot.cli.async.AsyncTask; 4 | import org.junit.jupiter.api.Test; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | @SpringBootTest 9 | class DomeApplicationTests { 10 | 11 | @Autowired 12 | AsyncTask asyncTask; 13 | 14 | @Test 15 | void test() { 16 | for (int i = 0; i < 10; i++) { 17 | asyncTask.run(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-captcha/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-captcha/readme.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 3 | 致力于让开发者快速搭建基础环境并让应用跑起来,提供使用示例供使用者参考,让初学者快速上手。 4 | 5 | ## 环境 6 | 7 | 8 | ## 使用示例 9 | 10 | - 浏览器输入 11 | 12 | ``` 13 | http://localhost:9999/getCaptcha 14 | ``` 15 | 16 | -------------------------------------------------------------------------------- /springboot-captcha/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-captcha/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | 4 | import com.springboot.cli.utils.CaptchaUtils; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | /** 11 | * @author ding 12 | */ 13 | @RestController 14 | public class IndexController { 15 | 16 | 17 | /** 18 | * 获取验证码 19 | */ 20 | @GetMapping("/getCaptcha") 21 | public void getCaptcha(String uuid, HttpServletResponse response) throws IOException { 22 | CaptchaUtils.getCircleCaptcha(uuid, response); 23 | } 24 | 25 | /** 26 | * 模拟登录校验 27 | */ 28 | @GetMapping("/login") 29 | public boolean login(String uuid, String code, String username, String password) { 30 | return CaptchaUtils.verify(uuid, code); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /springboot-captcha/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-captcha/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-demo/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-demo/readme.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 3 | 致力于让开发者快速搭建基础环境并让应用跑起来,提供使用示例供使用者参考,让初学者快速上手。 4 | 5 | ## 环境 6 | 7 | 8 | ## 使用示例 9 | 10 | - 浏览器输入 11 | 12 | ``` 13 | http://localhost:9999/ 14 | ``` 15 | 16 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/executors/ExecutorsDemo.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.executors; 2 | 3 | import java.util.concurrent.Executor; 4 | import java.util.concurrent.ExecutorService; 5 | import java.util.concurrent.Executors; 6 | 7 | 8 | public class ExecutorsDemo { 9 | 10 | public static void print(String msg) { 11 | System.out.println(Thread.currentThread().getName() + ":" + msg); 12 | } 13 | 14 | public static void main(String[] args) { 15 | ExecutorService executorService = Executors.newWorkStealingPool(4); 16 | executorService.execute(() -> ExecutorsDemo.print("任务1")); 17 | executorService.execute(() -> ExecutorsDemo.print("任务2")); 18 | executorService.execute(() -> ExecutorsDemo.print("任务3")); 19 | executorService.execute(() -> ExecutorsDemo.print("任务4")); 20 | // 由于是线程是抢占式,必须保持程序不终止,否则可能导致线程抢不到任务程序就终止了 21 | while (true) {} 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/lock/Reentrant.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.lock; 2 | 3 | /** 4 | * 可重入锁 5 | * 有了可重入锁之后,破解第一把之后就可以一直持有该锁,直到内层执行完毕 6 | * @author ding 7 | */ 8 | public class Reentrant { 9 | 10 | public static void test() { 11 | Object o = new Object(); 12 | new Thread(() -> { 13 | synchronized (o) { 14 | System.out.println(Thread.currentThread().getName() + "买1"); 15 | 16 | synchronized (o) { 17 | System.out.println(Thread.currentThread().getName() + "送1"); 18 | 19 | synchronized (o) { 20 | System.out.println(Thread.currentThread().getName() + "再送"); 21 | } 22 | } 23 | } 24 | 25 | }, "线程:").start(); 26 | } 27 | 28 | public static void main(String[] args) { 29 | test(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/lock/SpinLock.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.lock; 2 | 3 | import java.util.concurrent.atomic.AtomicReference; 4 | 5 | /** 6 | * 自旋锁 7 | * 8 | * @author ding 9 | */ 10 | public class SpinLock { 11 | 12 | private static final AtomicReference CAS = new AtomicReference<>(); 13 | 14 | public static void lock() { 15 | Thread current = Thread.currentThread(); 16 | // 利用CAS,compare比较CAS中值是否为空,为空则把值更新为新的线程并返回true,否则一直循环运行 17 | while (!CAS.compareAndSet(null, current)) { 18 | } 19 | // DO nothing 20 | System.out.println(Thread.currentThread().getName() + "获得锁"); 21 | } 22 | 23 | public static void unlock() { 24 | // 解锁也很简单,compare比较当前线程是否拥有锁,拥有则把CAS中的值重新设空即可 25 | Thread current = Thread.currentThread(); 26 | CAS.compareAndSet(current, null); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/thread/CallableDemo.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.thread; 2 | 3 | import java.util.concurrent.Callable; 4 | import java.util.concurrent.ExecutionException; 5 | import java.util.concurrent.FutureTask; 6 | 7 | /** 8 | * 实现 Callable 接口 9 | * 带执行回调 10 | * 11 | * @author ding 12 | */ 13 | public class CallableDemo implements Callable { 14 | 15 | @Override 16 | public String call() { 17 | System.out.println(Thread.currentThread().getName() + "执行了"); 18 | return "执行成功!"; 19 | } 20 | 21 | public static void main(String[] args) throws ExecutionException, InterruptedException { 22 | CallableDemo mc = new CallableDemo(); 23 | FutureTask ft0 = new FutureTask<>(mc); 24 | FutureTask ft1 = new FutureTask<>(mc); 25 | Thread thread0 = new Thread(ft0); 26 | Thread thread1 = new Thread(ft1); 27 | thread0.start(); 28 | thread1.start(); 29 | System.out.println(ft0.get()); 30 | System.out.println(ft1.get()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/thread/RunnableDemo.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.thread; 2 | 3 | /** 4 | * Runnable 开启多线程 5 | * 需要实现接口中的 run() 方法。 6 | * @author ding 7 | */ 8 | public class RunnableDemo implements Runnable { 9 | 10 | @Override 11 | public void run() { 12 | System.out.println(Thread.currentThread().getName() + "执行了"); 13 | } 14 | 15 | /** 16 | * 使用 Runnable 实例再创建一个 Thread 实例,然后调用 Thread 实例的 start() 方法来启动线程。 17 | */ 18 | public static void main(String[] args) { 19 | RunnableDemo runnable = new RunnableDemo(); 20 | Thread thread0 = new Thread(runnable); 21 | Thread thread1 = new Thread(runnable); 22 | thread0.start(); 23 | thread1.start(); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/thread/ThreadDemo.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.thread; 2 | 3 | /** 4 | * @author ding 5 | */ 6 | public class ThreadDemo extends Thread { 7 | 8 | @Override 9 | public void run() { 10 | System.out.println(Thread.currentThread().getName() + "执行了"); 11 | } 12 | 13 | public static void main(String[] args) { 14 | ThreadDemo thread0 = new ThreadDemo(); 15 | ThreadDemo thread1 = new ThreadDemo(); 16 | thread0.start(); 17 | thread1.start(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-demo/src/main/java/com/springboot/cli/thread/ThreadTest.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.thread; 2 | 3 | /** 4 | * 直接创建Thread对象新建线程 5 | * 6 | * @author ding 7 | */ 8 | public class ThreadTest { 9 | 10 | public static void start() { 11 | new Thread(new Runnable() { 12 | @Override 13 | public void run() { 14 | System.out.println(Thread.currentThread().getName() + "执行了"); 15 | } 16 | }).start(); 17 | } 18 | 19 | public static void main(String[] args) { 20 | start(); 21 | start(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-demo/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-demo/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-druid/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-druid/readme.md: -------------------------------------------------------------------------------- 1 | ## 前置 2 | - 创建`example`数据库 3 | - 运行`example.sql`导入数据表 4 | - 修改`application.yml`中数据库连接地址及密码 5 | 6 | ## 使用 7 | - 启动项目 8 | - druid监控界面地址 账号密码 root/123456 9 | ```go 10 | http://localhost:9999/druid/sql.html 11 | ``` 12 | - 查询接口 13 | ```go 14 | http://localhost:9999/list 15 | ``` -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | 4 | import com.springboot.cli.domain.User; 5 | import com.springboot.cli.service.impl.UserServiceImpl; 6 | import lombok.RequiredArgsConstructor; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author ding 15 | */ 16 | @RestController 17 | @Slf4j 18 | @RequiredArgsConstructor 19 | public class IndexController { 20 | 21 | 22 | private final UserServiceImpl userService; 23 | /** 24 | * 查询所有用户 25 | */ 26 | @GetMapping("/list") 27 | public List list() { 28 | return userService.list(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/springboot/cli/dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.dao; 2 | 3 | 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import com.springboot.cli.domain.User; 6 | import org.apache.ibatis.annotations.Mapper; 7 | 8 | /** 9 | *

10 | * Mapper 接口 11 | *

12 | * 13 | * @author qiDing 14 | * @since 2022-04-11 15 | */ 16 | @Mapper 17 | public interface UserMapper extends BaseMapper { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/springboot/cli/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import com.springboot.cli.domain.User; 5 | 6 | 7 | /** 8 | *

9 | * 服务类 10 | *

11 | * 12 | * @author ding 13 | * @since 2022-04-11 14 | */ 15 | public interface IUserService extends IService { 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-druid/src/main/java/com/springboot/cli/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import com.springboot.cli.dao.UserMapper; 5 | import com.springboot.cli.domain.User; 6 | import com.springboot.cli.service.IUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | 10 | /** 11 | *

12 | * 服务实现类 13 | *

14 | * 15 | * @author qiDing 16 | * @since 2022-04-11 17 | */ 18 | @Service 19 | public class UserServiceImpl extends ServiceImpl implements IUserService { 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-druid/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /springboot-druid/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.springboot.cli.domain.User; 5 | import com.springboot.cli.service.IUserService; 6 | import org.junit.jupiter.api.Test; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import java.util.List; 11 | 12 | @SpringBootTest 13 | class DomeApplicationTests { 14 | 15 | @Autowired 16 | IUserService userService; 17 | 18 | @Test 19 | void test() { 20 | List list = userService.list(); 21 | System.out.println(JSON.toJSONString(list)); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /springboot-elasticsearch/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-elasticsearch/readme.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 3 | 致力于让开发者快速搭建基础环境并让应用跑起来,提供使用示例供使用者参考,让初学者快速上手。 4 | 5 | ## 环境 6 | 7 | - 修改yml中`elasticsearch.url`的地址为你实际的地址 8 | - 无需主动创建表,确保`elasticsearch`正确安装且连接正常即可 9 | 10 | ## 使用示例 11 | 12 | - 打开测试类 13 | 14 | 路径:`src\test\java\com\springboot\cli\DemoApplicationTests` 15 | 16 | - 运行测试方法 17 | 18 | -------------------------------------------------------------------------------- /springboot-elasticsearch/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-elasticsearch/src/main/java/com/springboot/cli/config/RestClientConfig.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.config; 2 | 3 | import org.elasticsearch.client.RestHighLevelClient; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.data.elasticsearch.client.ClientConfiguration; 8 | import org.springframework.data.elasticsearch.client.RestClients; 9 | import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; 10 | 11 | @Configuration 12 | public class RestClientConfig extends AbstractElasticsearchConfiguration { 13 | 14 | @Value("${elasticsearch.url}") 15 | private String url; 16 | 17 | @Override 18 | @Bean 19 | public RestHighLevelClient elasticsearchClient() { 20 | final ClientConfiguration clientConfiguration = ClientConfiguration.builder() 21 | .connectedTo(url) 22 | .build(); 23 | return RestClients.create(clientConfiguration).rest(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot-elasticsearch/src/main/java/com/springboot/cli/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.entity; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | import java.util.Date; 6 | 7 | /** 8 | * 用户表 9 | * 10 | * @author ding 11 | */ 12 | @Data 13 | @Accessors(chain = true) 14 | public class User { 15 | 16 | /** 17 | * 用户id 18 | */ 19 | private Long userId; 20 | 21 | /** 22 | * 用户名 23 | */ 24 | private String username; 25 | 26 | /** 27 | * 用户别称 28 | */ 29 | private String account; 30 | 31 | /** 32 | * 密码 33 | */ 34 | private String password; 35 | 36 | /** 37 | * 创建日期 38 | */ 39 | private Date createdDate; 40 | 41 | } 42 | -------------------------------------------------------------------------------- /springboot-elasticsearch/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | elasticsearch: 2 | url: 192.168.41.128:9200 -------------------------------------------------------------------------------- /springboot-email/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-email/readme.md: -------------------------------------------------------------------------------- 1 | #### 访问 2 | > 浏览器输入 3 | 4 | ``` 5 | http://localhost:9999/send?to=xx@qq.com 6 | ``` 7 | -------------------------------------------------------------------------------- /springboot-email/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-email/src/main/java/com/springboot/cli/config/EMailConfig.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.config; 2 | 3 | import cn.hutool.extra.mail.MailAccount; 4 | import cn.hutool.json.JSONUtil; 5 | import lombok.Data; 6 | import org.springframework.boot.context.properties.ConfigurationProperties; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Data 10 | @Component 11 | @ConfigurationProperties(prefix = EMailConfig.PRE) 12 | public class EMailConfig { 13 | 14 | public final static String PRE = "email"; 15 | 16 | private String host; 17 | private Integer port; 18 | private String from ; 19 | private String pass; 20 | 21 | public MailAccount getAccount() { 22 | MailAccount account = new MailAccount(); 23 | account.setAuth(true); 24 | account.setHost(host); 25 | account.setPort(port); 26 | account.setFrom(from); 27 | account.setUser(from); 28 | account.setPass(pass); 29 | return account; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-email/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | email: 5 | host: smtp.qq.com 6 | from: xx@qq.com 7 | # 密码自行登录邮箱开启获取,操作很简单 8 | pass: xxxxxxxxxxxxx 9 | port: 25 10 | -------------------------------------------------------------------------------- /springboot-email/src/main/resources/templates/emailTemplate.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 激活码 6 | 7 | 8 |

欢迎登录Springboot-cli

9 | 您好,您的激活码为,请在5分钟内使用完成操作。 10 | 11 | -------------------------------------------------------------------------------- /springboot-excel-export/.gitignore: -------------------------------------------------------------------------------- 1 | README.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-excel-export/README.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 3 | 便捷的邮件导出 4 | 5 | 完整功能参考文档:[https://gitee.com/lemur/easypoi](https://gitee.com/lemur/easypoi) 6 | 7 | ### 使用教程 8 | 9 | - 普通导出 10 | 11 | 直接运行 `com.exel.demo.test` 包下的main方法即可测试 12 | 13 | - 浏览器下载 14 | 15 | 运行 `DemoApplication` 启动web项目 16 | 17 | - 浏览器输入 18 | 19 | 1. 普通导出EXCEL:`http://localhost:20000/excel/downloadByTem` 20 | 2. 根据模板导出EXCEL:`http://localhost:20000/excel/download` 21 | 3. 导出Work文档:`http://localhost:20000/word/download` 22 | 23 | 24 | -------------------------------------------------------------------------------- /springboot-excel-export/src/main/java/com/exel/demo/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.exel.demo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author qiding 8 | */ 9 | @SpringBootApplication 10 | public class DemoApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(DemoApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-excel-export/src/main/java/com/exel/demo/entity/Course.java: -------------------------------------------------------------------------------- 1 | package com.exel.demo.entity; 2 | 3 | import cn.afterturn.easypoi.excel.annotation.Excel; 4 | import cn.afterturn.easypoi.excel.annotation.ExcelCollection; 5 | import lombok.Data; 6 | import lombok.experimental.Accessors; 7 | 8 | import java.util.Date; 9 | 10 | 11 | /** 12 | * @author qiding 13 | */ 14 | @Data 15 | @Accessors(chain = true) 16 | public class Course implements java.io.Serializable { 17 | 18 | /** 19 | * 主键 20 | */ 21 | private Integer courseId; 22 | 23 | @Excel(name = "课程名", orderNum = "1", width = 30) 24 | private String courseName; 25 | 26 | @Excel(name = "类型", orderNum = "2", width = 10) 27 | private String courseType; 28 | 29 | @Excel(name = "日期", format = "yyyy-MM-dd", width = 20) 30 | private Date createdDate; 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot-excel-export/src/main/java/com/exel/demo/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.exel.demo.entity; 2 | 3 | import cn.afterturn.easypoi.excel.annotation.Excel; 4 | import cn.afterturn.easypoi.excel.annotation.ExcelCollection; 5 | import lombok.Data; 6 | import lombok.experimental.Accessors; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 手机 12 | * 13 | * @author qiding 14 | */ 15 | @Data 16 | @Accessors(chain = true) 17 | public class User { 18 | /** 19 | * 主键 20 | */ 21 | private Integer userId; 22 | 23 | @Excel(name = "用户名", orderNum = "1", width = 30, needMerge = true) 24 | private String username; 25 | 26 | @Excel(name = "年龄", orderNum = "2", width = 10, needMerge = true) 27 | private Integer age; 28 | 29 | @Excel(name = "性别", orderNum = "3", width = 30, needMerge = true) 30 | private String sex; 31 | 32 | @ExcelCollection(name = "课程", orderNum = "4") 33 | private List courseList; 34 | } 35 | -------------------------------------------------------------------------------- /springboot-excel-export/src/main/java/com/exel/demo/test/Test.java: -------------------------------------------------------------------------------- 1 | package com.exel.demo.test; 2 | 3 | import com.exel.demo.entity.User; 4 | import com.exel.demo.utils.ExelUtils; 5 | import com.exel.demo.utils.MockDataUtils; 6 | import com.exel.demo.utils.WordUtils; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * 本类测试类 12 | * 13 | * @author qiding 14 | */ 15 | public class Test { 16 | 17 | public static void main(String[] args) throws Exception { 18 | // 获取模拟数据 19 | List userListMockData1 = MockDataUtils.getUserListMockData(); 20 | List userListMockData2 = MockDataUtils.getUserListMockData(); 21 | 22 | // 1. 普通导出xlsx 23 | ExelUtils.exportExcel("课程表", "第一页", userListMockData1, User.class, "D://test/基础课程表.xlsx"); 24 | 25 | // 2. 通过模板导出xlsx 26 | ExelUtils.exportExcelByTem(userListMockData2, ExelUtils.XlsxTemplate.USER_COURSE, "D://test/模板课程表.xlsx"); 27 | 28 | // 3. Word文档导出 29 | WordUtils.exportWord(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /springboot-excel-export/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 20000 -------------------------------------------------------------------------------- /springboot-excel-export/src/main/resources/exportTemplate/simple.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangqiding/springboot-cli/8c6927c300602c1afc79cb49a124bbf065d13f25/springboot-excel-export/src/main/resources/exportTemplate/simple.docx -------------------------------------------------------------------------------- /springboot-excel-export/src/main/resources/exportTemplate/user_course_tem.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/liangqiding/springboot-cli/8c6927c300602c1afc79cb49a124bbf065d13f25/springboot-excel-export/src/main/resources/exportTemplate/user_course_tem.xlsx -------------------------------------------------------------------------------- /springboot-excel-export/src/main/resources/exportTemplate/~$simple.docx: -------------------------------------------------------------------------------- 1 | Administrator Administrator -------------------------------------------------------------------------------- /springboot-excel-export/src/test/java/com/exel/demo/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.exel.demo; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-exception/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-exception/readme.md: -------------------------------------------------------------------------------- 1 | #### 访问 2 | > 浏览器输入 3 | 4 | ``` 5 | http://localhost:9999/ 6 | ``` 7 | -------------------------------------------------------------------------------- /springboot-exception/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-exception/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | 4 | import com.springboot.cli.exception.MyException; 5 | import com.springboot.cli.utils.ResponseResult; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author ding 11 | */ 12 | @RestController 13 | public class IndexController { 14 | 15 | @GetMapping("/") 16 | public ResponseResult get() { 17 | return ResponseResult.ok("模拟成功获取数据"); 18 | } 19 | 20 | /** 21 | * 自定义异常捕获 22 | */ 23 | @GetMapping("/err") 24 | public ResponseResult error() { 25 | throw new MyException("模拟异常", 4004); 26 | } 27 | 28 | /** 29 | * 其它异常捕获 30 | */ 31 | @GetMapping("/err2") 32 | public ResponseResult error2() { 33 | int i = 1 / 0; 34 | return ResponseResult.ok("OK"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-exception/src/main/java/com/springboot/cli/exception/MyException.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.exception; 2 | 3 | 4 | import lombok.Data; 5 | import lombok.EqualsAndHashCode; 6 | 7 | /** 8 | * 自定义异常 9 | * 10 | * @author ding 11 | */ 12 | @EqualsAndHashCode(callSuper = true) 13 | @Data 14 | public class MyException extends RuntimeException { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | private String msg; 19 | 20 | private Integer code = 200; 21 | 22 | public MyException(String msg) { 23 | super(msg); 24 | this.msg = msg; 25 | } 26 | 27 | public MyException(String msg, Throwable e) { 28 | super(msg, e); 29 | this.msg = msg; 30 | } 31 | 32 | public MyException(String msg, int code) { 33 | super(msg); 34 | this.msg = msg; 35 | this.code = code; 36 | } 37 | 38 | public MyException(String msg, int code, Throwable e) { 39 | super(msg, e); 40 | this.msg = msg; 41 | this.code = code; 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /springboot-exception/src/main/java/com/springboot/cli/handler/ControllerExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.handler; 2 | 3 | 4 | import com.springboot.cli.exception.MyException; 5 | import com.springboot.cli.utils.ResponseResult; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.*; 8 | 9 | 10 | /** 11 | * 全局异常捕获 12 | * 若用 @RestControllerAdvice 替换 @ControllerAdvice 则可省略 @ResponseBody 13 | * 14 | * @author ding 15 | */ 16 | @ControllerAdvice 17 | @Slf4j 18 | public class ControllerExceptionHandler { 19 | 20 | /** 21 | * 异常处理 22 | */ 23 | @ExceptionHandler(value = Exception.class) 24 | public ResponseResult defaultException(Exception e) { 25 | if (e instanceof NullPointerException){ 26 | log.error("空指针异常:" + e.getMessage(), e); 27 | return ResponseResult.fail("空指针异常"); 28 | } 29 | log.error("未知异常:" + e.getMessage(), e); 30 | return ResponseResult.fail(); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot-exception/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-exception/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-jwt/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-jwt/readme.md: -------------------------------------------------------------------------------- 1 | #### swagger 访问接口 2 | 3 | ``` 4 | http://localhost:10100/swagger-ui/index.html 5 | ``` 6 | 7 | #### spring-boot-starter-parent版本和swagger3 问题 8 | 9 | > spring-boot-starter-parent 不能大于2.5.3 否则swagger3报错 -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/com/springboot/cli/JwtDomeApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JwtDomeApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JwtDomeApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/com/springboot/cli/config/PasswordEncoder.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.config; 2 | 3 | 4 | import org.springframework.util.DigestUtils; 5 | 6 | /** 7 | * 密码加密工具类 8 | * 9 | * @author liangQiDing 10 | */ 11 | public class PasswordEncoder { 12 | 13 | /** 14 | * 密码加密 15 | * 16 | * @param rawPassword 登录时传入的密码 17 | */ 18 | public static String encode(CharSequence rawPassword) { 19 | return DigestUtils.md5DigestAsHex(rawPassword.toString().getBytes()); 20 | } 21 | 22 | /** 23 | * 密码对比 24 | * 25 | * @param rawPassword 登录时传入的密码 26 | * @param encodedPassword 数据库保存的加密过的密码 27 | */ 28 | public static boolean matches(CharSequence rawPassword, String encodedPassword) { 29 | return encodedPassword.equals(DigestUtils.md5DigestAsHex(rawPassword.toString().getBytes())); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/com/springboot/cli/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * 配置拦截器路径 9 | * 10 | * @author lqd 11 | */ 12 | @Configuration 13 | public class WebMvcConfig implements WebMvcConfigurer { 14 | @Override 15 | public void addInterceptors(InterceptorRegistry registry) { 16 | registry.addInterceptor(new AuthInterceptor()) 17 | // 拦截的路径 18 | .addPathPatterns("/**") 19 | // 开放的路径 20 | .excludePathPatterns("/login/**", "/token/validate"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/com/springboot/cli/jwt/JwtUser.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.jwt; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | /** 7 | * @author l 8 | */ 9 | @Data 10 | @Accessors(chain = true) 11 | public class JwtUser { 12 | 13 | private boolean valid; 14 | private String userId; 15 | private String role; 16 | 17 | public JwtUser() { 18 | this.valid = false; 19 | } 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #==========================swagger 访问接口================================== 2 | # http://${ip}:10131/swagger-ui/index.html # 3 | #========================================================================== 4 | server: 5 | port: 20010 6 | spring: 7 | application: 8 | name: jwt_demo 9 | profiles: 10 | active: test 11 | 12 | springfox: 13 | documentation: 14 | swagger-ui: 15 | enabled: true -------------------------------------------------------------------------------- /springboot-jwt/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-kafka/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-kafka/consumer/src/main/java/com/springboot/cli/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConsumerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ConsumerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-kafka/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | kafka: 3 | bootstrap-servers: 192.168.41.128:9092 4 | consumer: 5 | # 默认的消费组ID 6 | group-id: javagroup 7 | # 是否自动提交offset 8 | enable-auto-commit: true 9 | # 提交offset延时(接收到消息后多久提交offset) 10 | auto-commit-interval: 100 11 | # earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费 12 | # latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据 13 | # none:topic各分区都存在已提交的offset时,从offset后开始消费;只要有一个分区不存在已提交的offset,则抛出异常 14 | auto-offset-reset: latest 15 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 16 | value-deserializer: org.apache.kafka.common.serialization.StringDeserializer 17 | 18 | kafka: 19 | # 订阅的主题 20 | topic: test 21 | # 主题消费分组 22 | group: group-test -------------------------------------------------------------------------------- /springboot-kafka/producer/src/main/java/com/springboot/cli/KafkaProducer/KafkaProducer.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.KafkaProducer; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import lombok.RequiredArgsConstructor; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.kafka.core.KafkaTemplate; 7 | import org.springframework.stereotype.Component; 8 | 9 | 10 | @Component 11 | @RequiredArgsConstructor 12 | @Slf4j 13 | public class KafkaProducer { 14 | 15 | private final KafkaTemplate kafkaTemplate; 16 | 17 | /** 18 | * 发送json消息 19 | * 20 | * @param topic 频道 21 | * @param message 消息 22 | */ 23 | public void send(String topic, String message) { 24 | kafkaTemplate.send(topic, message); 25 | log.info("send success"); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-kafka/producer/src/main/java/com/springboot/cli/ProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProducerApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProducerApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-kafka/producer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | kafka: 6 | bootstrap-servers: 192.168.41.128:9092 7 | producer: 8 | # 每次批量发送消息的数量 9 | batch-size: 16 10 | # 缓存容量 11 | buffer-memory: 33554432 12 | #设置大于0的值,则客户端会将发送失败的记录重新发送 13 | retries: 0 14 | # 指定消息key和消息体的编解码方式 UTF-8 15 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 16 | value-serializer: org.apache.kafka.common.serialization.StringSerializer 17 | 18 | -------------------------------------------------------------------------------- /springboot-kafka/readme.md: -------------------------------------------------------------------------------- 1 | ## 基础配置 2 | 3 | - 提供者producer 4 | `yml`中修改`spring.kafka.bootstrap-servers`为你实际的kafka地址 5 | 6 | - 消费者consumer 7 | `yml`中修改`spring.kafka.bootstrap-servers`为你实际的kafka地址 8 | `yml`中修改`kafka.topic`为你实际需要监听的topic 9 | `yml`中修改`kafka.group`为你的消费分组,相同组内的消费者不会重复消费同一条消息,起到负载均衡的作用 10 | 11 | ## 测试接口 12 | 13 | > 基础地址 http://localhost:9999 14 | 15 | ```go 16 | 1. 普通消息 17 | localhost:9999/send?message=hello&topic=test 18 | 19 | 2. 发送json 20 | ```json 21 | Request URL: http://localhost:9999/send 22 | Request Method: POST 23 | Request Headers: 24 | { 25 | "Content-Type":"application/json" 26 | } 27 | Request Body: 28 | { 29 | "topic": "test", 30 | "message": { 31 | "data": "hello" 32 | } 33 | } 34 | ``` -------------------------------------------------------------------------------- /springboot-minio/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-minio/readme.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 3 | 致力于让开发者快速搭建基础环境并让应用跑起来,提供使用示例供使用者参考,让初学者快速上手。 4 | 5 | ## 环境 6 | 7 | - 修改yml中`minio.endpoint`的地址为你实际的地址 8 | - 无需主动创建表,确保`minio`正确安装且连接正常即可 9 | 10 | ## 使用示例 11 | 12 | - 接口请查看 `com.springboot.cli.controller.IndexController.java` 13 | -------------------------------------------------------------------------------- /springboot-minio/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-minio/src/main/resources/META-INF/additional-spring-configuration-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": [ 3 | { 4 | "name": "minio.endpoint", 5 | "type": "java.lang.String", 6 | "description": "endPoint是一个URL,域名,IPv4或者IPv6地址." 7 | }, 8 | { 9 | "name": "minio.accessKey", 10 | "type": "java.lang.String", 11 | "description": "accessKey类似于用户ID,用于唯一标识你的账户." 12 | }, 13 | { 14 | "name": "minio.secretKey", 15 | "type": "java.lang.String", 16 | "description": "secretKey是你账户的密码." 17 | }, 18 | { 19 | "name": "minio.secure", 20 | "type": "java.lang.Boolean", 21 | "description": "如果是true,则用的是https而不是http,默认值是true." 22 | }, 23 | { 24 | "name": "minio.bucketName", 25 | "type": "java.lang.String", 26 | "description": "默认存储桶." 27 | }, 28 | { 29 | "name": "minio.configDir", 30 | "type": "java.lang.String", 31 | "description": "配置目录." 32 | } 33 | ] } -------------------------------------------------------------------------------- /springboot-minio/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | minio: 5 | endpoint: http://192.168.41.128:20000 6 | accessKey: admin 7 | secretKey: 12345678 8 | secure: false 9 | bucketName: test 10 | -------------------------------------------------------------------------------- /springboot-minio/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-mongodb/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-mongodb/readme.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 致力于让开发者快速搭建基础环境并让应用跑起来,提供使用示例供使用者参考,让初学者快速上手。 3 | 4 | ## 环境 5 | 6 | - 修改yml中mongodb的地址为你实际的地址 7 | - 无需主动创建表,确保mongodb正确安装且连接正常即可 8 | 9 | ## 使用示例 10 | 11 | - 打开测试类 12 | 13 | 路径:`src\test\java\com\springboot\cli\MongodbApplicationTests` 14 | 15 | - 运行测试方法 16 | 17 | -------------------------------------------------------------------------------- /springboot-mongodb/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | public class WebApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(WebApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-mongodb/src/main/java/com/springboot/cli/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.entity; 2 | 3 | 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | import org.springframework.data.annotation.Id; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * @author ding 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | public class User implements Serializable { 16 | 17 | private static final long serialVersionUID = 1L; 18 | /** 19 | * 用户id 20 | */ 21 | @Id 22 | private Long userId; 23 | 24 | /** 25 | * 用户名 26 | */ 27 | private String username; 28 | 29 | /** 30 | * 性别 31 | */ 32 | private String sex; 33 | 34 | /** 35 | * 备注 36 | */ 37 | private String remark; 38 | } 39 | -------------------------------------------------------------------------------- /springboot-mongodb/src/main/java/com/springboot/cli/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service; 2 | 3 | import com.springboot.cli.entity.User; 4 | 5 | import java.util.List; 6 | 7 | public interface IUserService { 8 | 9 | /** 10 | * 添加用户 11 | * 12 | * @param user 用户数据 13 | */ 14 | void insertUser(User user); 15 | 16 | /** 17 | * 批量添加用户 18 | * 19 | * @param users 用户数据 20 | */ 21 | void insertUser(List users); 22 | 23 | /** 24 | * 更新用户 25 | * 26 | * @param user 用户数据 27 | */ 28 | void updateUser(User user); 29 | 30 | /** 31 | * 查询用户 32 | * 33 | * @param user 用户数据 34 | * @return list 35 | */ 36 | List listUser(User user); 37 | 38 | /** 39 | * 删除用户 40 | * 41 | * @param userId 用户id 42 | */ 43 | void deleteUser(Long userId); 44 | } 45 | -------------------------------------------------------------------------------- /springboot-mongodb/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | application: 6 | name: springboot-mongodb 7 | data: 8 | mongodb: 9 | uri: mongodb://192.168.41.128:27017/test 10 | 11 | 12 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/README.MD: -------------------------------------------------------------------------------- 1 | #### mybatis_plus 代码生成器 2 | 3 | #### 使用 4 | 5 | 1. 打开GlobalConfigs.java 配置数据库地址及密码 6 | 2. 运行utils包下的 GlobalConfigs 即可 -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/MybatisGenerationApplication.java: -------------------------------------------------------------------------------- 1 | package com.example.mybatis_generation; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MybatisGenerationApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MybatisGenerationApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/controller/JsonDataController.java: -------------------------------------------------------------------------------- 1 | package com.example.mybatis_generation.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | import org.springframework.stereotype.Controller; 7 | 8 | /** 9 | *

10 | * 前端控制器 11 | *

12 | * 13 | * @author qiDing 14 | * @since 2022-03-18 15 | */ 16 | @Controller 17 | @RequestMapping("/jsonData") 18 | public class JsonDataController { 19 | 20 | } 21 | 22 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/dao/JsonDataMapper.java: -------------------------------------------------------------------------------- 1 | package com.example.mybatis_generation.dao; 2 | 3 | import com.example.mybatis_generation.domain.JsonData; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | *

8 | * Mapper 接口 9 | *

10 | * 11 | * @author qiDing 12 | * @since 2022-03-18 13 | */ 14 | public interface JsonDataMapper extends BaseMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/dao/JsonDataMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | id, json_data 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/domain/JsonData.java: -------------------------------------------------------------------------------- 1 | package com.example.mybatis_generation.domain; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | import com.baomidou.mybatisplus.annotation.TableId; 6 | 7 | import java.io.Serializable; 8 | 9 | import lombok.Data; 10 | import lombok.EqualsAndHashCode; 11 | import lombok.experimental.Accessors; 12 | 13 | /** 14 | *

15 | * 16 | *

17 | * 18 | * @author qiDing 19 | * @since 2022-03-18 20 | */ 21 | @Data 22 | @EqualsAndHashCode(callSuper = false) 23 | @Accessors(chain = true) 24 | public class JsonData extends Model { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | @TableId(value = "id", type = IdType.AUTO) 29 | private Integer id; 30 | 31 | private String jsonData; 32 | 33 | 34 | @Override 35 | protected Serializable pkVal() { 36 | return this.id; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/service/IJsonDataService.java: -------------------------------------------------------------------------------- 1 | package com.example.mybatis_generation.service; 2 | 3 | import com.example.mybatis_generation.domain.JsonData; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | *

8 | * 服务类 9 | *

10 | * 11 | * @author qiDing 12 | * @since 2022-03-18 13 | */ 14 | public interface IJsonDataService extends IService { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/java/com/example/mybatis_generation/service/impl/JsonDataServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.example.mybatis_generation.service.impl; 2 | 3 | import com.example.mybatis_generation.domain.JsonData; 4 | import com.example.mybatis_generation.dao.JsonDataMapper; 5 | import com.example.mybatis_generation.service.IJsonDataService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | *

11 | * 服务实现类 12 | *

13 | * 14 | * @author qiDing 15 | * @since 2022-03-18 16 | */ 17 | @Service 18 | public class JsonDataServiceImpl extends ServiceImpl implements IJsonDataService { 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot-mybatis-plus-generator/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #==========================swagger 访问接口================================== 2 | # http://${ip}:10131/swagger-ui/index.html # 3 | #========================================================================== 4 | server: 5 | port: 10100 6 | spring: 7 | main: 8 | # 允许循环嵌套查询 9 | allow-circular-references: true 10 | application: 11 | name: AuthSercurity 12 | profiles: 13 | active: test 14 | 15 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/README.MD: -------------------------------------------------------------------------------- 1 | ## 前置 2 | 3 | - 创建`example`数据库 4 | - 运行`example.sql`导入数据表 5 | - 修改`application.yml`中数据库连接地址及密码 6 | 7 | ##使用 8 | 9 | - 浏览器输入 `localhost:9999/user/list` 10 | - 更多接口请查看 `controller`包 11 | 12 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/com/springboot/cli/MybatisApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MybatisApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MybatisApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/com/springboot/cli/controller/AreaController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | 4 | import com.springboot.cli.domain.Area; 5 | import com.springboot.cli.service.IAreaService; 6 | import lombok.RequiredArgsConstructor; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | 10 | import org.springframework.stereotype.Controller; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | *

17 | * 前端控制器 18 | *

19 | * 20 | * @author ding 21 | * @since 2022-04-28 22 | */ 23 | @RequiredArgsConstructor 24 | @RestController 25 | @RequestMapping("area") 26 | public class AreaController { 27 | 28 | private final IAreaService iAreaService; 29 | 30 | /** 31 | * 树形递归查询地区信息 32 | */ 33 | @GetMapping("list") 34 | public List list(Integer parentId) { 35 | return iAreaService.listChildrenTree(parentId); 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/com/springboot/cli/dao/AreaMapper.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.dao; 2 | 3 | import com.springboot.cli.domain.Area; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | *

12 | * Mapper 接口 13 | *

14 | * 15 | * @author ding 16 | */ 17 | @Mapper 18 | public interface AreaMapper extends BaseMapper { 19 | 20 | /** 21 | * 查询地区树形 22 | * 23 | * @param parentId 父节点id 24 | * @return tree 25 | */ 26 | List listChildrenTree(Integer parentId); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/com/springboot/cli/dao/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.dao; 2 | 3 | import com.springboot.cli.domain.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | 8 | import java.util.HashMap; 9 | import java.util.List; 10 | 11 | /** 12 | *

13 | * Mapper 接口 14 | *

15 | * 16 | * @author qiDing 17 | * @since 2022-04-11 18 | */ 19 | @Mapper 20 | public interface UserMapper extends BaseMapper { 21 | 22 | /** 23 | * 关联查询 24 | * 25 | * @param userId 用户id(可为空) 26 | * @param account 账号(可为空) 27 | * @return List 28 | */ 29 | List> listUserAndArea(@Param("userId") Long userId, @Param("account") String account); 30 | } 31 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/com/springboot/cli/service/IAreaService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service; 2 | 3 | import com.springboot.cli.domain.Area; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | *

10 | * 服务类 11 | *

12 | * 13 | * @author ding 14 | * @since 2022-04-28 15 | */ 16 | public interface IAreaService extends IService { 17 | 18 | /** 19 | * 查询地区树形 20 | * 21 | * @param parentId 父节点id 22 | * @return tree 23 | */ 24 | List listChildrenTree(Integer parentId); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/com/springboot/cli/service/impl/AreaServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service.impl; 2 | 3 | import com.springboot.cli.domain.Area; 4 | import com.springboot.cli.dao.AreaMapper; 5 | import com.springboot.cli.service.IAreaService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import lombok.RequiredArgsConstructor; 8 | import org.springframework.stereotype.Service; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | *

14 | * 服务实现类 15 | *

16 | * 17 | * @author ding 18 | * @since 2022-04-28 19 | */ 20 | @Service 21 | @RequiredArgsConstructor 22 | public class AreaServiceImpl extends ServiceImpl implements IAreaService { 23 | 24 | private final AreaMapper areaMapper; 25 | 26 | @Override 27 | public List listChildrenTree(Integer parentId) { 28 | return areaMapper.listChildrenTree(parentId); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/test/java/com/springboot/cli/MybatisGenerationApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.springboot.cli.dao.AreaMapper; 5 | import com.springboot.cli.dao.UserMapper; 6 | import com.springboot.cli.domain.Area; 7 | import com.springboot.cli.domain.User; 8 | import com.springboot.cli.service.IUserService; 9 | import lombok.RequiredArgsConstructor; 10 | import org.junit.jupiter.api.Test; 11 | import org.springframework.boot.test.context.SpringBootTest; 12 | 13 | import javax.annotation.Resource; 14 | import java.util.List; 15 | 16 | @SpringBootTest 17 | class MybatisGenerationApplicationTests { 18 | 19 | @Resource 20 | private AreaMapper areaMapper; 21 | 22 | @Resource 23 | private IUserService userService; 24 | 25 | @Test 26 | void listChildrenTree() { 27 | List areas = areaMapper.listChildrenTree(1); 28 | System.out.println(JSON.toJSONString(areas)); 29 | } 30 | 31 | @Test 32 | void listUser() { 33 | List users = userService.listUser(new User()); 34 | System.out.println(JSON.toJSONString(users)); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springboot-rabbitMQ 7 | com.springboot 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | common 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springboot-rabbitMQ 7 | com.springboot 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | consumer 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | 21 | com.springboot 22 | common 23 | 0.0.1-SNAPSHOT 24 | 25 | 26 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/consumer/src/main/java/com/springboot/cli/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class ConsumerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ConsumerApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/consumer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: rabbitmq-consumer 4 | rabbitmq: 5 | host: 192.168.41.128 6 | port: 5672 7 | username: guest 8 | password: guest 9 | virtualHost: / 10 | # 手动提交ack消息 11 | listener: 12 | simple: 13 | acknowledge-mode: manual 14 | direct: 15 | acknowledge-mode: manual 16 | 17 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/producer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springboot-rabbitMQ 7 | com.springboot 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | producer 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | com.springboot 26 | common 27 | 0.0.1-SNAPSHOT 28 | 29 | 30 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/producer/src/main/java/com/springboot/cli/ProducerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class ProducerApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ProducerApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/producer/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: rabbitmq-producer 4 | rabbitmq: 5 | host: 192.168.41.128 6 | port: 5672 7 | username: guest 8 | password: guest 9 | virtualHost: / 10 | # 手动提交ack消息 11 | listener: 12 | simple: 13 | acknowledge-mode: manual 14 | direct: 15 | acknowledge-mode: manual 16 | -------------------------------------------------------------------------------- /springboot-rabbitMQ/producer/src/test/java/com/springboot/cli/ProducerTest.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import com.springboot.cli.producer.RabbitProducer; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.boot.test.context.SpringBootTest; 8 | 9 | @SpringBootTest 10 | @Slf4j 11 | public class ProducerTest { 12 | 13 | @Autowired 14 | RabbitProducer rabbitProducer; 15 | 16 | @Test 17 | void sendDirect() { 18 | rabbitProducer.sendDirect("直通消息9527!"); 19 | } 20 | 21 | @Test 22 | void sendFanout() { 23 | rabbitProducer.sendFanout("分裂消息6666!"); 24 | } 25 | 26 | @Test 27 | void sendAndExpire() { 28 | rabbitProducer.sendAndExpire("晚上10点老地方不见不散!该消息有效期10秒"); 29 | } 30 | 31 | @Test 32 | void sendDelay() { 33 | rabbitProducer.sendDelay("有内鬼,终止交易~~", 5000); 34 | } 35 | 36 | 37 | @Test 38 | void sendTopic() { 39 | rabbitProducer.sendTopic("放学别走!", "test123.topic.test456"); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /springboot-redis/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-redis/readme.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | 3 | Redis中文配置文档:https://ppg007.github.io/redis/ 4 | 5 | #### 接口 6 | 7 | ```go 8 | # 自动缓存 9 | http://localhost:9999/getUser 10 | # 删除 11 | http://localhost:9999/delUser 12 | # 手动设置缓存 13 | http://localhost:9999/set 14 | # 手动获取缓存 15 | http://localhost:9999/get 16 | ``` 17 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | 9 | @SpringBootApplication 10 | @Slf4j 11 | public class WebApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(WebApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/springboot/cli/config/SessionConfig.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 5 | 6 | /** 7 | * 开始共享session实现,不需要可以删除此类 8 | */ 9 | @Configuration 10 | @EnableRedisHttpSession(maxInactiveIntervalInSeconds = 86400 * 30) 11 | public class SessionConfig { 12 | 13 | } -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/springboot/cli/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.entity; 2 | 3 | 4 | import lombok.Data; 5 | import lombok.experimental.Accessors; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author ding 10 | */ 11 | @Data 12 | @Accessors(chain = true) 13 | public class User implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | /** 17 | * 用户id 18 | */ 19 | private Long userId; 20 | 21 | /** 22 | * 用户名 23 | */ 24 | private String username; 25 | 26 | /** 27 | * 性别 28 | */ 29 | private String sex; 30 | 31 | /** 32 | * 备注 33 | */ 34 | private String remark; 35 | } 36 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/com/springboot/cli/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service; 2 | 3 | import com.springboot.cli.entity.User; 4 | 5 | public interface IUserService { 6 | 7 | /** 8 | * 缓存测试 9 | * 10 | * @param id 用户id 随便输入 11 | * @return 用户数据 12 | */ 13 | User getUser(Long id); 14 | 15 | /** 16 | * 删除缓存测试 17 | * 18 | * @param id 用户id 随便输入 19 | */ 20 | void delUser(Long id); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | # redis 配置 6 | redis: 7 | database: 0 8 | host: 192.168.41.128 9 | port: 6379 10 | #连接超时时间 11 | timeout: 3000 12 | password: 123456 13 | #连接池配置 14 | lettuce: 15 | pool: 16 | max-active: 8 17 | max-idle: 8 18 | min-idle: 0 19 | max-wait: -1 -------------------------------------------------------------------------------- /springboot-redis/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-redisson/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-redisson/readme.md: -------------------------------------------------------------------------------- 1 | ## 使用 2 | 3 | -------------------------------------------------------------------------------- /springboot-redisson/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | 9 | @SpringBootApplication 10 | @Slf4j 11 | public class WebApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(WebApplication.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-redisson/src/main/java/com/springboot/cli/config/RedissonProperties.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.config; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | import org.springframework.boot.context.properties.ConfigurationProperties; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * redisson yml配置 10 | * 11 | * @author : qiDing 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | @Configuration 16 | @ConfigurationProperties(prefix = RedissonProperties.PREFIX) 17 | public class RedissonProperties { 18 | 19 | public static final String PREFIX = "redisson"; 20 | /** 21 | * 连接超时,单位:毫秒 22 | */ 23 | private Integer connectTimeout; 24 | 25 | /** 26 | * 密码 27 | */ 28 | private String password; 29 | 30 | /** 31 | * 服务器地址 32 | */ 33 | private String[] address; 34 | 35 | /** 36 | * 数据库序号,只有单机模式下生效 37 | */ 38 | private Integer database; 39 | 40 | /** 41 | * 传输模式 linux上开启会有更高的性能 42 | */ 43 | private Boolean useEpoll; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /springboot-redisson/src/main/java/com/springboot/cli/domain/Product.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * 用户表 10 | * 11 | * @author ding 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | public class Product { 16 | 17 | /** 18 | * 产品id 19 | */ 20 | private Long productId; 21 | 22 | /** 23 | * 用户名 24 | */ 25 | private String productName; 26 | 27 | /** 28 | * 创建日期 29 | */ 30 | private Date createdDate; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /springboot-redisson/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | # redis 配置 5 | redisson: 6 | # 是否集群 7 | cluster: false 8 | # 数组格式,参考,若开启集群模式,最少配置3个节点 192.168.41.128:6379 9 | address: 10 | - redis://192.168.41.128:6379 11 | # 连接超时时间 12 | connect-timeout: 3 13 | # 密码 14 | password: 123456 15 | # redis数据库序号,只有单机模式下生效 16 | database: 0 17 | # 传输模式 linux上开启会有更高的性能 18 | use-epoll: false -------------------------------------------------------------------------------- /springboot-scheduler/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-scheduler/readme.md: -------------------------------------------------------------------------------- 1 | ## 定时任务封装 2 | 本例中已对定时器做了封装,具体请查看接口`ScheduleService.java`及`ScheduleRunner.java`,这样做的好处就是 3 | - 统一执行定时任务 4 | - 代码整洁好管理 5 | - 统一线程池管理,减轻我们系统的开销 6 | 7 | ## 使用 8 | 在我们需要使用定时任务时,只要重写`ScheduleService.java`接口就可以啦 9 | - 如每秒执行使用示例 10 | ```java 11 | @Component 12 | @Slf4j 13 | public class Test1TaskImpl implements ScheduleService { 14 | 15 | @Override 16 | public void everySecond() { 17 | log.info("(每秒)定时任务执行了"); 18 | } 19 | 20 | } 21 | ``` 22 | - 当我们需要添加更多自定义定时任务时(如:每分钟) 23 | 只需要在`ScheduleService.java`中添加方法 24 | 25 | ```java 26 | /** 27 | * 每分钟 28 | */ 29 | default void everyMinute(){} 30 | 31 | ``` 32 | 然后在`ScheduleRunner.java`中添加执行逻辑 33 | ```java 34 | /** 35 | * 每分钟 36 | */ 37 | @Scheduled(cron = "0 */1 * * * ?") 38 | public void everyMinute() { 39 | scheduleServiceList.forEach(ScheduleService::everyMinute); 40 | } 41 | ``` 42 | 最后我们编写实现类`Test2TaskImpl.java` 43 | ```java 44 | @Component 45 | @Slf4j 46 | public class Test2TaskImpl implements ScheduleService { 47 | 48 | @Override 49 | public void everyMinute() { 50 | log.info("(每分钟)定时任务执行了"); 51 | } 52 | 53 | } 54 | ``` 55 | - 更多示例请看源码 -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/SchedulerApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.scheduling.annotation.EnableScheduling; 7 | 8 | /** 9 | * @author ding 10 | */ 11 | @SpringBootApplication 12 | @Slf4j 13 | @EnableScheduling 14 | public class SchedulerApplication { 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(SchedulerApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/scheduler/ScheduleService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.scheduler; 2 | 3 | /** 4 | * 定时任务 5 | * 6 | * @author qiding 7 | */ 8 | public interface ScheduleService { 9 | 10 | /** 11 | * 每秒 12 | */ 13 | default void everySecond(){} 14 | 15 | /** 16 | * 每分钟 17 | */ 18 | default void everyMinute(){} 19 | 20 | /** 21 | * 每五分钟 22 | */ 23 | default void everyFiveMinute(){} 24 | 25 | /** 26 | * 每小时 27 | */ 28 | default void everyHour(){} 29 | 30 | /** 31 | * 每天上午8点 32 | */ 33 | default void everyDayEightClock(){} 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/scheduler/task/Test1TaskImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.scheduler.task; 2 | 3 | import com.springboot.cli.scheduler.ScheduleService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | 8 | /** 9 | * 执行示例 10 | * 11 | * @author ding 12 | */ 13 | @Component 14 | @Slf4j 15 | public class Test1TaskImpl implements ScheduleService { 16 | 17 | @Override 18 | public void everySecond() { 19 | log.info("(每秒)定时任务执行了"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/scheduler/task/Test2TaskImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.scheduler.task; 2 | 3 | import com.springboot.cli.scheduler.ScheduleService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | 8 | /** 9 | * 10 | * 执行示例 11 | * 12 | * @author ding 13 | */ 14 | @Component 15 | @Slf4j 16 | public class Test2TaskImpl implements ScheduleService { 17 | 18 | @Override 19 | public void everyMinute() { 20 | log.info("(每分钟)定时任务执行了"); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/scheduler/task/Test3TaskImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.scheduler.task; 2 | 3 | import com.springboot.cli.scheduler.ScheduleService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | 8 | /** 9 | * 执行示例 10 | * 11 | * @author ding 12 | */ 13 | @Component 14 | @Slf4j 15 | public class Test3TaskImpl implements ScheduleService { 16 | 17 | @Override 18 | public void everyFiveMinute() { 19 | log.info("(每5分钟)定时任务执行了"); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/scheduler/task/Test4TaskImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.scheduler.task; 2 | 3 | import com.springboot.cli.scheduler.ScheduleService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | 8 | /** 9 | * 执行示例 10 | * 11 | * @author qiding 12 | */ 13 | @Component 14 | @Slf4j 15 | public class Test4TaskImpl implements ScheduleService { 16 | 17 | @Override 18 | public void everyHour() { 19 | log.info("(每小时)定时任务执行了"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/java/com/springboot/cli/scheduler/task/Test5TaskImpl.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.scheduler.task; 2 | 3 | import com.springboot.cli.scheduler.ScheduleService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * 执行示例 9 | * 10 | * @author ding 11 | */ 12 | @Component 13 | @Slf4j 14 | public class Test5TaskImpl implements ScheduleService { 15 | 16 | @Override 17 | public void everyDayEightClock() { 18 | log.info("(每天早上8点)定时任务执行了"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-scheduler/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-scheduler/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-security-captcha/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-security-captcha/readme.md: -------------------------------------------------------------------------------- 1 | ## 使用示例 2 | 3 | 4 | - 浏览器输入`http://192.168.0.54:9999/get` 5 | - 账号密码 admin 123456 6 | 7 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/java/com/springboot/cli/domain/MyUser.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data 7 | @Accessors(chain = true) 8 | public class MyUser { 9 | 10 | /** 11 | * id 12 | */ 13 | private Long userId; 14 | 15 | /** 16 | * 账号 17 | */ 18 | private String username; 19 | 20 | /** 21 | * 密码 22 | */ 23 | private String password; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/java/com/springboot/cli/exception/CaptchaInvalidException.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.exception; 2 | 3 | import org.springframework.security.core.AuthenticationException; 4 | 5 | /** 6 | * 验证码错误异常 7 | * 8 | * @author ding 9 | */ 10 | public class CaptchaInvalidException extends AuthenticationException { 11 | 12 | public CaptchaInvalidException(String msg, Throwable cause) { 13 | super(msg, cause); 14 | } 15 | 16 | public CaptchaInvalidException(String msg) { 17 | super(msg); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/java/com/springboot/cli/security/hander/LoginSuccess.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.security.hander; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; 7 | import org.springframework.stereotype.Component; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | /** 13 | * 登录成功 14 | * 15 | * @author ding 16 | */ 17 | @Component 18 | @Slf4j 19 | public class LoginSuccess extends SavedRequestAwareAuthenticationSuccessHandler { 20 | 21 | @Override 22 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { 23 | log.info("登录认证成功"); 24 | // 这里写你登录成功后的逻辑,可以验证其他信息。 25 | // 重定向 26 | this.getRedirectStrategy().sendRedirect(request, response, "/toIndex"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/java/com/springboot/cli/utils/RequestUtils.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.utils; 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.HttpSession; 8 | 9 | 10 | /** 11 | * 请求工具类 12 | * 13 | * @author ding 14 | */ 15 | public class RequestUtils { 16 | 17 | /** 18 | * 获取session 19 | */ 20 | public static HttpSession getHttpSession() { 21 | return getHttpRequest().getSession(); 22 | } 23 | 24 | /** 25 | * 获取request 26 | */ 27 | public static HttpServletRequest getHttpRequest() { 28 | ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); 29 | assert servletRequestAttributes != null; 30 | return servletRequestAttributes.getRequest(); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | thymeleaf: 6 | # 关闭页面缓存,便于开发环境测试 7 | cache: false 8 | # 静态资源路径 9 | prefix: classpath:/templates/ 10 | # 网页资源默认.html结尾 11 | mode: HTML 12 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 首页 6 | 7 | 8 |

首页

9 |

10 |
11 | 退出登录 12 |
13 | 14 | -------------------------------------------------------------------------------- /springboot-security-captcha/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-security-jwt/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | /html/.idea 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-security-jwt/html/readme.md: -------------------------------------------------------------------------------- 1 | ## 用法 2 | - 直接双击`index.html`选择浏览器打开即可 -------------------------------------------------------------------------------- /springboot-security-jwt/readme.md: -------------------------------------------------------------------------------- 1 | ## 使用示例 2 | 3 | #### 1. 服务端 4 | 5 | - 运行启动类启动服务器 6 | 7 | #### 2. web端 8 | 9 | - 进入html目录 10 | - 在文件中双击`index.html`选择浏览器打开 11 | - 账号密码 admin 123456 12 | 13 | ## API 14 | 15 | - 登录 16 | 17 | ```json 18 | method: post 19 | url: /login 20 | # 请求参数 21 | # params(可选) 22 | "params": 23 | { 24 | "username":"admin", 25 | "password":"123456" 26 | } 27 | # body(可选) 28 | "form-data": 29 | { 30 | "username":"admin", 31 | "password":"123456" 32 | } 33 | ``` 34 | 35 | - 获取用户信息 36 | 37 | ```json 38 | method: get 39 | url: /info 40 | # 请求头 41 | headers:{ 42 | "token":"xxxxx" 43 | } 44 | ``` 45 | 46 | - 退出登录 47 | 48 | ```json 49 | method: get 50 | url: /logout 51 | # 请求头 52 | headers:{ 53 | "token":"xxxxx" 54 | } 55 | ``` 56 | 57 | 58 | 59 | - 测试接口 60 | 61 | ```json 62 | method: test 63 | url: /info 64 | # 请求头 65 | headers:{ 66 | "token":"xxxxx" 67 | } 68 | ``` 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /springboot-security-jwt/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-security-jwt/src/main/java/com/springboot/cli/domain/MyUser.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * 模拟数据库实体,实际环境中应该: 1用户---->n角色---->n权限 10 | * 11 | * @author ding 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | public class MyUser { 16 | 17 | /** 18 | * id 19 | */ 20 | private Long userId; 21 | 22 | /** 23 | * 账号 24 | */ 25 | private String username; 26 | 27 | /** 28 | * 密码 29 | */ 30 | private String password; 31 | 32 | 33 | /** 34 | * 角色 35 | */ 36 | private List roles; 37 | 38 | /** 39 | * 权限 40 | */ 41 | private List auths; 42 | 43 | } 44 | -------------------------------------------------------------------------------- /springboot-security-jwt/src/main/java/com/springboot/cli/security/hander/LogoutSuccess.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.security.hander; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.springboot.cli.utils.ResponseResult; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.security.core.Authentication; 7 | import org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler; 8 | import org.springframework.stereotype.Component; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | 13 | 14 | /** 15 | * 退出登录 16 | * 17 | * @author DING 18 | */ 19 | @Slf4j 20 | @Component 21 | public class LogoutSuccess extends SimpleUrlLogoutSuccessHandler { 22 | 23 | @Override 24 | public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { 25 | response.setContentType("application/json;charset=UTF-8"); 26 | response.getWriter().write(JSONObject.toJSONString(ResponseResult.ok().setMessage("退出登录成功!"))); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-security-jwt/src/main/java/com/springboot/cli/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service; 2 | 3 | import com.springboot.cli.domain.MyUser; 4 | 5 | public interface UserService { 6 | 7 | /** 8 | * 获取用户 9 | * 10 | * @param username 账号 11 | * @return user 12 | */ 13 | MyUser getUser(String username); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-security-jwt/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | jwt: 5 | # 密钥 6 | secret: xxxxx.xxxx.xxxx 7 | # 有效期(秒) 8 | expire: 86400 9 | -------------------------------------------------------------------------------- /springboot-security-jwt/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/readme.md: -------------------------------------------------------------------------------- 1 | ## 使用示例 2 | 3 | 4 | - 浏览器输入`http://192.168.0.54:9999/get` 5 | - 账号密码 admin 123456 6 | 7 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | import com.springboot.cli.security.AuthUser; 4 | import com.springboot.cli.utils.SecurityUtils; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.ui.Model; 8 | import org.springframework.web.bind.annotation.GetMapping; 9 | import org.springframework.web.bind.annotation.PostMapping; 10 | 11 | /** 12 | * @author ding 13 | */ 14 | @Controller 15 | @Slf4j 16 | public class IndexController { 17 | 18 | @GetMapping("/") 19 | public String index() { 20 | return "index"; 21 | } 22 | 23 | @GetMapping("/toIndex") 24 | public String index(Model model) { 25 | AuthUser user = SecurityUtils.getUser(); 26 | log.info("当前用户为:{}", user); 27 | model.addAttribute("user", user); 28 | return "index"; 29 | } 30 | 31 | @GetMapping("/toLogin") 32 | public String login() { 33 | return "login"; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/java/com/springboot/cli/domain/MyUser.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data 7 | @Accessors(chain = true) 8 | public class MyUser { 9 | 10 | /** 11 | * id 12 | */ 13 | private Long userId; 14 | 15 | /** 16 | * 账号 17 | */ 18 | private String username; 19 | 20 | /** 21 | * 密码 22 | */ 23 | private String password; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/java/com/springboot/cli/security/hander/LoginSuccess.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.security.hander; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.security.core.Authentication; 6 | import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; 7 | import org.springframework.stereotype.Component; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | import java.io.IOException; 11 | 12 | /** 13 | * 登录成功 14 | * 15 | * @author ding 16 | */ 17 | @Component 18 | @Slf4j 19 | public class LoginSuccess extends SavedRequestAwareAuthenticationSuccessHandler { 20 | 21 | @Override 22 | public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException { 23 | log.info("登录认证成功"); 24 | // 这里写你登录成功后的逻辑,可以验证其他信息。 25 | // 重定向 26 | this.getRedirectStrategy().sendRedirect(request, response, "/toIndex"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | spring: 5 | thymeleaf: 6 | # 关闭页面缓存,便于开发环境测试 7 | cache: false 8 | # 静态资源路径 9 | prefix: classpath:/templates/ 10 | # 网页资源默认.html结尾 11 | mode: HTML 12 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 首页 6 | 7 | 8 |

首页

9 |

10 |
11 | 退出登录 12 |
13 | 14 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登陆页 6 | 7 | 8 |
9 |
10 |

登陆页

11 |
账号:admin,密码:123456
12 | 13 | 14 | 15 |
16 | 账号或密码错误. 17 |
18 |
19 | 登录失效. 20 |
21 |
22 |
23 | 24 | -------------------------------------------------------------------------------- /springboot-security-thymeleaf/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-security/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-security/readme.md: -------------------------------------------------------------------------------- 1 | ## 使用示例 2 | 3 | 4 | - 浏览器输入`http://192.168.0.54:9999/get` 5 | - 账号密码 admin 123456 6 | 7 | -------------------------------------------------------------------------------- /springboot-security/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-security/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | 8 | /** 9 | * @author ding 10 | */ 11 | @RestController 12 | @Slf4j 13 | public class IndexController { 14 | 15 | @GetMapping("/") 16 | public String index() { 17 | return "请求成功"; 18 | } 19 | 20 | @GetMapping("/get") 21 | public String get() { 22 | return "神秘代码9527"; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-security/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | -------------------------------------------------------------------------------- /springboot-security/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/readme.md: -------------------------------------------------------------------------------- 1 | #### 访问 2 | 3 | - 建议使用api测试工具测试,如`postman` 4 | - 登录接口`/login` 5 | - 账号密码 admin,123456 6 | 7 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/com/springboot/cli/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | @Data 7 | @Accessors(chain = true) 8 | public class User { 9 | 10 | /** 11 | * id 12 | */ 13 | private Long userId; 14 | 15 | /** 16 | * 账号 17 | */ 18 | private String username; 19 | 20 | /** 21 | * 密码 22 | */ 23 | private String password; 24 | } 25 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/com/springboot/cli/shiro/ShiroDefaultSubjectFactory.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.shiro; 2 | 3 | import org.apache.shiro.mgt.DefaultSubjectFactory; 4 | import org.apache.shiro.subject.Subject; 5 | import org.apache.shiro.subject.SubjectContext; 6 | 7 | /** 8 | * 不创建shiro内部的session 9 | * @author ding 10 | */ 11 | public class ShiroDefaultSubjectFactory extends DefaultSubjectFactory { 12 | 13 | @Override 14 | public Subject createSubject(SubjectContext context) { 15 | // 不创建shiro内部的session 16 | context.setSessionCreationEnabled(false); 17 | return super.createSubject(context); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/com/springboot/cli/shiro/jwt/JwtToken.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.shiro.jwt; 2 | 3 | 4 | import org.apache.shiro.authc.AuthenticationToken; 5 | 6 | 7 | /** 8 | * 9 | * 自定义shiro的token 10 | * 11 | * @author ding 12 | */ 13 | public class JwtToken implements AuthenticationToken { 14 | 15 | private final String token; 16 | 17 | public JwtToken(String token) { 18 | this.token = token; 19 | } 20 | 21 | @Override 22 | public Object getPrincipal() { 23 | return token; 24 | } 25 | 26 | @Override 27 | public Object getCredentials() { 28 | return token; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | 4 | jwt: 5 | # 密钥 6 | secret: xxxxx.xxxx.xxxx 7 | # 有效期(秒) 8 | expire: 86400 9 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-shiro/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-shiro/readme.md: -------------------------------------------------------------------------------- 1 | #### 访问 2 | > 浏览器输入 3 | > 账号密码 admin,123456 4 | ``` 5 | http://localhost:9999/ 6 | ``` 7 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/springboot/cli/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | /** 7 | * 用户表 8 | * 9 | * @author ding 10 | */ 11 | @Data 12 | @Accessors(chain = true) 13 | public class User { 14 | 15 | /** 16 | * 用户id 17 | */ 18 | private Long userId; 19 | 20 | /** 21 | * 用户名 22 | */ 23 | private String username; 24 | 25 | /** 26 | * 密码 27 | */ 28 | private String password; 29 | 30 | /** 31 | * 用户别称 32 | */ 33 | private String name; 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/com/springboot/cli/utils/ShiroUtils.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.utils; 2 | 3 | import org.apache.shiro.SecurityUtils; 4 | import org.apache.shiro.session.Session; 5 | import org.apache.shiro.subject.Subject; 6 | 7 | /** 8 | * shiro 工具类 9 | * 用于快速获取登录信息 10 | * 11 | * @author ding 12 | */ 13 | public class ShiroUtils { 14 | 15 | /** 16 | * 获取登录信息 17 | */ 18 | public static Subject getSubject() { 19 | return SecurityUtils.getSubject(); 20 | } 21 | 22 | /** 23 | * 获取登录信息 24 | */ 25 | public static Session getSession() { 26 | return SecurityUtils.getSubject().getSession(); 27 | } 28 | 29 | /** 30 | * 退出登录 31 | */ 32 | public static void logout() { 33 | getSubject().logout(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | servlet: 4 | session: 5 | # 让Tomcat只能从COOKIE中获取会话信息,这样,当没有Cookie时,URL也就不会被自动添加上 ;jsessionid=… 了。 6 | tracking-modes: COOKIE 7 | 8 | spring: 9 | thymeleaf: 10 | # 关闭页面缓存,便于开发环境测试 11 | cache: false 12 | # 静态资源路径 13 | prefix: classpath:/templates/ 14 | # 网页资源默认.html结尾 15 | mode: HTML -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Title 7 | 8 | 9 |

首页

10 | 11 | 12 |

用户已登录

退出登录 13 |
14 | 15 |

用户未登录

   16 |
17 |
18 | 用户信息 19 | table 20 | 21 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登陆页 6 | 7 | 8 |
9 |

10 |
11 |

登陆页

12 |
账号:admin,密码:123456
13 | 14 | 15 | 16 |
17 |
18 | 19 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/table.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | table 6 | 7 | 8 |

table

9 | 10 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/unAuth.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | table2 6 | 7 | 8 |

权限不足

9 | 10 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/userInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | table1 6 | 7 | 8 |

用户信息

9 | 10 | 用户名: 11 |
12 | 用户完整信息: 13 | 14 | -------------------------------------------------------------------------------- /springboot-shiro/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-swagger/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-swagger/readme.md: -------------------------------------------------------------------------------- 1 | ## 注意 2 | 3 | spring-boot-starter-parent 不能大于2.5.3 否则swagger3报错 4 | #### 访问 5 | > swagger界面地址 6 | 7 | ``` 8 | http://192.168.0.54:9999/swagger-ui/index.html#/ 9 | ``` 10 | -------------------------------------------------------------------------------- /springboot-swagger/src/main/java/com/springboot/cli/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.entity; 2 | 3 | import io.swagger.annotations.ApiModel; 4 | import io.swagger.annotations.ApiModelProperty; 5 | import lombok.Data; 6 | import lombok.experimental.Accessors; 7 | 8 | /** 9 | * @author ding 10 | */ 11 | @Data 12 | @Accessors(chain = true) 13 | @ApiModel("用户信息表") 14 | public class User { 15 | 16 | @ApiModelProperty("用户id") 17 | private Long userId; 18 | 19 | @ApiModelProperty("用户名") 20 | private String username; 21 | 22 | @ApiModelProperty("用户性别") 23 | private String sex; 24 | } 25 | -------------------------------------------------------------------------------- /springboot-swagger/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-swagger/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-thymeleaf/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-thymeleaf/readme.md: -------------------------------------------------------------------------------- 1 | ## 简介 2 | thymeleaf参考中文文档: `https://www.docs4dev.com/docs/zh/thymeleaf/3.0/reference/using_thymeleaf.html` 3 | #### 访问 4 | > 浏览器输入 5 | ``` 6 | http://localhost:9999/ 7 | ``` 8 | > 账号密码 admin,123456 9 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/com/springboot/cli/domain/User.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.domain; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | 6 | import java.util.Date; 7 | 8 | /** 9 | * 用户表 10 | * 11 | * @author ding 12 | */ 13 | @Data 14 | @Accessors(chain = true) 15 | public class User { 16 | 17 | /** 18 | * 用户id 19 | */ 20 | private Long userId; 21 | 22 | /** 23 | * 用户名 24 | */ 25 | private String username; 26 | 27 | /** 28 | * 密码 29 | */ 30 | private String password; 31 | 32 | /** 33 | * 用户别称 34 | */ 35 | private String name; 36 | 37 | /** 38 | * 角色 39 | */ 40 | private String role; 41 | 42 | /** 43 | * 是否启用 44 | */ 45 | private Boolean enable; 46 | 47 | /** 48 | * 创建日期 49 | */ 50 | private Date createdDate; 51 | 52 | } 53 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/com/springboot/cli/service/IUserService.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.service; 2 | 3 | import com.springboot.cli.domain.User; 4 | 5 | import javax.servlet.http.HttpSession; 6 | import java.util.List; 7 | 8 | public interface IUserService { 9 | 10 | /** 11 | * 模拟登录 12 | * 13 | * @param username 用户名 14 | * @param password 密码 15 | * @param session 会话 16 | * @return true 17 | */ 18 | boolean login(String username, String password, HttpSession session); 19 | 20 | /** 21 | * 模拟用户信息获取 22 | * 23 | * @return 用户信息 24 | */ 25 | User getUser(); 26 | 27 | /** 28 | * 模拟10个用户信息 29 | * 30 | * @return 用户信息数组 31 | */ 32 | List listUser(); 33 | } 34 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | servlet: 4 | session: 5 | # 让Tomcat只能从COOKIE中获取会话信息,这样,当没有Cookie时,URL也就不会被自动添加上 ;jsessionid=… 了。 6 | tracking-modes: COOKIE 7 | 8 | 9 | spring: 10 | thymeleaf: 11 | # 关闭页面缓存,便于开发环境测试 12 | cache: false 13 | # 静态资源路径 14 | prefix: classpath:/templates/ 15 | # 网页资源默认.html结尾 16 | mode: HTML -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

首页

9 | 退出登录 10 |
11 |
12 |
13 | 全部用户信息 14 | 15 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登陆页 6 | 7 | 8 |
9 |

10 |
11 |

登陆页

12 |
账号:admin,密码:123456
13 | 14 | 15 | 16 |
17 |
18 | 19 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/userInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | table1 7 | 8 | 9 |

全部用户信息

10 | 11 |
12 | 13 |
14 |

管理员

15 |

普通用户

16 |
17 |
18 |
19 | 请先登录 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
用户id名称是否启用创建日期
////
37 | 38 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/test/java/com/springboot/cli/JwtDomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class JwtDomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-upload/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-upload/src/main/java/com/springboot/cli/MLinksFileApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MLinksFileApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MLinksFileApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-upload/src/main/java/com/springboot/cli/confg/MyExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.confg; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import com.springboot.cli.utils.ResponseResult; 5 | import org.springframework.web.bind.annotation.ControllerAdvice; 6 | import org.springframework.web.bind.annotation.ExceptionHandler; 7 | 8 | /** 9 | * @author lqd 10 | */ 11 | @ControllerAdvice 12 | @Slf4j 13 | public class MyExceptionHandler { 14 | 15 | @ExceptionHandler(value = Exception.class) 16 | public ResponseResult exceptionHandler(Exception e) { 17 | return new ResponseResult<>(40004, "未知异常!原因是:" + e); 18 | } 19 | } -------------------------------------------------------------------------------- /springboot-upload/src/main/resources/application.yaml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 20010 3 | spring: 4 | servlet: 5 | multipart: 6 | max-file-size: 200MB #单个数据大小 7 | max-request-size: 500MB #总数据大小 8 | file: 9 | path: d:/test -------------------------------------------------------------------------------- /springboot-upload/src/test/java/com/springboot/cli/MLinksFileApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class MLinksFileApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-validator/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-validator/readme.md: -------------------------------------------------------------------------------- 1 | ## 注解解析 2 | 3 | - `@AssertFalse` 可以为null,如果不为null的话必须为false 4 | 5 | - `@AssertTrue ` 可以为null,如果不为null的话必须为true 6 | 7 | - `@DecimalMax` 设置不能超过最大值 8 | 9 | - `@DecimalMin` 设置不能超过最小值 10 | 11 | - `@Digits` 设置必须是数字且数字整数的位数和小数的位数必须在指定范围内 12 | 13 | - `@Future` 日期必须在当前日期的未来 14 | 15 | - `@Past` 日期必须在当前日期的过去 16 | 17 | - `@Max` 最大不得超过此最大值 18 | 19 | - `@Min` 最大不得小于此最小值 20 | 21 | - `@NotNull` 不能为null,可以是空 22 | 23 | - `@Null` 必须为null 24 | 25 | - `@Pattern` 必须满足指定的正则表达式 26 | 27 | - `@Size` 集合、数组、map等的size()值必须在指定范围内 28 | 29 | - `@Email` 必须是email格式 30 | 31 | - `@Length` 长度必须在指定范围内 32 | 33 | - `@NotBlank` 字符串不能为null,字符串trim()后也不能等于“” 34 | 35 | - `@NotEmpty `不能为null,集合、数组、map等size()不能为0;字符串trim()后可以等于“” 36 | 37 | - `@Range` 值必须在指定范围内 38 | 39 | - `@URL` 必须是一个URL 40 | 41 | 42 | ## 使用示例 43 | 44 | - 浏览器输入 45 | 46 | ``` 47 | http://localhost:9999/ 48 | ``` 49 | 50 | -------------------------------------------------------------------------------- /springboot-validator/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-validator/src/main/java/com/springboot/cli/dto/UserVo.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.dto; 2 | 3 | import lombok.Data; 4 | import lombok.experimental.Accessors; 5 | import org.hibernate.validator.constraints.Length; 6 | 7 | import javax.validation.constraints.Max; 8 | import javax.validation.constraints.Min; 9 | import javax.validation.constraints.NotBlank; 10 | import javax.validation.constraints.NotNull; 11 | 12 | @Data 13 | @Accessors(chain = true) 14 | public class UserVo { 15 | 16 | @NotBlank(message = "用户名称不能为空") 17 | private String name; 18 | 19 | @NotNull(message = "编号不能为空") 20 | @Max(value = 999, message = "编号需小于1000") 21 | @Min(value = 0, message = "编号需大于0") 22 | private Integer number; 23 | 24 | @NotNull(message = "邮箱不能为空") 25 | private String email; 26 | 27 | @Length(message = "手机号不合法") 28 | private String phone; 29 | } 30 | -------------------------------------------------------------------------------- /springboot-validator/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-validator/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-web/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /springboot-web/readme.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 3 | 致力于让开发者快速搭建基础环境并让应用跑起来,提供使用示例供使用者参考,让初学者快速上手。 4 | 5 | ## 环境 6 | 7 | 8 | ## 使用示例 9 | 10 | - 浏览器输入 11 | 12 | ``` 13 | http://localhost:9999/ 14 | ``` 15 | 16 | -------------------------------------------------------------------------------- /springboot-web/src/main/java/com/springboot/cli/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @SpringBootApplication 11 | @Slf4j 12 | public class WebApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(WebApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-web/src/main/java/com/springboot/cli/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli.controller; 2 | 3 | 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author ding 9 | */ 10 | @RestController 11 | public class IndexController { 12 | 13 | /** 14 | * 基础web 15 | */ 16 | @GetMapping("/") 17 | public String hello() { 18 | return "欢迎使用 springboot-cli !"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-web/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | -------------------------------------------------------------------------------- /springboot-web/src/test/java/com/springboot/cli/DomeApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.springboot.cli; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DomeApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springcloud-gateway/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | !**/src/main/**/build/ 29 | !**/src/test/**/build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | ### my #### 35 | logs/ 36 | *-dev.yml 37 | **/src/main/resources/application-dev.yml 38 | -------------------------------------------------------------------------------- /springcloud-gateway/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 梁其定 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /springcloud-gateway/README.md: -------------------------------------------------------------------------------- 1 | ## springCloud版本对照信息 2 | 3 | ```go 4 | https://start.spring.io/actuator/info 5 | ``` 6 | 7 | ## 使用 8 | 9 | - 修改yml中的nacos地址为你的实际地址 10 | - 启动服务1 11 | - 启动服务2 12 | - 启动网关服务 13 | - 浏览器输入`http://localhost:20000/server1/get` 14 | - 浏览器输入`http://localhost:20000/server2/get` 15 | 16 | 17 | -------------------------------------------------------------------------------- /springcloud-gateway/gateway/src/main/java/com/cli/gateway/GatewayAppliction.java: -------------------------------------------------------------------------------- 1 | package com.cli.gateway; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class GatewayAppliction { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(GatewayAppliction.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springcloud-gateway/gateway/src/main/java/com/cli/gateway/utils/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.cli.gateway.utils; 2 | 3 | 4 | 5 | import lombok.Data; 6 | import lombok.experimental.Accessors; 7 | import java.io.Serializable; 8 | 9 | /** 10 | * @author qiding 11 | */ 12 | @Data 13 | @Accessors(chain = true) 14 | public class ResponseResult implements Serializable { 15 | 16 | private static final long serialVersionUID = -1L; 17 | 18 | private Integer code; 19 | 20 | private String message; 21 | 22 | private T data; 23 | 24 | /** 25 | * http默认构造 26 | */ 27 | public ResponseResult() { 28 | super(); 29 | } 30 | 31 | 32 | public ResponseResult(Integer code, String message) { 33 | super(); 34 | this.code = code; 35 | this.message = message; 36 | } 37 | 38 | public ResponseResult(Integer code, String message, T data) { 39 | super(); 40 | this.code = code; 41 | this.message = message; 42 | this.data = data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /springcloud-gateway/server-1/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | gateway-demo 7 | com.springcloud 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | server-1 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | -------------------------------------------------------------------------------- /springcloud-gateway/server-1/src/main/java/com/cli/server/Server1Appliction.java: -------------------------------------------------------------------------------- 1 | package com.cli.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Server1Appliction { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Server1Appliction.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springcloud-gateway/server-1/src/main/java/com/cli/server/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.cli.server.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @Slf4j 10 | @RequestMapping("/server1") 11 | public class IndexController { 12 | 13 | @GetMapping("/get") 14 | public String get() { 15 | return "我是服务1"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springcloud-gateway/server-1/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 20001 3 | # NaCos 4 | spring: 5 | application: 6 | name: server-1 7 | # NaCos 8 | cloud: 9 | service-registry: 10 | auto-registration: 11 | # 是否注册到注册中心 12 | enabled: true 13 | nacos: 14 | discovery: 15 | server-addr: 192.168.41.128:8848 16 | namespace: 4c016e5c-cacb-44d5-955d-22754ede9fce 17 | config: 18 | server-addr: ${spring.cloud.nacos.discovery.server-addr} 19 | namespace: ${spring.cloud.nacos.discovery.namespace} 20 | file-extension: yaml 21 | prefix: ${spring.application.name} 22 | -------------------------------------------------------------------------------- /springcloud-gateway/server-2/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | gateway-demo 7 | com.springcloud 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | server-2 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /springcloud-gateway/server-2/src/main/java/com/cli/server/Server2Appliction.java: -------------------------------------------------------------------------------- 1 | package com.cli.server; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | @SpringBootApplication 8 | @EnableFeignClients 9 | public class Server2Appliction { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(Server2Appliction.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springcloud-gateway/server-2/src/main/java/com/cli/server/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.cli.server.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | @Slf4j 10 | @RequestMapping("/server2") 11 | public class IndexController { 12 | 13 | @GetMapping("/get") 14 | public String get() { 15 | return "我是服务2"; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springcloud-gateway/server-2/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 20002 3 | # NaCos 4 | spring: 5 | application: 6 | name: server-2 7 | # NaCos 8 | cloud: 9 | service-registry: 10 | auto-registration: 11 | # 是否注册到注册中心 12 | enabled: true 13 | nacos: 14 | discovery: 15 | server-addr: 192.168.41.128:8848 16 | namespace: 4c016e5c-cacb-44d5-955d-22754ede9fce 17 | config: 18 | server-addr: ${spring.cloud.nacos.discovery.server-addr} 19 | namespace: ${spring.cloud.nacos.discovery.namespace} 20 | file-extension: yaml 21 | prefix: ${spring.application.name} 22 | -------------------------------------------------------------------------------- /springcloud-hystrix/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | !**/src/main/**/build/ 29 | !**/src/test/**/build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | ### my #### 35 | logs/ 36 | *-dev.yml 37 | **/src/main/resources/application-dev.yml 38 | -------------------------------------------------------------------------------- /springcloud-hystrix/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 梁其定 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /springcloud-hystrix/README.md: -------------------------------------------------------------------------------- 1 | ## springCloud版本对照信息 2 | 3 | ```go 4 | https://start.spring.io/actuator/info 5 | ``` 6 | 7 | ## 使用 8 | 9 | - 修改yml中的nacos地址为你的实际地址 10 | - 启动提供者 11 | - 启动消费者 12 | - 浏览器输入`http://127.0.0.1:9999/test` 13 | 14 | 15 | -------------------------------------------------------------------------------- /springcloud-hystrix/common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | hystrix 7 | com.springcloud 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | common 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | -------------------------------------------------------------------------------- /springcloud-hystrix/consumer/src/main/java/com/cli/consumer/ConsumerServer.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.openfeign.EnableFeignClients; 6 | 7 | 8 | @SpringBootApplication 9 | @EnableFeignClients 10 | public class ConsumerServer { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(ConsumerServer.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springcloud-hystrix/consumer/src/main/java/com/cli/consumer/controller/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer.controller; 2 | 3 | import com.cli.consumer.openfeign.ProviderApi; 4 | import lombok.RequiredArgsConstructor; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @Slf4j 12 | @RequiredArgsConstructor 13 | public class ConsumerController { 14 | 15 | private final ProviderApi providerApi; 16 | 17 | @GetMapping("/test") 18 | public String get() { 19 | // 从提供者中获取数据 20 | ResponseEntity stringResponseEntity = providerApi.get(); 21 | log.info("从提供者中获取数据:{}", stringResponseEntity); 22 | return stringResponseEntity.getBody(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springcloud-hystrix/consumer/src/main/java/com/cli/consumer/openfeign/ProviderApi.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer.openfeign; 2 | 3 | import com.cli.consumer.openfeign.impl.ProviderApiImpl; 4 | import org.springframework.cloud.openfeign.FeignClient; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | 8 | /** 9 | * 利用openfeign 调用消费者的api 10 | * 11 | * @author lqd 12 | */ 13 | @FeignClient(value = "provider", fallback = ProviderApiImpl.class) 14 | public interface ProviderApi { 15 | /** 16 | * @return `` 17 | */ 18 | @GetMapping("/get") 19 | ResponseEntity get(); 20 | } 21 | -------------------------------------------------------------------------------- /springcloud-hystrix/consumer/src/main/java/com/cli/consumer/openfeign/impl/ProviderApiImpl.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer.openfeign.impl; 2 | 3 | 4 | import com.cli.consumer.openfeign.ProviderApi; 5 | import org.springframework.http.ResponseEntity; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * @author lqd 10 | */ 11 | @Service 12 | public class ProviderApiImpl implements ProviderApi { 13 | 14 | @Override 15 | public ResponseEntity get() { 16 | return ResponseEntity.ok("请求出错啦,进入熔断处理。"); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springcloud-hystrix/consumer/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | # NaCos 4 | spring: 5 | application: 6 | name: consumer 7 | # NaCos 8 | cloud: 9 | service-registry: 10 | auto-registration: 11 | # 是否注册到注册中心 12 | enabled: true 13 | nacos: 14 | discovery: 15 | server-addr: 192.168.0.251:8848 16 | # namespace: 1d5a097c-898e-403e-8935-fdbe2cf854f6 17 | namespace: be88b2b8-987c-4801-a5f1-05b867e6370e 18 | config: 19 | server-addr: ${spring.cloud.nacos.discovery.server-addr} 20 | namespace: ${spring.cloud.nacos.discovery.namespace} 21 | file-extension: yaml 22 | prefix: ${spring.application.name} 23 | 24 | feign: 25 | # 开启熔断机制 26 | circuitbreaker: 27 | enabled: true 28 | # 设置超时时间 29 | httpclient: 30 | connection-timeout: 2000 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /springcloud-hystrix/provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | hystrix 7 | com.springcloud 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | provider 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | com.springcloud 21 | common 22 | 0.0.1-SNAPSHOT 23 | 24 | 25 | org.springframework.boot 26 | spring-boot-starter-web 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /springcloud-hystrix/provider/src/main/java/com/cli/provider/ProviderServer.java: -------------------------------------------------------------------------------- 1 | package com.cli.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderServer { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProviderServer.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springcloud-hystrix/provider/src/main/java/com/cli/provider/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.cli.provider.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | @Slf4j 9 | public class IndexController { 10 | 11 | @GetMapping("get") 12 | public String get() throws InterruptedException { 13 | Thread.sleep(5000); 14 | return "喵喵喵"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springcloud-hystrix/provider/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9998 3 | # NaCos 4 | spring: 5 | application: 6 | name: provider 7 | # NaCos 8 | cloud: 9 | service-registry: 10 | auto-registration: 11 | # 是否注册到注册中心 12 | enabled: true 13 | nacos: 14 | discovery: 15 | server-addr: 192.168.0.251:8848 16 | # namespace: 1d5a097c-898e-403e-8935-fdbe2cf854f6 17 | namespace: be88b2b8-987c-4801-a5f1-05b867e6370e 18 | config: 19 | server-addr: ${spring.cloud.nacos.discovery.server-addr} 20 | namespace: ${spring.cloud.nacos.discovery.namespace} 21 | file-extension: yaml 22 | prefix: ${spring.application.name} 23 | -------------------------------------------------------------------------------- /springcloud-nacos/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | ### NetBeans ### 22 | /nbproject/private/ 23 | /nbbuild/ 24 | /dist/ 25 | /nbdist/ 26 | /.nb-gradle/ 27 | build/ 28 | !**/src/main/**/build/ 29 | !**/src/test/**/build/ 30 | 31 | ### VS Code ### 32 | .vscode/ 33 | 34 | ### my #### 35 | logs/ 36 | *-dev.yml 37 | **/src/main/resources/application-dev.yml 38 | -------------------------------------------------------------------------------- /springcloud-nacos/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 梁其定 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /springcloud-nacos/README.md: -------------------------------------------------------------------------------- 1 | ## springCloud版本对照信息 2 | 3 | ```go 4 | https://start.spring.io/actuator/info 5 | ``` 6 | 7 | ## 使用 8 | 9 | - 修改yml中的nacos地址为你的实际地址 10 | - 启动提供者 11 | - 启动消费者 12 | - 浏览器输入`http://127.0.0.1:9999/` 13 | 14 | 15 | -------------------------------------------------------------------------------- /springcloud-nacos/consumer/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cli 7 | com.springcloud 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | consumer 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /springcloud-nacos/consumer/src/main/java/com/cli/consumer/ConsumerServer.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @SpringBootApplication 9 | @EnableDiscoveryClient 10 | @EnableFeignClients 11 | public class ConsumerServer { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ConsumerServer.class, args); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springcloud-nacos/consumer/src/main/java/com/cli/consumer/controller/ConsumerController.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer.controller; 2 | 3 | import com.cli.consumer.openfeign.ProviderApi; 4 | import lombok.RequiredArgsConstructor; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.http.ResponseEntity; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @Slf4j 12 | @RequiredArgsConstructor 13 | public class ConsumerController { 14 | 15 | private final ProviderApi providerApi; 16 | 17 | @GetMapping("/test") 18 | public String get() { 19 | // 从提供者中获取数据 20 | ResponseEntity stringResponseEntity = providerApi.get(); 21 | log.info("从提供者中获取数据:{}", stringResponseEntity); 22 | return stringResponseEntity.getBody(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springcloud-nacos/consumer/src/main/java/com/cli/consumer/openfeign/ProviderApi.java: -------------------------------------------------------------------------------- 1 | package com.cli.consumer.openfeign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.http.ResponseEntity; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * @author lqd 10 | */ 11 | @FeignClient(value = "provider") 12 | public interface ProviderApi { 13 | /** 14 | * @return `` 15 | */ 16 | @GetMapping("/get") 17 | ResponseEntity get(); 18 | } 19 | -------------------------------------------------------------------------------- /springcloud-nacos/consumer/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9999 3 | # NaCos 4 | spring: 5 | application: 6 | name: consumer 7 | # NaCos 8 | cloud: 9 | service-registry: 10 | auto-registration: 11 | # 是否注册到注册中心 12 | enabled: true 13 | nacos: 14 | discovery: 15 | server-addr: 192.168.41.128:8848 16 | namespace: 1d5a097c-898e-403e-8935-fdbe2cf854f6 17 | config: 18 | server-addr: ${spring.cloud.nacos.discovery.server-addr} 19 | namespace: ${spring.cloud.nacos.discovery.namespace} 20 | file-extension: yaml 21 | prefix: ${spring.application.name} 22 | -------------------------------------------------------------------------------- /springcloud-nacos/provider/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cli 7 | com.springcloud 8 | 0.0.1-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | provider 13 | 14 | 15 | 11 16 | 11 17 | 18 | 19 | 20 | org.springframework.boot 21 | spring-boot-starter-web 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /springcloud-nacos/provider/src/main/java/com/cli/provider/ProviderServer.java: -------------------------------------------------------------------------------- 1 | package com.cli.provider; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProviderServer { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProviderServer.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springcloud-nacos/provider/src/main/java/com/cli/provider/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.cli.provider.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | @Slf4j 9 | public class IndexController { 10 | 11 | @GetMapping("get") 12 | public String get() { 13 | return "喵喵喵"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springcloud-nacos/provider/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 9998 3 | # NaCos 4 | spring: 5 | application: 6 | name: provider 7 | # NaCos 8 | cloud: 9 | service-registry: 10 | auto-registration: 11 | # 是否注册到注册中心 12 | enabled: true 13 | nacos: 14 | discovery: 15 | server-addr: 192.168.41.128:8848 16 | namespace: 1d5a097c-898e-403e-8935-fdbe2cf854f6 17 | config: 18 | server-addr: ${spring.cloud.nacos.discovery.server-addr} 19 | namespace: ${spring.cloud.nacos.discovery.namespace} 20 | file-extension: yaml 21 | prefix: ${spring.application.name} 22 | --------------------------------------------------------------------------------