├── .gitignore ├── README.md ├── pom.xml ├── springboot-aop-log ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── AopLogApplication.java │ │ ├── annotation │ │ └── Log.java │ │ ├── aspect │ │ └── LogAspect.java │ │ ├── controller │ │ ├── SysLogController.java │ │ └── UserRecordController.java │ │ ├── dao │ │ ├── SysLogDao.java │ │ └── UserRecordDao.java │ │ ├── entity │ │ ├── SysLog.java │ │ └── UserRecord.java │ │ └── service │ │ ├── SysLogService.java │ │ ├── UserRecordService.java │ │ └── impl │ │ ├── SysLogServiceImpl.java │ │ └── UserRecordServiceImpl.java │ └── resources │ ├── application.properties │ └── mapper │ ├── SysLogDao.xml │ └── UserRecordDao.xml ├── springboot-async ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── AsyncApplication.java │ │ ├── config │ │ └── AsyncConfig.java │ │ ├── controller │ │ └── UserRecordController.java │ │ ├── dao │ │ └── UserRecordDao.java │ │ ├── entity │ │ └── UserRecord.java │ │ └── service │ │ ├── AsyncService.java │ │ ├── UserRecordService.java │ │ └── impl │ │ ├── AsyncServiceImpl.java │ │ └── UserRecordServiceImpl.java │ └── resources │ └── application.yml ├── springboot-caffeine ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── CaffeineApplication.java │ │ ├── config │ │ └── CacheManagerConfig.java │ │ └── controller │ │ └── TestController.java │ └── resources │ └── application.yml ├── springboot-easyexcel ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── ruiyeclub │ │ │ ├── EasyExcelApplication.java │ │ │ ├── entity │ │ │ └── ExcelModel.java │ │ │ ├── listener │ │ │ ├── ModelExcelListener.java │ │ │ └── StringExcelListener.java │ │ │ └── utils │ │ │ ├── DataConvertUtil.java │ │ │ ├── ExcelConvertCsvUtil.java │ │ │ └── ExcelUtil.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── EasyExcelApplicationTests.java ├── springboot-fastjson2 ├── README.md ├── pom.xml └── src │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── FastJson2ApplicationTests.java ├── springboot-flyway ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── ruiyeclub │ │ │ ├── FlywayApplication.java │ │ │ ├── entity │ │ │ └── User.java │ │ │ └── mapper │ │ │ └── UserMapper.java │ └── resources │ │ ├── application.yml │ │ └── db │ │ └── migration │ │ └── V1__Base_version.sql │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── UserTests.java ├── springboot-hibernate-validator ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── HibernateValidatorApplication.java │ │ ├── controller │ │ └── TestController.java │ │ ├── entity │ │ ├── JsonData.java │ │ └── UserModel.java │ │ └── exception │ │ └── GlobalExceptionAdvice.java │ └── resources │ ├── application.properties │ └── banner.txt ├── springboot-hutool ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── entity │ │ └── PmsBrand.java │ │ └── hutool │ │ ├── AnnotationUtilTest.java │ │ ├── BeanUtilTest.java │ │ ├── ClassPathResourceTest.java │ │ ├── CollUtilTest.java │ │ ├── ConvertTest.java │ │ ├── DateUtilTest.java │ │ ├── DigestUtilTest.java │ │ ├── HttpUtilTest.java │ │ ├── JSONUtilTest.java │ │ ├── MapUtilTest.java │ │ ├── NumberUtilTest.java │ │ ├── ReflectUtilTest.java │ │ ├── SecureUtilTest.java │ │ ├── StrUtilTest.java │ │ └── ValidatorTest.java │ └── resources │ └── application.yml ├── springboot-i18n ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── I18nApplication.java │ │ ├── config │ │ ├── LocaleConfig.java │ │ └── WebMvcConfig.java │ │ ├── controller │ │ └── HelloController.java │ │ └── utils │ │ └── MessageUtils.java │ └── resources │ ├── application.yml │ ├── messages.properties │ ├── messages_en_US.properties │ ├── messages_zh_CN.properties │ └── messages_zh_TW.properties ├── springboot-japidocs ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── JApiDocsApplication.java │ │ ├── config │ │ └── MybatisPlusConfig.java │ │ ├── controller │ │ └── UserRecordController.java │ │ ├── dao │ │ └── UserRecordDao.java │ │ ├── entity │ │ └── UserRecord.java │ │ ├── service │ │ ├── UserRecordService.java │ │ └── impl │ │ │ └── UserRecordServiceImpl.java │ │ └── util │ │ └── DocUtil.java │ └── resources │ └── application.yml ├── springboot-jpa ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── ruiyeclub │ │ │ ├── JpaApplication.java │ │ │ ├── controller │ │ │ └── UserRecordController.java │ │ │ ├── dao │ │ │ └── UserRecordDao.java │ │ │ ├── entity │ │ │ └── UserRecord.java │ │ │ └── service │ │ │ ├── UserRecordService.java │ │ │ └── impl │ │ │ └── UserRecordServiceImpl.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── JpaSpringBootTest.java ├── springboot-jwt ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── TokenApplication.java │ │ ├── annotation │ │ ├── CheckToken.java │ │ └── LoginToken.java │ │ ├── config │ │ └── InterceptorConfig.java │ │ ├── controller │ │ └── UserController.java │ │ ├── dao │ │ └── UserDao.java │ │ ├── entity │ │ └── User.java │ │ ├── interceptor │ │ └── AuthenticationInterceptor.java │ │ ├── service │ │ ├── UserService.java │ │ └── impl │ │ │ └── UserServiceImpl.java │ │ └── utils │ │ ├── JsonData.java │ │ └── JwtUtils.java │ └── resources │ ├── application.properties │ └── mapper │ └── UserDao.xml ├── springboot-kaptcha ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── KaptchaApplication.java │ │ ├── config │ │ └── RedisConfig.java │ │ ├── controller │ │ └── LoginController.java │ │ ├── dto │ │ └── LoginDTO.java │ │ ├── service │ │ ├── CaptchaService.java │ │ └── impl │ │ │ └── CaptchaServiceImpl.java │ │ └── util │ │ └── RedisUtils.java │ └── resources │ └── application.yml ├── springboot-knife4j ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── Knife4jApplication.java │ │ ├── config │ │ ├── Knife4jConfig.java │ │ └── MybatisPlusConfig.java │ │ ├── controller │ │ └── UserRecordController.java │ │ ├── dao │ │ └── UserRecordDao.java │ │ ├── entity │ │ └── UserRecord.java │ │ ├── service │ │ ├── UserRecordService.java │ │ └── impl │ │ │ └── UserRecordServiceImpl.java │ │ └── util │ │ └── LocalHostUtils.java │ └── resources │ └── application.yml ├── springboot-lambda ├── pom.xml └── src │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── LambdaApplicationTests.java ├── springboot-mail-rabbitmq ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── MailRabbitMQApplication.java │ │ ├── config │ │ └── RabbitMQConfig.java │ │ ├── constant │ │ └── MQPrefixConst.java │ │ ├── consumer │ │ └── EmailConsumer.java │ │ ├── controller │ │ └── MailController.java │ │ ├── dto │ │ └── EmailDTO.java │ │ └── utils │ │ └── MailUtils.java │ └── resources │ ├── application.yml │ └── templates │ └── code.html ├── springboot-mail ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── MailApplication.java │ │ ├── config │ │ └── Swagger3Config.java │ │ ├── controller │ │ └── MailController.java │ │ └── utils │ │ └── MailUtils.java │ └── resources │ ├── application.yml │ └── templates │ └── hello.html ├── springboot-mongodb ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── ruiyeclub │ │ │ └── MongodbApplication.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── mongodb │ └── MongodbApplicationTests.java ├── springboot-mybatis-plus ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── MybatisPlusApplication.java │ │ ├── config │ │ └── MybatisPlusConfig.java │ │ ├── controller │ │ └── UserRecordController.java │ │ ├── dao │ │ └── UserRecordDao.java │ │ ├── entity │ │ └── UserRecord.java │ │ └── service │ │ ├── UserRecordService.java │ │ └── impl │ │ └── UserRecordServiceImpl.java │ └── resources │ └── application.yml ├── springboot-nacos ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── NacosApplication.java │ │ ├── config │ │ └── RegisterNacosConfig.java │ │ └── controller │ │ ├── DiscoveryController.java │ │ └── HelloController.java │ └── resources │ └── application.yml ├── springboot-oss-qiniu ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── OssQiniuApplication.java │ │ ├── controller │ │ └── QiNiuTestController.java │ │ └── utils │ │ └── QiniuUtil.java │ └── resources │ └── application.yml ├── springboot-quartz ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── QuartzApplication.java │ │ ├── config │ │ ├── DruidConnectionProvider.java │ │ ├── QuartzConfig.java │ │ └── QuartzJobFactory.java │ │ ├── controller │ │ └── TestController.java │ │ ├── dto │ │ └── QuartzConfigDTO.java │ │ ├── job │ │ └── TfCommandJob.java │ │ └── service │ │ ├── QuartzJobService.java │ │ └── impl │ │ └── QuartzJobServiceImpl.java │ └── resources │ ├── application.properties │ ├── db │ └── tables_mysql_innodb.sql │ └── quartz.properties ├── springboot-rabbitmq ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── ruiyeclub │ │ │ ├── RabbitMQApplication.java │ │ │ ├── config │ │ │ └── MyAMQPConfig.java │ │ │ └── service │ │ │ └── MQService.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── RabbitMQApplicationTests.java ├── springboot-redis-lock ├── pom.xml └── src │ ├── main │ ├── java │ │ └── cn │ │ │ └── ruiyeclub │ │ │ ├── RedisLockApplication.java │ │ │ └── utils │ │ │ └── RedisLock.java │ └── resources │ │ └── application.yml │ └── test │ └── java │ └── cn │ └── ruiyeclub │ └── RedisTest.java ├── springboot-redis-mq ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── RedisMQApplication.java │ │ ├── config │ │ ├── PublisherConfig.java │ │ └── SubscriberConfig.java │ │ ├── controller │ │ └── PublisherController.java │ │ ├── listener │ │ └── Receiver.java │ │ └── service │ │ └── PublisherService.java │ └── resources │ └── application.yml ├── springboot-redis-ratelimit ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── RedisRateLimitApplication.java │ │ ├── annotation │ │ └── RateLimiter.java │ │ ├── aspect │ │ └── RateLimiterAspect.java │ │ ├── config │ │ └── RedisConfig.java │ │ ├── controller │ │ └── TestController.java │ │ ├── hander │ │ └── GlobalExceptionHandler.java │ │ └── util │ │ └── IpUtil.java │ └── resources │ ├── application.yml │ └── scripts │ └── redis │ └── limit.lua ├── springboot-redis ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── RedisApplication.java │ │ ├── controller │ │ └── StudentController.java │ │ └── entity │ │ └── Student.java │ └── resources │ └── application.yml ├── springboot-scheduled ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── ScheduledApplication.java │ │ ├── config │ │ └── AsyncConfig.java │ │ └── scheduled │ │ └── Jobs.java │ └── resources │ └── application.yml ├── springboot-shiro-jwt-redis ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── ShiroJwtRedisApplication.java │ │ ├── config │ │ ├── CorsConfig.java │ │ └── MybatisPlusConfig.java │ │ ├── controller │ │ └── AccountController.java │ │ ├── dao │ │ ├── SysPermissionDao.java │ │ ├── SysRoleDao.java │ │ ├── SysRolePermissionDao.java │ │ ├── SysUserDao.java │ │ └── SysUserRoleDao.java │ │ ├── dto │ │ └── LoginDto.java │ │ ├── entity │ │ ├── SysPermission.java │ │ ├── SysRole.java │ │ ├── SysRolePermission.java │ │ ├── SysUser.java │ │ └── SysUserRole.java │ │ ├── excepiton │ │ └── GlobalExcepitonHandler.java │ │ ├── result │ │ └── Result.java │ │ ├── service │ │ ├── SysPermissionService.java │ │ ├── SysRolePermissionService.java │ │ ├── SysRoleService.java │ │ ├── SysUserRoleService.java │ │ ├── SysUserService.java │ │ └── impl │ │ │ ├── SysPermissionServiceImpl.java │ │ │ ├── SysRolePermissionServiceImpl.java │ │ │ ├── SysRoleServiceImpl.java │ │ │ ├── SysUserRoleServiceImpl.java │ │ │ └── SysUserServiceImpl.java │ │ ├── shiro │ │ ├── AccountProfile.java │ │ ├── JwtFilter.java │ │ ├── JwtToken.java │ │ ├── JwtUtils.java │ │ ├── ShiroConfig.java │ │ └── ShiroRealm.java │ │ └── util │ │ ├── MD5Utils.java │ │ └── ShiroUtil.java │ └── resources │ ├── application.yml │ └── mapper │ ├── SysPermissionMapper.xml │ └── SysRoleMapper.xml ├── springboot-shiro-jwt ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── ShiroJwtApplication.java │ │ ├── config │ │ └── MybatisPlusConfig.java │ │ ├── controller │ │ └── AccountController.java │ │ ├── dao │ │ ├── SysPermissionDao.java │ │ ├── SysRoleDao.java │ │ ├── SysRolePermissionDao.java │ │ ├── SysUserDao.java │ │ └── SysUserRoleDao.java │ │ ├── dto │ │ └── LoginDto.java │ │ ├── entity │ │ ├── SysPermission.java │ │ ├── SysRole.java │ │ ├── SysRolePermission.java │ │ ├── SysUser.java │ │ └── SysUserRole.java │ │ ├── result │ │ └── Result.java │ │ ├── service │ │ ├── SysPermissionService.java │ │ ├── SysRolePermissionService.java │ │ ├── SysRoleService.java │ │ ├── SysUserRoleService.java │ │ ├── SysUserService.java │ │ └── impl │ │ │ ├── SysPermissionServiceImpl.java │ │ │ ├── SysRolePermissionServiceImpl.java │ │ │ ├── SysRoleServiceImpl.java │ │ │ ├── SysUserRoleServiceImpl.java │ │ │ └── SysUserServiceImpl.java │ │ ├── shiro │ │ ├── JwtFilter.java │ │ ├── JwtToken.java │ │ ├── ShiroConfig.java │ │ └── ShiroRealm.java │ │ └── util │ │ ├── JwtUtils.java │ │ ├── MD5Utils.java │ │ └── ShiroUtil.java │ └── resources │ ├── application.yml │ └── mapper │ ├── SysPermissionMapper.xml │ └── SysRoleMapper.xml ├── springboot-shiro ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── ShiroApplication.java │ │ ├── config │ │ ├── ShiroConfig.java │ │ └── UserRealm.java │ │ ├── controller │ │ └── UserController.java │ │ ├── mapper │ │ └── UserMapper.java │ │ ├── pojo │ │ └── User.java │ │ └── service │ │ ├── UserService.java │ │ └── impl │ │ └── UserServiceImpl.java │ └── resources │ ├── application.yml │ ├── mapper │ └── UserMapper.xml │ └── templates │ ├── index.html │ ├── login.html │ └── user │ ├── add.html │ └── update.html ├── springboot-sms ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── SmsApplication.java │ │ ├── controller │ │ └── SendSmsController.java │ │ └── service │ │ ├── SendSmsService.java │ │ └── impl │ │ └── SendSmsServiceImpl.java │ └── resources │ └── application.yml ├── springboot-socket.io ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── SocketIOApplication.java │ │ ├── client │ │ └── SocketIOClientLaunch.java │ │ ├── config │ │ └── SocketIOConfig.java │ │ ├── controller │ │ └── SocketIOController.java │ │ └── service │ │ ├── ISocketIOService.java │ │ └── impl │ │ └── SocketIOServiceImpl.java │ └── resources │ └── application.yml ├── springboot-swagger3 ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── Swagger3Application.java │ │ ├── config │ │ ├── MybatisPlusConfig.java │ │ └── Swagger3Config.java │ │ ├── controller │ │ └── UserRecordController.java │ │ ├── dao │ │ └── UserRecordDao.java │ │ ├── entity │ │ └── UserRecord.java │ │ └── service │ │ ├── UserRecordService.java │ │ └── impl │ │ └── UserRecordServiceImpl.java │ └── resources │ └── application.yml ├── springboot-thymeleaf ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── ThymeleafApplication.java │ │ ├── controller │ │ └── IndexController.java │ │ └── entity │ │ └── Account.java │ └── resources │ ├── application.yml │ ├── static │ └── css │ │ └── style.css │ └── templates │ ├── account.html │ └── hello.html ├── springboot-undertow ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ └── UndertowApplication.java │ └── resources │ └── application.yml ├── springboot-upload ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── UploadApplication.java │ │ ├── config │ │ └── WebMvcConfig.java │ │ └── controller │ │ └── FileController.java │ └── resources │ └── application.properties ├── springboot-validation ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── cn │ └── ruiyeclub │ ├── ValidationApplication.java │ ├── config │ └── Swagger3Config.java │ ├── controller │ └── TestController.java │ ├── entity │ ├── JsonData.java │ └── UserModel.java │ └── exception │ ├── GlobalExceptionAdvice.java │ └── GlobalExceptionHandler.java ├── springboot-vue-axios ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── VueAxiosApplication.java │ │ ├── controller │ │ └── DeptController.java │ │ ├── dao │ │ └── DeptDao.java │ │ ├── entity │ │ └── Dept.java │ │ └── service │ │ ├── DeptService.java │ │ └── impl │ │ └── DeptServiceImpl.java │ └── resources │ ├── application.yml │ └── static │ └── dept-vue.html ├── springboot-websocket-server-client ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── Application.java │ │ ├── config │ │ └── WebSocketServerConfig.java │ │ └── socket │ │ ├── WebSocketClient.java │ │ └── WebSocketHandler.java │ └── resources │ └── static │ └── chat.html ├── springboot-websocket ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── WebsocketApplication.java │ │ ├── config │ │ └── WebSocketServerConfig.java │ │ └── handler │ │ └── MyStringWebSocketHandler.java │ └── resources │ └── static │ └── client.html ├── springboot-wxpay ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── WxpayApplication.java │ │ ├── config │ │ ├── Swagger3Config.java │ │ ├── WxPayConfiguration.java │ │ └── WxPayProperties.java │ │ ├── controller │ │ ├── EntPayController.java │ │ └── WxPayController.java │ │ ├── error │ │ ├── ErrorController.java │ │ └── ErrorPageConfiguration.java │ │ └── utils │ │ ├── IpUtil.java │ │ └── PayUtils.java │ └── resources │ ├── application.yml │ └── templates │ └── error.html ├── springboot-xxl-job ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── cn │ │ └── ruiyeclub │ │ ├── XxlJobApplication.java │ │ ├── config │ │ └── XxlJobConfig.java │ │ └── job │ │ └── SampleXxlJob.java │ └── resources │ ├── application.yml │ └── logback.xml └── sql └── boot_hello.sql /.gitignore: -------------------------------------------------------------------------------- 1 | */.settings/ 2 | */target/ 3 | */.classpath 4 | */.project 5 | .idea -------------------------------------------------------------------------------- /springboot-aop-log/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot之AOP实现日志写入数据库(一) 2 | https://www.jianshu.com/p/626e658816aa -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/AopLogApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @MapperScan("cn.ruiyeclub.dao") 9 | public class AopLogApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AopLogApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/annotation/Log.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.annotation; 2 | 3 | import java.lang.annotation.*; 4 | 5 | /** 6 | * @author Ray。 7 | * @create 2020-06-07 22:06 8 | */ 9 | @Target(ElementType.METHOD) 10 | @Retention(RetentionPolicy.RUNTIME) 11 | @Documented //生成文档 12 | public @interface Log { 13 | //日志操作名称 14 | String value() default ""; 15 | 16 | //日志级别(暂未用) 17 | String level() default ""; 18 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/controller/SysLogController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.entity.SysLog; 4 | import cn.ruiyeclub.service.SysLogService; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * (SysLog)表控制层 11 | * 12 | * @author Ray。 13 | * @since 2020-06-07 22:04:11 14 | */ 15 | @RestController 16 | @RequestMapping("sysLog") 17 | public class SysLogController { 18 | /** 19 | * 服务对象 20 | */ 21 | @Resource 22 | private SysLogService sysLogService; 23 | 24 | /** 25 | * 通过主键查询单条数据 26 | * 27 | * @param id 主键 28 | * @return 单条数据 29 | */ 30 | @GetMapping("selectOne") 31 | public SysLog selectOne(Integer id) { 32 | return this.sysLogService.queryById(id); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/controller/UserRecordController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.annotation.Log; 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import javax.annotation.Resource; 11 | 12 | /** 13 | * (UserRecord)表控制层 14 | * 15 | * @author Ray。 16 | * @since 2020-07-22 14:29:23 17 | */ 18 | @RestController 19 | @RequestMapping("userRecord") 20 | public class UserRecordController { 21 | /** 22 | * 服务对象 23 | */ 24 | @Resource 25 | private UserRecordService userRecordService; 26 | 27 | /** 28 | * 通过主键查询单条数据 29 | * 30 | * @param id 主键 31 | * @return 单条数据 32 | */ 33 | @Log("查看用户") 34 | @GetMapping("selectOne") 35 | public UserRecord selectOne(Integer id) { 36 | return this.userRecordService.queryById(id); 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/dao/SysLogDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.SysLog; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * (SysLog)表数据库访问层 10 | * 11 | * @author Ray。 12 | * @since 2020-06-07 22:04:11 13 | */ 14 | public interface SysLogDao { 15 | 16 | /** 17 | * 通过ID查询单条数据 18 | * 19 | * @param id 主键 20 | * @return 实例对象 21 | */ 22 | SysLog queryById(Integer id); 23 | 24 | /** 25 | * 查询指定行数据 26 | * 27 | * @param offset 查询起始位置 28 | * @param limit 查询条数 29 | * @return 对象列表 30 | */ 31 | List queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit); 32 | 33 | 34 | /** 35 | * 通过实体作为筛选条件查询 36 | * 37 | * @param sysLog 实例对象 38 | * @return 对象列表 39 | */ 40 | List queryAll(SysLog sysLog); 41 | 42 | /** 43 | * 新增数据 44 | * 45 | * @param sysLog 实例对象 46 | * @return 影响行数 47 | */ 48 | int insert(SysLog sysLog); 49 | 50 | /** 51 | * 修改数据 52 | * 53 | * @param sysLog 实例对象 54 | * @return 影响行数 55 | */ 56 | int update(SysLog sysLog); 57 | 58 | /** 59 | * 通过主键删除数据 60 | * 61 | * @param id 主键 62 | * @return 影响行数 63 | */ 64 | int deleteById(Integer id); 65 | 66 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * (UserRecord)表数据库访问层 10 | * 11 | * @author Ray。 12 | * @since 2020-07-22 14:32:33 13 | */ 14 | public interface UserRecordDao { 15 | 16 | /** 17 | * 通过ID查询单条数据 18 | * 19 | * @param id 主键 20 | * @return 实例对象 21 | */ 22 | UserRecord queryById(Integer id); 23 | 24 | /** 25 | * 查询指定行数据 26 | * 27 | * @param offset 查询起始位置 28 | * @param limit 查询条数 29 | * @return 对象列表 30 | */ 31 | List queryAllByLimit(@Param("offset") int offset, @Param("limit") int limit); 32 | 33 | 34 | /** 35 | * 通过实体作为筛选条件查询 36 | * 37 | * @param userRecord 实例对象 38 | * @return 对象列表 39 | */ 40 | List queryAll(UserRecord userRecord); 41 | 42 | /** 43 | * 新增数据 44 | * 45 | * @param userRecord 实例对象 46 | * @return 影响行数 47 | */ 48 | int insert(UserRecord userRecord); 49 | 50 | /** 51 | * 修改数据 52 | * 53 | * @param userRecord 实例对象 54 | * @return 影响行数 55 | */ 56 | int update(UserRecord userRecord); 57 | 58 | /** 59 | * 通过主键删除数据 60 | * 61 | * @param id 主键 62 | * @return 影响行数 63 | */ 64 | int deleteById(Integer id); 65 | 66 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/entity/SysLog.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import java.util.Date; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * (SysLog)实体类 8 | * 9 | * @author Ray。 10 | * @since 2020-06-07 22:04:11 11 | */ 12 | public class SysLog implements Serializable { 13 | private static final long serialVersionUID = 974370584191486768L; 14 | 15 | private Integer id; 16 | 17 | private Integer userId; 18 | 19 | private String userAction; 20 | 21 | private Date createTime; 22 | 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public Integer getUserId() { 33 | return userId; 34 | } 35 | 36 | public void setUserId(Integer userId) { 37 | this.userId = userId; 38 | } 39 | 40 | public String getUserAction() { 41 | return userAction; 42 | } 43 | 44 | public void setUserAction(String userAction) { 45 | this.userAction = userAction; 46 | } 47 | 48 | public Date getCreateTime() { 49 | return createTime; 50 | } 51 | 52 | public void setCreateTime(Date createTime) { 53 | this.createTime = createTime; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * (UserRecord)表实体类 7 | * 8 | * @author Ray。 9 | * @date 2020-07-22 14:29:22 10 | */ 11 | public class UserRecord { 12 | 13 | private Integer id; 14 | 15 | private String name; 16 | 17 | private Integer age; 18 | 19 | private String email; 20 | 21 | 22 | public Integer getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Integer id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public Integer getAge() { 39 | return age; 40 | } 41 | 42 | public void setAge(Integer age) { 43 | this.age = age; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/service/SysLogService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.SysLog; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * (SysLog)表服务接口 9 | * 10 | * @author Ray。 11 | * @since 2020-06-07 22:04:11 12 | */ 13 | public interface SysLogService { 14 | 15 | /** 16 | * 通过ID查询单条数据 17 | * 18 | * @param id 主键 19 | * @return 实例对象 20 | */ 21 | SysLog queryById(Integer id); 22 | 23 | /** 24 | * 查询多条数据 25 | * 26 | * @param offset 查询起始位置 27 | * @param limit 查询条数 28 | * @return 对象列表 29 | */ 30 | List queryAllByLimit(int offset, int limit); 31 | 32 | /** 33 | * 新增数据 34 | * 35 | * @param sysLog 实例对象 36 | * @return 实例对象 37 | */ 38 | SysLog insert(SysLog sysLog); 39 | 40 | /** 41 | * 修改数据 42 | * 43 | * @param sysLog 实例对象 44 | * @return 实例对象 45 | */ 46 | SysLog update(SysLog sysLog); 47 | 48 | /** 49 | * 通过主键删除数据 50 | * 51 | * @param id 主键 52 | * @return 是否成功 53 | */ 54 | boolean deleteById(Integer id); 55 | 56 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * (UserRecord)表服务接口 9 | * 10 | * @author Ray。 11 | * @since 2020-07-22 14:29:22 12 | */ 13 | public interface UserRecordService { 14 | 15 | /** 16 | * 通过ID查询单条数据 17 | * 18 | * @param id 主键 19 | * @return 实例对象 20 | */ 21 | UserRecord queryById(Integer id); 22 | 23 | /** 24 | * 查询多条数据 25 | * 26 | * @param offset 查询起始位置 27 | * @param limit 查询条数 28 | * @return 对象列表 29 | */ 30 | List queryAllByLimit(int offset, int limit); 31 | 32 | /** 33 | * 新增数据 34 | * 35 | * @param userRecord 实例对象 36 | * @return 实例对象 37 | */ 38 | UserRecord insert(UserRecord userRecord); 39 | 40 | /** 41 | * 修改数据 42 | * 43 | * @param userRecord 实例对象 44 | * @return 实例对象 45 | */ 46 | UserRecord update(UserRecord userRecord); 47 | 48 | /** 49 | * 通过主键删除数据 50 | * 51 | * @param id 主键 52 | * @return 是否成功 53 | */ 54 | boolean deleteById(Integer id); 55 | 56 | } -------------------------------------------------------------------------------- /springboot-aop-log/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=81 2 | ##\u6570\u636E\u5E93\u8FDE\u63A5\u4FE1\u606F 3 | spring.datasource.url=jdbc:mysql://localhost/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 4 | spring.datasource.username=root 5 | spring.datasource.password=root 6 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 7 | mybatis.mapper-locations=classpath:mapper/*.xml 8 | #\u63A7\u5236\u53F0\u6253\u5370sql 9 | logging.level.com.ruiyeclub.dao=debug -------------------------------------------------------------------------------- /springboot-async/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot之集成Async异步调用 2 | https://blog.csdn.net/qq_37132495/article/details/121322146 3 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/AsyncApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author: Cr. 9 | * @date: 2022/12/12 10 | */ 11 | @SpringBootApplication 12 | @MapperScan(basePackages = {"cn.ruiyeclub.dao"}) 13 | public class AsyncApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(AsyncApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/config/AsyncConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 7 | 8 | /** 9 | * 配置自定义线程池 10 | * 11 | * @author Cr. 12 | */ 13 | @Configuration 14 | @EnableAsync 15 | public class AsyncConfig { 16 | 17 | @Bean("customExecutor") 18 | public ThreadPoolTaskExecutor asyncOperationExecutor() { 19 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 20 | // 设置核心线程数 21 | executor.setCorePoolSize(8); 22 | // 设置最大线程数 23 | executor.setMaxPoolSize(20); 24 | // 设置队列大小 25 | executor.setQueueCapacity(Integer.MAX_VALUE); 26 | // 设置线程活跃时间(秒) 27 | executor.setKeepAliveSeconds(60); 28 | // 设置线程名前缀+分组名称 29 | executor.setThreadNamePrefix("AsyncOperationThread-"); 30 | executor.setThreadGroupName("AsyncOperationGroup"); 31 | // 所有任务结束后关闭线程池 32 | executor.setWaitForTasksToCompleteOnShutdown(true); 33 | // 初始化 34 | executor.initialize(); 35 | return executor; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/controller/UserRecordController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.service.UserRecordService; 4 | import com.baomidou.mybatisplus.extension.api.ApiController; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * (UserRecord)表控制层 11 | * 12 | * @author Ray。 13 | * @date 2020-07-22 14:06:53 14 | */ 15 | @RestController 16 | @RequestMapping("userRecord") 17 | public class UserRecordController extends ApiController { 18 | 19 | /** 20 | * 服务对象 21 | */ 22 | @Resource 23 | private UserRecordService userRecordService; 24 | 25 | /** 26 | * 保存方法 27 | * 28 | * @return 29 | * @throws InterruptedException 30 | */ 31 | @GetMapping("save") 32 | public int save() throws InterruptedException { 33 | return userRecordService.execute(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (UserRecord)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @date 2020-07-22 14:06:51 11 | */ 12 | public interface UserRecordDao extends BaseMapper { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.baomidou.mybatisplus.extension.activerecord.Model; 7 | 8 | /** 9 | * (UserRecord)表实体类 10 | * 11 | * @author Ray。 12 | * @date 2020-07-22 14:06:49 13 | */ 14 | @TableName("user_record") 15 | public class UserRecord extends Model { 16 | 17 | @TableId(value = "id", type = IdType.AUTO) 18 | private Integer id; 19 | 20 | private String name; 21 | 22 | private Integer age; 23 | 24 | private String email; 25 | 26 | 27 | public Integer getId() { 28 | return id; 29 | } 30 | 31 | public void setId(Integer id) { 32 | this.id = id; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public void setName(String name) { 40 | this.name = name; 41 | } 42 | 43 | public Integer getAge() { 44 | return age; 45 | } 46 | 47 | public void setAge(Integer age) { 48 | this.age = age; 49 | } 50 | 51 | public String getEmail() { 52 | return email; 53 | } 54 | 55 | public void setEmail(String email) { 56 | this.email = email; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/service/AsyncService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | /** 4 | * @author: Cr. 5 | * @date: 2022/12/12 6 | */ 7 | public interface AsyncService { 8 | 9 | /** 10 | * 异步方法 11 | */ 12 | void sleep() throws InterruptedException; 13 | } 14 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (UserRecord)表服务接口 8 | * 9 | * @author Ray。 10 | * @date 2020-07-22 14:06:52 11 | */ 12 | public interface UserRecordService extends IService { 13 | 14 | /** 15 | * 测试异步方法 16 | * 17 | * @return 18 | */ 19 | int execute() throws InterruptedException; 20 | } 21 | -------------------------------------------------------------------------------- /springboot-async/src/main/java/cn/ruiyeclub/service/impl/AsyncServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import cn.ruiyeclub.service.AsyncService; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.scheduling.annotation.Async; 8 | import org.springframework.stereotype.Service; 9 | import org.springframework.transaction.annotation.Transactional; 10 | 11 | /** 12 | * @author: Cr. 13 | * @date: 2022/12/12 14 | */ 15 | @Service 16 | public class AsyncServiceImpl implements AsyncService { 17 | 18 | @Autowired 19 | private UserRecordService userRecordService; 20 | 21 | @Override 22 | @Transactional(rollbackFor = Exception.class) 23 | @Async("customExecutor") 24 | public void sleep() throws InterruptedException { 25 | UserRecord userRecord = new UserRecord(); 26 | userRecord.setName("小米"); 27 | userRecordService.save(userRecord); 28 | for (int i = 0; i < 5; i++) { 29 | Thread.sleep(1000 * 5); 30 | System.out.println(i); 31 | } 32 | int a = 1 / 0; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-async/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://116.205.186.87:3306/test?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: admin1999 11 | -------------------------------------------------------------------------------- /springboot-caffeine/README.md: -------------------------------------------------------------------------------- 1 | Spring Boot 整合 Caffeine 本地缓存及 Spring Cache 注解的使用 2 | https://blog.csdn.net/qq_45607784/article/details/135409207 -------------------------------------------------------------------------------- /springboot-caffeine/src/main/java/cn/ruiyeclub/CaffeineApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CaffeineApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(CaffeineApplication.class, args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /springboot-caffeine/src/main/java/cn/ruiyeclub/config/CacheManagerConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.github.benmanes.caffeine.cache.Caffeine; 4 | import org.springframework.cache.CacheManager; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | import org.springframework.cache.caffeine.CaffeineCacheManager; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | import java.util.concurrent.TimeUnit; 11 | 12 | @EnableCaching 13 | @Configuration 14 | public class CacheManagerConfig { 15 | 16 | @Bean("caffeineCacheManager") 17 | public CacheManager cacheManager() { 18 | CaffeineCacheManager cacheManager = new CaffeineCacheManager(); 19 | cacheManager.setCaffeine(Caffeine.newBuilder() 20 | // 设置过期时间,写入后五分钟过期 21 | .expireAfterWrite(5, TimeUnit.MINUTES) 22 | // 初始化缓存空间大小 23 | .initialCapacity(100) 24 | // 最大的缓存条数 25 | .maximumSize(200) 26 | ); 27 | return cacheManager; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-caffeine/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | # 配置数据源 5 | spring: 6 | cache: 7 | type: caffeine 8 | caffeine: 9 | spec: initialCapacity=100,maximumSize=200,expireAfterWrite=5m -------------------------------------------------------------------------------- /springboot-easyexcel/src/main/java/cn/ruiyeclub/EasyExcelApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/7/18 10:07 9 | */ 10 | @SpringBootApplication 11 | public class EasyExcelApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(EasyExcelApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-easyexcel/src/main/java/cn/ruiyeclub/entity/ExcelModel.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.alibaba.excel.annotation.ExcelProperty; 4 | import com.alibaba.excel.metadata.BaseRowModel; 5 | import lombok.Getter; 6 | import lombok.Setter; 7 | 8 | /** 9 | * 生成excel文件数据字段模板 10 | * 11 | * @author Ray。 12 | */ 13 | @Getter 14 | @Setter 15 | public class ExcelModel extends BaseRowModel { 16 | 17 | public ExcelModel() { 18 | } 19 | 20 | public ExcelModel(String dateJuly, String onDuty, String offDuty, String overtime, String last) { 21 | this.dateJuly = dateJuly; 22 | this.onDuty = onDuty; 23 | this.offDuty = offDuty; 24 | this.overtime = overtime; 25 | this.last = last; 26 | } 27 | 28 | @ExcelProperty(value = "日期", index = 0) 29 | private String dateJuly; 30 | @ExcelProperty(value = "上班时间", index = 1) 31 | private String onDuty; 32 | @ExcelProperty(value = "下班时间", index = 2) 33 | private String offDuty; 34 | @ExcelProperty(value = "加班时长", index = 3) 35 | private String overtime; 36 | @ExcelProperty(value = "备注", index = 4) 37 | private String last; 38 | 39 | } -------------------------------------------------------------------------------- /springboot-easyexcel/src/main/java/cn/ruiyeclub/listener/ModelExcelListener.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.listener; 2 | 3 | import com.alibaba.excel.context.AnalysisContext; 4 | import com.alibaba.excel.event.AnalysisEventListener; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * 模型解析监听器 每解析一行会回调invoke()方法,整个excel解析结束会执行doAfterAllAnalysed()方法 11 | * 12 | * @author Ray。 13 | */ 14 | public class ModelExcelListener extends AnalysisEventListener { 15 | 16 | private List dataList = new ArrayList(); 17 | 18 | @Override 19 | public void invoke(E object, AnalysisContext context) { 20 | dataList.add(object); 21 | } 22 | 23 | @Override 24 | public void doAfterAllAnalysed(AnalysisContext context) { 25 | } 26 | 27 | public List getDataList() { 28 | return dataList; 29 | } 30 | 31 | public void setDataList(List dataList) { 32 | this.dataList = dataList; 33 | } 34 | } -------------------------------------------------------------------------------- /springboot-easyexcel/src/main/java/cn/ruiyeclub/listener/StringExcelListener.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.listener; 2 | 3 | import com.alibaba.excel.context.AnalysisContext; 4 | import com.alibaba.excel.event.AnalysisEventListener; 5 | 6 | import java.util.ArrayList; 7 | import java.util.List; 8 | 9 | /** 10 | * StringList 解析监听器 11 | * 12 | * @author Ray。 13 | * @date 2020/1/15 11:31 14 | */ 15 | public class StringExcelListener extends AnalysisEventListener { 16 | /** 17 | * 自定义用于暂时存储data 18 | * 可以通过实例获取该值 19 | */ 20 | private List> datas = new ArrayList>(); 21 | 22 | /** 23 | * 每解析一行都会回调invoke()方法 24 | * 25 | * @param object 26 | * @param context 27 | */ 28 | @Override 29 | public void invoke(Object object, AnalysisContext context) { 30 | List stringList = (List) object; 31 | //数据存储到list,供批量处理,或后续自己业务逻辑处理。 32 | datas.add(stringList); 33 | //根据自己业务做处理 34 | } 35 | 36 | @Override 37 | public void doAfterAllAnalysed(AnalysisContext context) { 38 | //解析结束销毁不用的资源 39 | //注意不要调用datas.clear(),否则getDatas为null 40 | } 41 | 42 | public List> getDatas() { 43 | return datas; 44 | } 45 | 46 | public void setDatas(List> datas) { 47 | this.datas = datas; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /springboot-easyexcel/src/main/java/cn/ruiyeclub/utils/DataConvertUtil.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.utils; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public class DataConvertUtil { 9 | 10 | /** 11 | * @param inputStream 输入流 12 | * @Author: jinhaoxun 13 | * @Description: 将inputStream转byte[] 14 | * @Date: 2020/1/16 21:43 15 | * @Return: byte[] 16 | * @Throws: Exception 17 | */ 18 | public static byte[] inputStreamTobyte2(InputStream inputStream) throws IOException { 19 | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); 20 | byte[] buff = new byte[100]; 21 | int rc = 0; 22 | while ((rc = inputStream.read(buff, 0, 100)) > 0) { 23 | byteArrayOutputStream.write(buff, 0, rc); 24 | } 25 | return byteArrayOutputStream.toByteArray(); 26 | } 27 | 28 | /** 29 | * @param bytes byte数组 30 | * @Author: jinhaoxun 31 | * @Description: 将byte[]转inputStream 32 | * @Date: 2020/1/16 21:43 33 | * @Return: InputStream 34 | * @Throws: Exception 35 | */ 36 | public static InputStream byte2ToInputStream(byte[] bytes) { 37 | return new ByteArrayInputStream(bytes); 38 | } 39 | } -------------------------------------------------------------------------------- /springboot-easyexcel/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 -------------------------------------------------------------------------------- /springboot-fastjson2/README.md: -------------------------------------------------------------------------------- 1 | fastjson2常用方法 2 | https://juejin.cn/post/7096659855217262622 -------------------------------------------------------------------------------- /springboot-flyway/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot整合flyway 2 | https://www.cnblogs.com/woyujiezhen/p/13025018.html -------------------------------------------------------------------------------- /springboot-flyway/src/main/java/cn/ruiyeclub/FlywayApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2021/1/20 9 | */ 10 | @SpringBootApplication 11 | public class FlywayApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(FlywayApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-flyway/src/main/java/cn/ruiyeclub/entity/User.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.extension.activerecord.Model; 6 | import lombok.AllArgsConstructor; 7 | import lombok.Data; 8 | 9 | @Data 10 | @AllArgsConstructor 11 | public class User extends Model { 12 | 13 | @TableId(type = IdType.AUTO) 14 | private Long id; 15 | private String name; 16 | private Integer age; 17 | 18 | } -------------------------------------------------------------------------------- /springboot-flyway/src/main/java/cn/ruiyeclub/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.mapper; 2 | 3 | import cn.ruiyeclub.entity.User; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * @Author: Ray。 9 | * @Date: 2021/1/20 10 | */ 11 | @Mapper 12 | public interface UserMapper extends BaseMapper { 13 | } 14 | -------------------------------------------------------------------------------- /springboot-flyway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: root 11 | flyway: 12 | baseline-on-migrate: true -------------------------------------------------------------------------------- /springboot-flyway/src/main/resources/db/migration/V1__Base_version.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS user ; 2 | CREATE TABLE `user` ( 3 | `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', 4 | `name` varchar(20) NOT NULL COMMENT '姓名', 5 | `age` int(5) DEFAULT NULL COMMENT '年龄', 6 | PRIMARY KEY (`id`) 7 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -------------------------------------------------------------------------------- /springboot-flyway/src/test/java/cn/ruiyeclub/UserTests.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import cn.ruiyeclub.entity.User; 4 | import cn.ruiyeclub.mapper.UserMapper; 5 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.junit.jupiter.api.Test; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | 10 | import javax.annotation.Resource; 11 | 12 | /** 13 | * @Author: Ray。 14 | * @Date: 2021/1/20 15 | */ 16 | @Slf4j 17 | @SpringBootTest 18 | public class UserTests { 19 | 20 | @Resource 21 | private UserMapper userMapper; 22 | 23 | @Test 24 | public void test() throws Exception { 25 | // 插入2个用户 26 | userMapper.insert(new User(1L, "Tom", 10)); 27 | userMapper.insert(new User(2L, "Mike", 11)); 28 | 29 | // 查数据库,应该有5个用户 30 | userMapper.selectList(new LambdaQueryWrapper<>()); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /springboot-hibernate-validator/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot整合Hibernate Validator实现参数验证功能 2 | https://www.cnblogs.com/ruiyeclub/p/13141467.html -------------------------------------------------------------------------------- /springboot-hibernate-validator/src/main/java/cn/ruiyeclub/HibernateValidatorApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HibernateValidatorApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HibernateValidatorApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-hibernate-validator/src/main/java/cn/ruiyeclub/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.entity.UserModel; 4 | import org.springframework.validation.BindingResult; 5 | import org.springframework.validation.ObjectError; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.validation.Valid; 12 | 13 | /** 14 | * @author Ray。 15 | * @version 1.0 16 | * @date 2020/5/29 19:22 17 | */ 18 | @RestController 19 | public class TestController { 20 | 21 | @GetMapping("/test") 22 | public Object test(@Valid UserModel userModel){ 23 | return userModel; 24 | } 25 | 26 | @PostMapping("/testPost") 27 | public Object testPost(@RequestBody @Valid UserModel userModel){ 28 | return userModel; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-hibernate-validator/src/main/java/cn/ruiyeclub/entity/UserModel.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import lombok.Data; 4 | import org.hibernate.validator.constraints.Range; 5 | import org.springframework.format.annotation.DateTimeFormat; 6 | 7 | import javax.validation.constraints.NotNull; 8 | import java.util.Date; 9 | 10 | /** 11 | * @description: 12 | * @author: Ray。 13 | * @create: 2020-01-17 15:17 14 | */ 15 | @Data 16 | public class UserModel { 17 | 18 | @NotNull(message = "用户名称不能为空!") 19 | private String userName; 20 | 21 | @NotNull(message = "age不能为null!") 22 | @Range(min = 1, max = 888, message = "范围为1至888") 23 | private Integer age; 24 | 25 | /** 26 | * 日期格式化转换 27 | */ 28 | @NotNull(message = "日期不能为null!") 29 | @DateTimeFormat(pattern = "yyyy-MM-dd") 30 | private Date date; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /springboot-hibernate-validator/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8080 2 | 3 | #\u65E5\u671F\u683C\u5F0F\u7684\u5904\u7406 4 | spring.jackson.default-property-inclusion=non_null 5 | spring.jackson.date-format= yyyy-MM-dd HH:mm:ss 6 | spring.jackson.time-zone=GMT+8 -------------------------------------------------------------------------------- /springboot-hibernate-validator/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ┏┓   ┏┓ 2 | ┏┛┻━━━┛┻┓ 3 | ┃       ┃   4 | ┃   ━   ┃ 5 | ┃ ┳┛ ┗┳ ┃ 6 | ┃       ┃ 7 | ┃   ┻   ┃ 8 | ┃       ┃ 9 | ┗━┓   ┏━┛ 10 | ┃   ┃ 神兽保佑         11 | ┃   ┃ 代码无BUG! 12 | ┃   ┗━━━┓ 13 | ┃       ┣┓ 14 | ┃       ┏┛ 15 | ┗┓┓┏━┳┓┏┛ 16 | ┃┫┫ ┃┫┫ 17 | ┗┻┛ -------------------------------------------------------------------------------- /springboot-hutool/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | springboot-hello 7 | cn.ruiyeclub 8 | 2.0.0-SNAPSHOT 9 | 10 | 11 | 12 | UTF-8 13 | UTF-8 14 | 1.8 15 | 16 | 4.0.0 17 | 18 | 19 | springboot-hutool 20 | 21 | 22 | 23 | cn.hutool 24 | hutool-all 25 | 5.8.21 26 | 27 | 28 | 29 | org.projectlombok 30 | lombok 31 | 1.18.12 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/entity/PmsBrand.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @Author: Ray。 7 | * @Date: 2021/1/26 8 | */ 9 | @Data 10 | public class PmsBrand { 11 | 12 | private Integer id; 13 | private String name; 14 | private Integer showStatus; 15 | } 16 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/AnnotationUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.crypto.digest.HMac; 4 | import cn.hutool.crypto.digest.HmacAlgorithm; 5 | 6 | 7 | /** 8 | * 注解工具类,可用于获取注解与注解中指定的值。 9 | * @Author: Ray。 10 | * @Date: 2021/1/26 11 | */ 12 | public class AnnotationUtilTest { 13 | 14 | public static void main(String[] args) { 15 | String testStr = "test中文"; 16 | 17 | // 此处密钥如果有非ASCII字符,考虑编码 18 | byte[] key = "password".getBytes(); 19 | HMac mac = new HMac(HmacAlgorithm.HmacMD5, key); 20 | 21 | // b977f4b13f93f549e06140971bded384 22 | String macHex1 = mac.digestHex(testStr); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/BeanUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.bean.BeanUtil; 4 | import cn.ruiyeclub.entity.PmsBrand; 5 | 6 | import java.util.Map; 7 | 8 | /** 9 | * JavaBean工具类,可用于Map与JavaBean对象的互相转换以及对象属性的拷贝。 10 | * @Author: Ray。 11 | * @Date: 2021/1/26 12 | */ 13 | public class BeanUtilTest { 14 | 15 | public static void main(String[] args) { 16 | PmsBrand brand = new PmsBrand(); 17 | brand.setId(1); 18 | brand.setName("小米"); 19 | brand.setShowStatus(0); 20 | 21 | //Bean转Map 22 | Map map = BeanUtil.beanToMap(brand); 23 | System.out.println("beanUtil bean to map:"+map); 24 | 25 | //Map转Bean 26 | PmsBrand mapBrand = BeanUtil.mapToBean(map, PmsBrand.class, false); 27 | System.out.println("beanUtil map to bean:"+mapBrand); 28 | 29 | //Bean属性拷贝 30 | PmsBrand copyBrand = new PmsBrand(); 31 | BeanUtil.copyProperties(brand, copyBrand); 32 | System.out.println("beanUtil copy properties:"+copyBrand); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/ClassPathResourceTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.io.resource.ClassPathResource; 4 | 5 | import java.io.IOException; 6 | import java.util.Properties; 7 | 8 | /** 9 | * ClassPath单一资源访问类,可以获取classPath下的文件,在Tomcat等容器下,classPath一般是WEB-INF/classes。 10 | * @Author: Ray。 11 | * @Date: 2021/1/26 12 | */ 13 | public class ClassPathResourceTest { 14 | 15 | public static void main(String[] args) throws IOException { 16 | //获取定义在src/main/resources文件夹中的配置文件 17 | ClassPathResource resource = new ClassPathResource("application.yml"); 18 | Properties properties = new Properties(); 19 | properties.load(resource.getStream()); 20 | System.out.println("classPath:"+properties); 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/CollUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.collection.CollUtil; 4 | import cn.hutool.core.util.StrUtil; 5 | 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.HashSet; 9 | import java.util.List; 10 | 11 | /** 12 | * 集合操作的工具类,定义了一些常用的集合操作。 13 | * @Author: Ray。 14 | * @Date: 2021/1/26 15 | */ 16 | public class CollUtilTest { 17 | 18 | public static void main(String[] args) { 19 | //数组转换为列表 20 | String[] array = new String[]{"a", "b", "c", "d", "e"}; 21 | List list = CollUtil.newArrayList(array); 22 | 23 | //join:数组转字符串时添加连接符号 24 | String joinStr = CollUtil.join(list, ","); 25 | System.out.println("collUtil join:"+joinStr); 26 | 27 | //将以连接符号分隔的字符串再转换为列表 28 | List splitList = StrUtil.split(joinStr, ','); 29 | System.out.println("collUtil split:"+splitList); 30 | 31 | //创建新的Map、Set、List 32 | HashMap newMap = CollUtil.newHashMap(); 33 | HashSet newHashSet = CollUtil.newHashSet(); 34 | ArrayList newList = CollUtil.newArrayList(); 35 | //判断列表是否为空 36 | CollUtil.isEmpty(list); 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/ConvertTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.convert.Convert; 4 | 5 | import java.util.Date; 6 | import java.util.List; 7 | 8 | /** 9 | * 类型转换工具类,用于各种类型数据的转换。 10 | * @Author: Ray。 11 | * @Date: 2021/1/26 12 | */ 13 | public class ConvertTest { 14 | 15 | public static void main(String[] args) { 16 | //转换为字符串 17 | int a = 1; 18 | String aStr = Convert.toStr(a); 19 | 20 | //转换为指定类型数组 21 | String[] b = {"1", "2", "3", "4"}; 22 | Integer[] bArr = Convert.toIntArray(b); 23 | 24 | //转换为日期对象 25 | String dateStr = "2017-05-06"; 26 | Date date = Convert.toDate(dateStr); 27 | 28 | //转换为列表 29 | String[] strArr = {"a", "b", "c", "d"}; 30 | List strList = Convert.toList(String.class, strArr); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/DigestUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.crypto.digest.DigestUtil; 4 | 5 | /** 6 | * 摘要算法工具类,支持MD5、SHA-256、Bcrypt等算法。 7 | * @Author: Ray。 8 | * @Date: 2021/4/20 9 | */ 10 | public class DigestUtilTest { 11 | 12 | public static void main(String[] args) { 13 | String password = "123456"; 14 | //计算MD5摘要值,并转为16进制字符串 15 | String result = DigestUtil.md5Hex(password); 16 | System.out.println("DigestUtil md5Hex:"+result); 17 | 18 | //计算SHA-256摘要值,并转为16进制字符串 19 | result = DigestUtil.sha256Hex(password); 20 | System.out.println("DigestUtil sha256Hex:"+result); 21 | 22 | //生成Bcrypt加密后的密文,并校验 23 | String hashPwd = DigestUtil.bcrypt(password); 24 | boolean check = DigestUtil.bcryptCheck(password,hashPwd); 25 | System.out.println("DigestUtil bcryptCheck:"+check); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/HttpUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.http.HttpUtil; 4 | 5 | /** 6 | * Http请求工具类,可以发起GET/POST等请求。 7 | * @Author: Ray。 8 | * @Date: 2021/4/20 9 | */ 10 | public class HttpUtilTest { 11 | public static void main(String[] args) { 12 | String response = HttpUtil.get("http://localhost:8080/hutool/covert"); 13 | System.out.println("HttpUtil get:"+response); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/JSONUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.json.JSONArray; 4 | import cn.hutool.json.JSONUtil; 5 | import cn.ruiyeclub.entity.PmsBrand; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * JSON解析工具类,可用于对象与JSON之间的互相转化。 12 | * @Author: Ray。 13 | * @Date: 2021/1/26 14 | */ 15 | public class JSONUtilTest { 16 | 17 | public static void main(String[] args) { 18 | PmsBrand brand = new PmsBrand(); 19 | brand.setId(1); 20 | brand.setName("小米"); 21 | brand.setShowStatus(1); 22 | //对象转化为JSON字符串 23 | String jsonStr = JSONUtil.parse(brand).toString(); 24 | System.out.println("jsonUtil parse:"+jsonStr); 25 | 26 | //JSON字符串转化为对象 27 | PmsBrand brandBean = JSONUtil.toBean(jsonStr, PmsBrand.class); 28 | System.out.println("jsonUtil toBean:"+brandBean); 29 | List brandList = new ArrayList(); 30 | brandList.add(brand); 31 | String jsonListStr = JSONUtil.parse(brandList).toString(); 32 | 33 | //JSON字符串转化为列表 34 | brandList = JSONUtil.toList(new JSONArray(jsonListStr), PmsBrand.class); 35 | System.out.println("jsonUtil toList:"+brandList); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/MapUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.map.MapUtil; 4 | 5 | import java.util.Map; 6 | 7 | /** 8 | * Map操作工具类,可用于创建Map对象及判断Map是否为空。 9 | * @Author: Ray。 10 | * @Date: 2021/1/26 11 | */ 12 | public class MapUtilTest { 13 | 14 | public static void main(String[] args) { 15 | //将多个键值对加入到Map中 16 | Map map = MapUtil.of(new String[][]{ 17 | {"key1", "value1"}, 18 | {"key2", "value2"}, 19 | {"key3", "value3"} 20 | }); 21 | 22 | //判断Map是否为空 23 | System.out.println(MapUtil.isEmpty(map)); 24 | MapUtil.isNotEmpty(map); 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/NumberUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.util.NumberUtil; 4 | 5 | import java.math.BigDecimal; 6 | 7 | /** 8 | * 数字处理工具类,可用于各种类型数字的加减乘除操作及类型判断。 9 | * @Author: Ray。 10 | * @Date: 2021/1/26 11 | */ 12 | public class NumberUtilTest { 13 | 14 | public static void main(String[] args) { 15 | double n1 = 1.234; 16 | double n2 = 1.234; 17 | double result; 18 | //对float、double、BigDecimal做加减乘除操作 19 | result = NumberUtil.add(n1, n2); 20 | result = NumberUtil.sub(n1, n2); 21 | result = NumberUtil.mul(n1, n2); 22 | result = NumberUtil.div(n1, n2); 23 | 24 | //保留两位小数 25 | BigDecimal roundNum = NumberUtil.round(n1, 2); 26 | String n3 = "1.234"; 27 | //判断是否为数字、整数、浮点数 28 | NumberUtil.isNumber(n3); 29 | NumberUtil.isInteger(n3); 30 | NumberUtil.isDouble(n3); 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/ReflectUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.util.ReflectUtil; 4 | import cn.ruiyeclub.entity.PmsBrand; 5 | 6 | import java.lang.reflect.Method; 7 | 8 | /** 9 | * Java反射工具类,可用于反射获取类的方法及创建对象。 10 | * @Author: Ray。 11 | * @Date: 2021/1/26 12 | */ 13 | public class ReflectUtilTest { 14 | 15 | public static void main(String[] args) { 16 | //获取某个类的所有方法 17 | Method[] methods = ReflectUtil.getMethods(PmsBrand.class); 18 | //获取某个类的指定方法 19 | Method method = ReflectUtil.getMethod(PmsBrand.class, "getId"); 20 | //使用反射来创建对象 21 | PmsBrand pmsBrand = ReflectUtil.newInstance(PmsBrand.class); 22 | //反射执行对象的方法 23 | ReflectUtil.invoke(pmsBrand, "setId", 1); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/SecureUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.crypto.SecureUtil; 4 | 5 | /** 6 | * 加密解密工具类,可用于MD5加密。 7 | * @Author: Ray。 8 | * @Date: 2021/4/20 9 | */ 10 | public class SecureUtilTest { 11 | 12 | public static void main(String[] args) { 13 | //MD5加密 14 | String str = "123456"; 15 | String md5Str = SecureUtil.md5(str); 16 | System.out.println("secureUtil md5:"+md5Str); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/StrUtilTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.util.StrUtil; 4 | 5 | /** 6 | * 字符串工具类,定义了一些常用的字符串操作方法。StrUtil比StringUtil名称更短,用起来也更方便! 7 | * @Author: Ray。 8 | * @Date: 2021/1/26 9 | */ 10 | public class StrUtilTest { 11 | 12 | public static void main(String[] args) { 13 | //判断是否为空字符串 14 | String str = "test"; 15 | StrUtil.isEmpty(str); 16 | StrUtil.isNotEmpty(str); 17 | 18 | //去除字符串的前后缀 19 | System.out.println(StrUtil.removeSuffix("a.jpg", ".jpg")); 20 | System.out.println(StrUtil.removePrefix("a.jpg", "a.")); 21 | 22 | //格式化字符串 23 | String template = "这只是个占位符:{}"; 24 | String str2 = StrUtil.format(template, "我是占位符"); 25 | System.out.println("strUtil format:"+str2); 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/java/cn/ruiyeclub/hutool/ValidatorTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hutool; 2 | 3 | import cn.hutool.core.lang.Validator; 4 | 5 | /** 6 | * 字段验证器,可以对不同格式的字符串进行验证,比如邮箱、手机号、IP等格式。 7 | * @Author: Ray。 8 | * @Date: 2021/4/20 9 | */ 10 | public class ValidatorTest { 11 | 12 | public static void main(String[] args) { 13 | //判断是否为邮箱地址 14 | boolean result = Validator.isEmail("macro@qq.com"); 15 | System.out.println("Validator isEmail:"+result); 16 | //判断是否为手机号码 17 | result = Validator.isMobile("18911111111"); 18 | System.out.println("Validator isMobile:"+result); 19 | //判断是否为IPV4地址 20 | result = Validator.isIpv4("192.168.3.101"); 21 | System.out.println("Validator isIpv4:"+result); 22 | //判断是否为汉字 23 | result = Validator.isChinese("你好"); 24 | System.out.println("Validator isChinese:"+result); 25 | //判断是否为身份证号码(18位中国) 26 | result = Validator.isCitizenId("123456"); 27 | System.out.println("Validator isCitizenId:"+result); 28 | //判断是否为URL 29 | result = Validator.isUrl("http://www.baidu.com"); 30 | System.out.println("Validator isUrl:"+result); 31 | //判断是否为生日 32 | result = Validator.isBirthday("2020-02-01"); 33 | System.out.println("Validator isBirthday:"+result); 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-hutool/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | hutool: 2 | test: sdfs -------------------------------------------------------------------------------- /springboot-i18n/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot 快速支持国际化i18n 2 | https://www.jianshu.com/p/e2eae08f3255 -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/cn/ruiyeclub/I18nApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/8/4 17:04 9 | */ 10 | @SpringBootApplication 11 | public class I18nApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(I18nApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/cn/ruiyeclub/config/LocaleConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.LocaleResolver; 6 | import org.springframework.web.servlet.i18n.SessionLocaleResolver; 7 | 8 | import java.util.Locale; 9 | 10 | /** 11 | * 配置国际化语言 12 | * @author Ray。 13 | * @date 2020/8/4 17:15 14 | */ 15 | @Configuration 16 | public class LocaleConfig { 17 | 18 | /** 19 | * 默认解析器 其中locale表示默认语言 20 | */ 21 | @Bean 22 | public LocaleResolver localeResolver() { 23 | SessionLocaleResolver localeResolver = new SessionLocaleResolver(); 24 | //默认中文 25 | localeResolver.setDefaultLocale(Locale.CHINA); 26 | return localeResolver; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/cn/ruiyeclub/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.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 | import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; 7 | 8 | /** 9 | * Web相关配置 10 | * @author Ray。 11 | */ 12 | @Configuration 13 | public class WebMvcConfig implements WebMvcConfigurer { 14 | 15 | /** 16 | * 默认拦截器 其中lang表示切换语言的参数名 17 | */ 18 | @Override 19 | public void addInterceptors(InterceptorRegistry registry) { 20 | LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor(); 21 | localeInterceptor.setParamName("lang"); 22 | registry.addInterceptor(localeInterceptor); 23 | } 24 | } -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/cn/ruiyeclub/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.utils.MessageUtils; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020/8/4 18:01 10 | */ 11 | @RestController 12 | @RequestMapping("/i18n") 13 | public class HelloController { 14 | 15 | @RequestMapping("/user") 16 | public String getUserName() { 17 | return MessageUtils.get("user.username"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-i18n/src/main/java/cn/ruiyeclub/utils/MessageUtils.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.utils; 2 | 3 | import org.springframework.context.MessageSource; 4 | import org.springframework.context.i18n.LocaleContextHolder; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * 国际化工具类 9 | */ 10 | @Component 11 | public class MessageUtils { 12 | 13 | private static MessageSource messageSource; 14 | 15 | public MessageUtils(MessageSource messageSource) { 16 | MessageUtils.messageSource = messageSource; 17 | } 18 | 19 | /** 20 | * 获取单个国际化翻译值 21 | */ 22 | public static String get(String msgKey) { 23 | try { 24 | return messageSource.getMessage(msgKey, null, LocaleContextHolder.getLocale()); 25 | } catch (Exception e) { 26 | System.out.println(e); 27 | return msgKey; 28 | } 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/application.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruiyeclub/SpringBoot-Hello/f4065f86b42dfa17e27181280360b53b08e322ca/springboot-i18n/src/main/resources/application.yml -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | #\u8FD9\u91CC\u586B\u5199\u9ED8\u8BA4\u7FFB\u8BD1\uFF0C\u5185\u5BB9\u53EF\u4EE5\u7559\u7A7A\uFF0C\u4F46\u6587\u4EF6\u5FC5\u987B\u5B58\u5728\u3002 -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/messages_en_US.properties: -------------------------------------------------------------------------------- 1 | #\u8FD9\u91CC\u586B\u5199\u82F1\u8BED\u7FFB\u8BD1\u3002 2 | user.title=User Login 3 | user.welcome=Welcome 4 | user.username=Username 5 | user.password=Password 6 | user.login=Sign In -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/messages_zh_CN.properties: -------------------------------------------------------------------------------- 1 | #\u8FD9\u91CC\u586B\u5199\u4E2D\u6587\u7FFB\u8BD1 2 | user.title=\u7528\u6237\u767B\u9646 3 | user.welcome=\u6B22\u8FCE 4 | user.username=\u767B\u9646\u7528\u6237 5 | user.password=\u767B\u9646\u5BC6\u7801 6 | user.login=\u767B\u9646 -------------------------------------------------------------------------------- /springboot-i18n/src/main/resources/messages_zh_TW.properties: -------------------------------------------------------------------------------- 1 | #\u8FD9\u91CC\u586B\u5199\u7E41\u4F53\u7FFB\u8BD1 2 | user.title=\u7528\u6236\u767B\u9678 3 | user.welcome=\u6B61\u8FCE 4 | user.username=\u767B\u9678\u7528\u6236 5 | user.password=\u767B\u9678\u5BC6\u78BC 6 | user.login=\u767B\u9678 -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/JApiDocsApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020/7/18 10:07 10 | */ 11 | @SpringBootApplication 12 | @MapperScan(basePackages = {"cn.ruiyeclub.dao"}) 13 | public class JApiDocsApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(JApiDocsApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020-07-17 21:57 10 | */ 11 | @Configuration 12 | public class MybatisPlusConfig { 13 | /** 14 | * 分页插件 15 | * @return 16 | */ 17 | @Bean 18 | public PaginationInterceptor paginationInterceptor(){ 19 | return new PaginationInterceptor(); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (UserRecord)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @date 2020-07-18 10:15:36 11 | */ 12 | public interface UserRecordDao extends BaseMapper { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import lombok.Data; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * (UserRecord)表实体类 10 | * 11 | * @author Ray。 12 | * @date 2020-07-18 10:15:34 13 | */ 14 | @Data 15 | public class UserRecord extends Model implements Serializable { 16 | 17 | /** 18 | * 主键 19 | */ 20 | private Integer id; 21 | /** 22 | * 名称 23 | */ 24 | private String name; 25 | /** 26 | * 年龄 27 | */ 28 | private Integer age; 29 | /** 30 | * 邮箱 31 | */ 32 | private String email; 33 | } -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (UserRecord)表服务接口 8 | * 9 | * @author Ray。 10 | * @date 2020-07-18 10:15:37 11 | */ 12 | public interface UserRecordService extends IService { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/service/impl/UserRecordServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.UserRecordDao; 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (UserRecord)表服务实现类 11 | * 12 | * @author Ray。 13 | * @date 2020-07-18 10:15:37 14 | */ 15 | @Service("userRecordService") 16 | public class UserRecordServiceImpl extends ServiceImpl implements UserRecordService { 17 | 18 | } -------------------------------------------------------------------------------- /springboot-japidocs/src/main/java/cn/ruiyeclub/util/DocUtil.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.util; 2 | 3 | import io.github.yedaxia.apidocs.Docs; 4 | import io.github.yedaxia.apidocs.DocsConfig; 5 | import io.github.yedaxia.apidocs.plugin.markdown.MarkdownDocPlugin; 6 | 7 | /** 8 | * 接口文档自动生成工具 9 | * @author Ray。 10 | */ 11 | public class DocUtil { 12 | 13 | public static void main(String[] args) { 14 | DocsConfig config = new DocsConfig(); 15 | // 项目根目录 16 | config.setProjectPath("你的项目路径"); 17 | // 项目名称 18 | config.setProjectName("springboot-japidocs"); 19 | // 声明该API的版本 20 | config.setApiVersion("V1.0.3"); 21 | //生成API 文档所在目录 22 | config.setDocsPath("C:\\新建文件夹1"); 23 | // 配置自动生成 24 | config.setAutoGenerate(Boolean.TRUE); 25 | // 执行生成文档 26 | config.addPlugin(new MarkdownDocPlugin()); 27 | Docs.buildHtmlDocs(config); 28 | } 29 | } -------------------------------------------------------------------------------- /springboot-japidocs/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: root -------------------------------------------------------------------------------- /springboot-jpa/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot2.0之三 优雅整合Spring Data JPA 2 | https://segmentfault.com/a/1190000015266872 -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/cn/ruiyeclub/JpaApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/7/17 19:46 9 | */ 10 | @SpringBootApplication 11 | public class JpaApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(JpaApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/cn/ruiyeclub/controller/UserRecordController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.annotation.Resource; 12 | import java.util.List; 13 | 14 | /** 15 | * (UserRecord)表控制层 16 | * @author Ray。 17 | * @date 2020-07-22 14:06:53 18 | */ 19 | @RestController 20 | @RequestMapping("user") 21 | public class UserRecordController{ 22 | /** 23 | * 服务对象 24 | */ 25 | @Resource 26 | private UserRecordService userRecordService; 27 | 28 | /** 29 | * 查询所有数据 30 | * @return 所有数据 31 | */ 32 | @GetMapping("/list") 33 | public List findAll() { 34 | return userRecordService.findAll(); 35 | } 36 | 37 | @GetMapping("/{id}") 38 | public UserRecord getUser(@PathVariable("id") Integer id){ 39 | return userRecordService.getUser(id); 40 | } 41 | } -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | import org.springframework.data.jpa.repository.Query; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.stereotype.Repository; 8 | 9 | /** 10 | * (UserRecord)表数据库访问层 11 | * 12 | * @author Ray。 13 | * @date 2020-07-22 14:06:51 14 | */ 15 | @Repository 16 | public interface UserRecordDao extends JpaRepository { 17 | 18 | @Query(value = "select * from user_record where id =:id ", nativeQuery = true) 19 | UserRecord getUser(@Param("id") Integer id); 20 | 21 | /** 22 | * 根据年纪查询用户 23 | * @param age 24 | * @return 25 | */ 26 | UserRecord findByAge(Integer age); 27 | 28 | /** 29 | * 根据年纪和姓名查询 30 | * @param name 31 | * @param age 32 | * @return 33 | */ 34 | UserRecord findByNameAndAge(String name, Integer age); 35 | } -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | 9 | /** 10 | * (UserRecord)表实体类 11 | * 12 | * @author Ray。 13 | * @date 2020-07-22 14:06:49 14 | */ 15 | @Data 16 | @Entity 17 | public class UserRecord{ 18 | 19 | /** 20 | * 声明id 21 | */ 22 | @Id 23 | @GeneratedValue 24 | private Integer id; 25 | 26 | private String name; 27 | 28 | private Integer age; 29 | 30 | private String email; 31 | } -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * (UserRecord)表服务接口 9 | * 10 | * @author Ray。 11 | * @date 2020-07-22 14:06:52 12 | */ 13 | public interface UserRecordService { 14 | 15 | List findAll(); 16 | 17 | UserRecord getUser(Integer id); 18 | } -------------------------------------------------------------------------------- /springboot-jpa/src/main/java/cn/ruiyeclub/service/impl/UserRecordServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.UserRecordDao; 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | import java.util.List; 10 | 11 | /** 12 | * (UserRecord)表服务实现类 13 | * 14 | * @author Ray。 15 | * @date 2020-07-22 14:06:53 16 | */ 17 | @Service 18 | public class UserRecordServiceImpl implements UserRecordService { 19 | 20 | @Resource 21 | private UserRecordDao userRecordDao; 22 | 23 | @Override 24 | public List findAll() { 25 | return userRecordDao.findAll(); 26 | } 27 | 28 | @Override 29 | public UserRecord getUser(Integer id) { 30 | return userRecordDao.getUser(id); 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /springboot-jpa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: root 11 | jpa: 12 | hibernate: 13 | ddl-auto: update #第一次建表create 后面用update,要不然每次重启都会新建表 14 | show-sql: true -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/cn/ruiyeclub/TokenApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | @SpringBootApplication 8 | @MapperScan("cn.ruiyeclub.dao") 9 | public class TokenApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(TokenApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/cn/ruiyeclub/annotation/CheckToken.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 需要进行token验证 10 | * 11 | * @author Raychen 12 | * @date 2020/5/24 10:48 13 | */ 14 | @Target({ElementType.METHOD, ElementType.TYPE}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface CheckToken { 17 | boolean required() default true; 18 | } 19 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/cn/ruiyeclub/annotation/LoginToken.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * login方法上加 10 | * 11 | * @author Raychen 12 | * @date 2020/5/24 10:45 13 | */ 14 | @Target({ElementType.METHOD, ElementType.TYPE}) 15 | @Retention(RetentionPolicy.RUNTIME) 16 | public @interface LoginToken { 17 | boolean required() default true; 18 | } 19 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/cn/ruiyeclub/config/InterceptorConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import cn.ruiyeclub.interceptor.AuthenticationInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 8 | 9 | /** 10 | * 拦截所有请求 去拦截器 11 | * 12 | * @author Ray。 13 | * @create 2020-05-24 10:52 14 | */ 15 | @Configuration 16 | public class InterceptorConfig implements WebMvcConfigurer { 17 | 18 | 19 | @Override 20 | public void addInterceptors(InterceptorRegistry registry) { 21 | registry.addInterceptor(authenticationInterceptor()) 22 | // 拦截所有请求,通过判断是否有 @LoginRequired 注解 决定是否需要登录 23 | .addPathPatterns("/**"); 24 | } 25 | 26 | @Bean 27 | public AuthenticationInterceptor authenticationInterceptor() { 28 | return new AuthenticationInterceptor(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/java/cn/ruiyeclub/service/UserService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * (User)表服务接口 9 | * 10 | * @author Ray。 11 | * @since 2020-05-24 11:01:01 12 | */ 13 | public interface UserService { 14 | 15 | /** 16 | * 通过ID查询单条数据 17 | * 18 | * @param id 主键 19 | * @return 实例对象 20 | */ 21 | User queryById(Integer id); 22 | 23 | /** 24 | * 查询多条数据 25 | * 26 | * @param offset 查询起始位置 27 | * @param limit 查询条数 28 | * @return 对象列表 29 | */ 30 | List queryAllByLimit(int offset, int limit); 31 | 32 | /** 33 | * 新增数据 34 | * 35 | * @param user 实例对象 36 | * @return 实例对象 37 | */ 38 | User insert(User user); 39 | 40 | /** 41 | * 修改数据 42 | * 43 | * @param user 实例对象 44 | * @return 实例对象 45 | */ 46 | User update(User user); 47 | 48 | /** 49 | * 通过主键删除数据 50 | * 51 | * @param id 主键 52 | * @return 是否成功 53 | */ 54 | boolean deleteById(Integer id); 55 | 56 | User findUserById(String userId); 57 | 58 | User findByUsername(User user); 59 | } 60 | -------------------------------------------------------------------------------- /springboot-jwt/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=80 2 | 3 | ##\u6570\u636E\u5E93\u8FDE\u63A5\u4FE1\u606F 4 | spring.datasource.url=jdbc:mysql://localhost/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 5 | spring.datasource.username=root 6 | spring.datasource.password=root 7 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 8 | mybatis.mapper-locations=classpath:mapper/*.xml 9 | 10 | #\u63A7\u5236\u53F0\u6253\u5370sql 11 | logging.level.cn.ruiyeclub.dao=debug 12 | -------------------------------------------------------------------------------- /springboot-kaptcha/src/main/java/cn/ruiyeclub/KaptchaApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class KaptchaApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(KaptchaApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot-kaptcha/src/main/java/cn/ruiyeclub/controller/LoginController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.dto.LoginDTO; 4 | import cn.ruiyeclub.service.CaptchaService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.RequestBody; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.servlet.http.HttpServletResponse; 12 | import java.io.IOException; 13 | 14 | /** 15 | * 登录 16 | */ 17 | @RestController 18 | public class LoginController { 19 | 20 | @Autowired 21 | private CaptchaService captchaService; 22 | 23 | @GetMapping("captcha") 24 | public void captcha(HttpServletResponse response, String uuid) throws IOException { 25 | //生成验证码 26 | captchaService.create(response, uuid); 27 | } 28 | 29 | @PostMapping("login") 30 | public String login(@RequestBody LoginDTO login) { 31 | //验证码是否正确 32 | boolean flag = captchaService.validate(login.getUuid(), login.getCaptcha()); 33 | if (!flag) { 34 | return "验证码错误"; 35 | } 36 | return "ok"; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /springboot-kaptcha/src/main/java/cn/ruiyeclub/dto/LoginDTO.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * 登录表单 9 | */ 10 | @Data 11 | public class LoginDTO implements Serializable { 12 | private static final long serialVersionUID = 1L; 13 | 14 | private String captcha; 15 | 16 | private String uuid; 17 | } -------------------------------------------------------------------------------- /springboot-kaptcha/src/main/java/cn/ruiyeclub/service/CaptchaService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import javax.servlet.http.HttpServletResponse; 4 | import java.io.IOException; 5 | 6 | /** 7 | * 验证码 8 | */ 9 | public interface CaptchaService { 10 | 11 | /** 12 | * 图片验证码 13 | */ 14 | void create(HttpServletResponse response, String uuid) throws IOException; 15 | 16 | /** 17 | * 验证码效验 18 | * 19 | * @param uuid uuid 20 | * @param code 验证码 21 | * @return true:成功 false:失败 22 | */ 23 | boolean validate(String uuid, String code); 24 | } 25 | -------------------------------------------------------------------------------- /springboot-kaptcha/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Tomcat 2 | server: 3 | tomcat: 4 | uri-encoding: UTF-8 5 | threads: 6 | max: 1000 7 | min-spare: 30 8 | port: 80 9 | spring: 10 | redis: 11 | database: 0 12 | host: localhost 13 | port: 6379 14 | # 是否开启redis缓存 true开启 false关闭 15 | sys: 16 | redis: 17 | open: true -------------------------------------------------------------------------------- /springboot-knife4j/src/main/java/cn/ruiyeclub/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020-07-17 21:57 10 | */ 11 | @Configuration 12 | public class MybatisPlusConfig { 13 | /** 14 | * 分页插件 15 | * @return 16 | */ 17 | @Bean 18 | public PaginationInterceptor paginationInterceptor(){ 19 | return new PaginationInterceptor(); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-knife4j/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (UserRecord)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @date 2020-07-18 10:15:36 11 | */ 12 | public interface UserRecordDao extends BaseMapper { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-knife4j/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | 7 | /** 8 | * (UserRecord)表实体类 9 | * 10 | * @author Ray。 11 | * @date 2020-07-18 10:15:34 12 | */ 13 | @ApiModel("(UserRecord)表实体类") 14 | public class UserRecord extends Model { 15 | 16 | @ApiModelProperty("主键") 17 | private Integer id; 18 | 19 | @ApiModelProperty("名称") 20 | private String name; 21 | 22 | @ApiModelProperty("年龄") 23 | private Integer age; 24 | 25 | @ApiModelProperty("邮箱") 26 | private String email; 27 | 28 | 29 | public Integer getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Integer id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public Integer getAge() { 46 | return age; 47 | } 48 | 49 | public void setAge(Integer age) { 50 | this.age = age; 51 | } 52 | 53 | public String getEmail() { 54 | return email; 55 | } 56 | 57 | public void setEmail(String email) { 58 | this.email = email; 59 | } 60 | } -------------------------------------------------------------------------------- /springboot-knife4j/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (UserRecord)表服务接口 8 | * 9 | * @author Ray。 10 | * @date 2020-07-18 10:15:37 11 | */ 12 | public interface UserRecordService extends IService { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-knife4j/src/main/java/cn/ruiyeclub/service/impl/UserRecordServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.UserRecordDao; 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (UserRecord)表服务实现类 11 | * 12 | * @author Ray。 13 | * @date 2020-07-18 10:15:37 14 | */ 15 | @Service("userRecordService") 16 | public class UserRecordServiceImpl extends ServiceImpl implements UserRecordService { 17 | 18 | } -------------------------------------------------------------------------------- /springboot-knife4j/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: Ray@1998 10 | password: root 11 | knife4j: 12 | enable: true -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/java/cn/ruiyeclub/MailRabbitMQApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/7/28 19:05 9 | */ 10 | @SpringBootApplication 11 | public class MailRabbitMQApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(MailRabbitMQApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/java/cn/ruiyeclub/config/RabbitMQConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.amqp.core.Binding; 4 | import org.springframework.amqp.core.BindingBuilder; 5 | import org.springframework.amqp.core.FanoutExchange; 6 | import org.springframework.amqp.core.Queue; 7 | import org.springframework.beans.factory.annotation.Configurable; 8 | 9 | import static cn.ruiyeclub.constant.MQPrefixConst.EMAIL_EXCHANGE; 10 | import static cn.ruiyeclub.constant.MQPrefixConst.EMAIL_QUEUE; 11 | 12 | /** 13 | * @Author: Cr. 14 | * @Date: 2022/6/10 15 | */ 16 | @Configurable 17 | public class RabbitMQConfig { 18 | 19 | // 邮箱队列 20 | public Queue emailQueue() { 21 | return new Queue(EMAIL_QUEUE, true); 22 | } 23 | 24 | // 邮箱交换机 25 | public FanoutExchange emailExchange() { 26 | return new FanoutExchange(EMAIL_EXCHANGE, true, false); 27 | } 28 | 29 | // 队列绑定交换机 30 | public Binding bindingEmailDirect() { 31 | return BindingBuilder.bind(emailQueue()).to(emailExchange()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/java/cn/ruiyeclub/constant/MQPrefixConst.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.constant; 2 | 3 | /** 4 | * mq常量 5 | * 6 | * @author: Cr. 7 | * @date: 2022/6/10 8 | */ 9 | public class MQPrefixConst { 10 | 11 | /** 12 | * email交换机 13 | */ 14 | public static final String EMAIL_EXCHANGE = "email_exchange"; 15 | 16 | /** 17 | * 邮件队列 18 | */ 19 | public static final String EMAIL_QUEUE = "email_queue"; 20 | } 21 | -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/java/cn/ruiyeclub/consumer/EmailConsumer.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.consumer; 2 | 3 | import cn.ruiyeclub.dto.EmailDTO; 4 | import cn.ruiyeclub.utils.MailUtils; 5 | import com.alibaba.fastjson2.JSON; 6 | import freemarker.template.TemplateException; 7 | import org.springframework.amqp.rabbit.annotation.RabbitHandler; 8 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | import javax.mail.MessagingException; 13 | import java.io.IOException; 14 | 15 | import static cn.ruiyeclub.constant.MQPrefixConst.EMAIL_QUEUE; 16 | 17 | /** 18 | * @author: Cr. 19 | * @date: 2022/6/10 20 | */ 21 | @Component 22 | @RabbitListener(queues = EMAIL_QUEUE) 23 | public class EmailConsumer { 24 | 25 | @Autowired 26 | private MailUtils mailUtils; 27 | 28 | @RabbitHandler 29 | public void process(byte[] data) throws TemplateException, IOException, MessagingException { 30 | EmailDTO emailDTO = JSON.parseObject(new String(data), EmailDTO.class); 31 | mailUtils.sendTemplateMail(emailDTO.getEmail(), emailDTO.getSubject(), emailDTO.getContent(), "code.html"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/java/cn/ruiyeclub/controller/MailController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.dto.EmailDTO; 4 | import com.alibaba.fastjson2.JSON; 5 | import org.springframework.amqp.core.Message; 6 | import org.springframework.amqp.core.MessageProperties; 7 | import org.springframework.amqp.rabbit.core.RabbitTemplate; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.web.bind.annotation.GetMapping; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import static cn.ruiyeclub.constant.MQPrefixConst.EMAIL_EXCHANGE; 14 | 15 | @RestController 16 | @RequestMapping("/mail") 17 | public class MailController { 18 | 19 | @Autowired 20 | RabbitTemplate rabbitTemplate; 21 | 22 | 23 | @GetMapping("/send") 24 | public String sendTemplate(String mailAddress) { 25 | EmailDTO emailDTO = new EmailDTO(); 26 | emailDTO.setEmail(mailAddress); 27 | emailDTO.setSubject("验证码"); 28 | emailDTO.setContent("code123"); 29 | 30 | rabbitTemplate.convertAndSend(EMAIL_EXCHANGE, "*", new Message(JSON.toJSONBytes(emailDTO), new MessageProperties())); 31 | // todo 缓存 32 | return "发送成功"; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/java/cn/ruiyeclub/dto/EmailDTO.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Builder; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | /** 9 | * 邮件 10 | * 11 | * @author Cr. 12 | * @date 2022/06/10 13 | */ 14 | @Data 15 | public class EmailDTO { 16 | 17 | /** 18 | * 邮箱号 19 | */ 20 | private String email; 21 | 22 | /** 23 | * 主题 24 | */ 25 | private String subject; 26 | 27 | /** 28 | * 内容 29 | */ 30 | private String content; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | spring: 5 | # mq配置 6 | rabbitmq: 7 | host: localhost 8 | port: 5672 9 | username: guest 10 | password: guest 11 | #邮箱发送的配置 网易的配置要加from参数 12 | mail: 13 | host: smtp.qq.com 14 | #邮箱账号 15 | username: 185048761@qq.com 16 | #邮箱密码或授权码 17 | password: 18 | #协议 19 | protocol: smtp 20 | #这里换成自己的邮箱类型 例如qq邮箱就写smtp.qq.com 21 | properties.mail.smtp.auth: true 22 | properties.mail.smtp.port: 465 #端口号465或587 23 | properties.mail.display.sendmail: aaa #可以任意 24 | properties.mail.display.sendname: bbb #可以任意 25 | properties.mail.smtp.starttls.enable: true 26 | properties.mail.smtp.starttls.required: true 27 | properties.mail.smtp.ssl.enable: true #开启SSL 28 | default-encoding: utf-8 29 | 30 | freemarker: 31 | cache: false # 缓存配置 开发阶段应该配置为false 因为经常会改 32 | suffix: .html # 模版后缀名 默认为ftl 33 | charset: UTF-8 # 文件编码 34 | template-loader-path: classpath:/templates/ # 存放模板的文件夹,以resource文件夹为相对路径 -------------------------------------------------------------------------------- /springboot-mail-rabbitmq/src/main/resources/templates/code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 验证码 6 | 7 | 8 |

验证码

9 |
您的验证码为 ${code} 有效期15分钟,请不要告诉他人哦!
10 | 11 | -------------------------------------------------------------------------------- /springboot-mail/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot之集成mail发送邮件 2 | https://www.cnblogs.com/sillyby/p/13131340.html 3 | -------------------------------------------------------------------------------- /springboot-mail/src/main/java/cn/ruiyeclub/MailApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/7/28 19:05 9 | */ 10 | @SpringBootApplication 11 | public class MailApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(MailApplication.class, args); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-mail/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | spring: 5 | #邮箱发送的配置 网易的配置要加from参数 6 | mail: 7 | host: smtp.qq.com 8 | #邮箱账号 9 | username: 185048761@qq.com 10 | #邮箱密码或授权码 11 | password: 12 | #协议 13 | protocol: smtp 14 | #这里换成自己的邮箱类型 例如qq邮箱就写smtp.qq.com 15 | properties.mail.smtp.auth: true 16 | properties.mail.smtp.port: 465 #端口号465或587 17 | properties.mail.display.sendmail: aaa #可以任意 18 | properties.mail.display.sendname: bbb #可以任意 19 | properties.mail.smtp.starttls.enable: true 20 | properties.mail.smtp.starttls.required: true 21 | properties.mail.smtp.ssl.enable: true #开启SSL 22 | default-encoding: utf-8 23 | 24 | freemarker: 25 | cache: false # 缓存配置 开发阶段应该配置为false 因为经常会改 26 | suffix: .html # 模版后缀名 默认为ftl 27 | charset: UTF-8 # 文件编码 28 | template-loader-path: classpath:/templates/ # 存放模板的文件夹,以resource文件夹为相对路径 -------------------------------------------------------------------------------- /springboot-mail/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | freemarker简单示例 6 | 7 | 8 |

Hello Freemarker

9 |
My name is ${myname}
10 | 11 | -------------------------------------------------------------------------------- /springboot-mongodb/src/main/java/cn/ruiyeclub/MongodbApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class MongodbApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(MongodbApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-mongodb/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | ## mongodb 2 | spring.data.mongodb.uri=mongodb://localhost:27017/test 3 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/cn/ruiyeclub/MybatisPlusApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020/7/17 19:46 10 | */ 11 | @SpringBootApplication 12 | @MapperScan(basePackages = {"cn.ruiyeclub.dao"}) 13 | public class MybatisPlusApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(MybatisPlusApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/cn/ruiyeclub/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020-07-17 21:57 10 | */ 11 | @Configuration 12 | public class MybatisPlusConfig { 13 | /** 14 | * 分页插件 15 | * @return 16 | */ 17 | @Bean 18 | public PaginationInterceptor paginationInterceptor(){ 19 | return new PaginationInterceptor(); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (UserRecord)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @date 2020-07-22 14:06:51 11 | */ 12 | public interface UserRecordDao extends BaseMapper { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | 5 | /** 6 | * (UserRecord)表实体类 7 | * 8 | * @author Ray。 9 | * @date 2020-07-22 14:06:49 10 | */ 11 | public class UserRecord extends Model { 12 | 13 | private Integer id; 14 | 15 | private String name; 16 | 17 | private Integer age; 18 | 19 | private String email; 20 | 21 | 22 | public Integer getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Integer id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public Integer getAge() { 39 | return age; 40 | } 41 | 42 | public void setAge(Integer age) { 43 | this.age = age; 44 | } 45 | 46 | public String getEmail() { 47 | return email; 48 | } 49 | 50 | public void setEmail(String email) { 51 | this.email = email; 52 | } 53 | } -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (UserRecord)表服务接口 8 | * 9 | * @author Ray。 10 | * @date 2020-07-22 14:06:52 11 | */ 12 | public interface UserRecordService extends IService { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/java/cn/ruiyeclub/service/impl/UserRecordServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.UserRecordDao; 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (UserRecord)表服务实现类 11 | * 12 | * @author Ray。 13 | * @date 2020-07-22 14:06:53 14 | */ 15 | @Service("userRecordService") 16 | public class UserRecordServiceImpl extends ServiceImpl implements UserRecordService { 17 | 18 | } -------------------------------------------------------------------------------- /springboot-mybatis-plus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: root -------------------------------------------------------------------------------- /springboot-nacos/src/main/java/cn/ruiyeclub/NacosApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @author Cr. 9 | * @date 2025/4/28 10 | */ 11 | // 使用 @NacosPropertySource 加载 `dataId` 为 `application.yml` 的配置源,并开启自动更新 12 | @NacosPropertySource(dataId = "application.yml", autoRefreshed = true) 13 | @SpringBootApplication 14 | public class NacosApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(NacosApplication.class, args); 17 | } 18 | } -------------------------------------------------------------------------------- /springboot-nacos/src/main/java/cn/ruiyeclub/config/RegisterNacosConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.alibaba.nacos.api.annotation.NacosInjected; 4 | import com.alibaba.nacos.api.exception.NacosException; 5 | import com.alibaba.nacos.api.naming.NamingService; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.stereotype.Component; 8 | 9 | import javax.annotation.PostConstruct; 10 | 11 | /** 12 | * 服务自动注册到nacos 13 | */ 14 | @Component 15 | public class RegisterNacosConfig { 16 | 17 | @NacosInjected 18 | private NamingService namingService; 19 | 20 | @Value("${server.port}") 21 | private int serverPort; 22 | 23 | @Value("${spring.application.name}") 24 | private String applicationName; 25 | 26 | /** 27 | * 注册服务 28 | * 29 | * @throws NacosException 30 | */ 31 | @PostConstruct // 修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次!!! 32 | public void registerInstance() throws NacosException { 33 | namingService.registerInstance(applicationName, "127.0.0.1", serverPort); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /springboot-nacos/src/main/java/cn/ruiyeclub/controller/DiscoveryController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import com.alibaba.nacos.api.annotation.NacosInjected; 4 | import com.alibaba.nacos.api.exception.NacosException; 5 | import com.alibaba.nacos.api.naming.NamingService; 6 | import com.alibaba.nacos.api.naming.pojo.Instance; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestParam; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import java.util.List; 13 | 14 | @RestController 15 | @RequestMapping("discovery") 16 | public class DiscoveryController { 17 | 18 | @NacosInjected 19 | private NamingService namingService; 20 | 21 | /** 22 | * 获取实例 23 | * 24 | * @param serviceName: 服务名 25 | * @return 26 | * @throws NacosException 27 | */ 28 | @GetMapping("/getInstance") 29 | public List getInstance(@RequestParam String serviceName) throws NacosException { 30 | return namingService.getAllInstances(serviceName); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /springboot-nacos/src/main/java/cn/ruiyeclub/controller/HelloController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import com.alibaba.nacos.api.config.annotation.NacosValue; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | @RestController 8 | public class HelloController { 9 | 10 | @NacosValue(value = "${helloworld:HelloWorld}", autoRefreshed = true) 11 | private String hello; 12 | 13 | @GetMapping("/hello") 14 | public String hello() { 15 | return hello; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-nacos/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | 4 | spring: 5 | application: 6 | name: nacos-demo # nacos服务名 7 | 8 | # ======================== ↓↓↓↓↓↓ nacos相关配置 ↓↓↓↓↓↓ =============================== 9 | nacos: 10 | # 配置管理 11 | config: 12 | server-addr: 127.0.0.1:8848 # TODO 这里换成自己的ip加端口 13 | # 服务注册与发现 14 | discovery: 15 | server-addr: ${nacos.config.server-addr} -------------------------------------------------------------------------------- /springboot-oss-qiniu/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot之集成七牛云上传 2 | https://www.cnblogs.com/zengnansheng/p/11110230.html -------------------------------------------------------------------------------- /springboot-oss-qiniu/src/main/java/cn/ruiyeclub/OssQiniuApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/7/24 18:11 9 | */ 10 | @SpringBootApplication 11 | public class OssQiniuApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(OssQiniuApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-oss-qiniu/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | #七牛的配置 2 | qiniu: 3 | accessKey: 123***789 4 | secretKey: 123***789 5 | bucketName: 存储空间名 6 | fileDomain: 存款空间域名 -------------------------------------------------------------------------------- /springboot-quartz/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot 整合 Quartz 实现分布式调度 2 | http://www.justdojava.com/2020/12/22/springboot-quart-cluster/ -------------------------------------------------------------------------------- /springboot-quartz/src/main/java/cn/ruiyeclub/QuartzApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2021/1/9 9 | */ 10 | @SpringBootApplication 11 | public class QuartzApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(QuartzApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-quartz/src/main/java/cn/ruiyeclub/config/QuartzJobFactory.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.quartz.spi.TriggerFiredBundle; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.beans.factory.config.AutowireCapableBeanFactory; 6 | import org.springframework.scheduling.quartz.AdaptableJobFactory; 7 | import org.springframework.stereotype.Component; 8 | 9 | @Component 10 | public class QuartzJobFactory extends AdaptableJobFactory { 11 | 12 | @Autowired 13 | private AutowireCapableBeanFactory capableBeanFactory; 14 | 15 | @Override 16 | protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { 17 | //调用父类的方法 18 | Object jobInstance = super.createJobInstance(bundle); 19 | //进行注入 20 | capableBeanFactory.autowireBean(jobInstance); 21 | return jobInstance; 22 | } 23 | } -------------------------------------------------------------------------------- /springboot-quartz/src/main/java/cn/ruiyeclub/job/TfCommandJob.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.job; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.quartz.Job; 5 | import org.quartz.JobExecutionContext; 6 | import org.quartz.SchedulerException; 7 | 8 | import java.text.SimpleDateFormat; 9 | import java.util.Date; 10 | 11 | @Slf4j 12 | public class TfCommandJob implements Job { 13 | 14 | @Override 15 | public void execute(JobExecutionContext context) { 16 | try { 17 | System.out.println(context.getScheduler().getSchedulerInstanceId() + "--" + new SimpleDateFormat("YYYY-MM-dd HH:mm:ss").format(new Date())); 18 | } catch (SchedulerException e) { 19 | log.error("任务执行失败",e); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-quartz/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruiyeclub/SpringBoot-Hello/f4065f86b42dfa17e27181280360b53b08e322ca/springboot-quartz/src/main/resources/application.properties -------------------------------------------------------------------------------- /springboot-quartz/src/main/resources/quartz.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ruiyeclub/SpringBoot-Hello/f4065f86b42dfa17e27181280360b53b08e322ca/springboot-quartz/src/main/resources/quartz.properties -------------------------------------------------------------------------------- /springboot-rabbitmq/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot 整合 rabbitmq 2 | https://www.jianshu.com/p/9a1569755419 -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/cn/ruiyeclub/RabbitMQApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.amqp.rabbit.annotation.EnableRabbit; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | /** 8 | * @Author: Ray。 9 | * @Date: 2020/9/27 10 | */ 11 | /** 12 | * 自动配置 13 | * 1. RabbitAutoConfiguration 14 | * 2. 自动配置了连接工厂ConnectionFactory 15 | * 3. RabbitProperties 封装了RabbitMQ的配置 16 | * 4. RabbitTemplate : 给RabbitMQ发送和接受消息 17 | * 5. AmqpAdmin : RabbitMQ系统管理功能组件 18 | * 6. @EnableRabbit + @RabbitListener 19 | */ 20 | @EnableRabbit 21 | @SpringBootApplication 22 | public class RabbitMQApplication { 23 | 24 | public static void main(String[] args) { 25 | SpringApplication.run(RabbitMQApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/cn/ruiyeclub/config/MyAMQPConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.amqp.support.converter.MessageConverter; 7 | 8 | /** 9 | * 自定义消息转换器,默认是jdk的序列化转换器,我们自定义为json的 10 | */ 11 | @Configuration 12 | public class MyAMQPConfig { 13 | 14 | @Bean 15 | public MessageConverter messageConverter() { 16 | return new Jackson2JsonMessageConverter(); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/java/cn/ruiyeclub/service/MQService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | 4 | import org.springframework.amqp.core.Message; 5 | import org.springframework.amqp.rabbit.annotation.RabbitListener; 6 | import org.springframework.stereotype.Service; 7 | 8 | @Service 9 | public class MQService { 10 | 11 | @RabbitListener(queues = "fanout.queue") 12 | public void receive(Message message) { 13 | System.out.println("收到消息 : " + new String(message.getBody())); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /springboot-rabbitmq/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | servlet: 3 | # 请求数据转码UTF8 4 | encoding: 5 | enabled: true 6 | charset: UTF-8 7 | force: true 8 | logging: 9 | level: 10 | web: debug 11 | cn: 12 | ruiyeclub: 13 | rabbitmq: debug 14 | 15 | spring: 16 | rabbitmq: 17 | addresses: 127.0.0.1 18 | host: 5672 19 | username: guest 20 | password: guest 21 | virtual-host: / 22 | # 打开消息确认机制 23 | publisher-confirm-type: correlated 24 | # 打开消息返回 25 | publisher-returns: true 26 | template: 27 | mandatory: true 28 | # 手动确认消息 29 | listener: 30 | simple: 31 | acknowledge-mode: manual 32 | prefetch: 2 -------------------------------------------------------------------------------- /springboot-redis-lock/src/main/java/cn/ruiyeclub/RedisLockApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2020/10/16 9 | */ 10 | @SpringBootApplication 11 | public class RedisLockApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(RedisLockApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-redis-lock/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | redis: 3 | host: 127.0.0.1 4 | password: 5 | # 连接超时时间(毫秒) 6 | timeout: 10000 7 | # Redis默认情况下有16个分片,这里配置具体使用的分片,默认是0 8 | database: 0 9 | lettuce: 10 | pool: 11 | # 连接池最大连接数(使用负值表示没有限制) 默认 8 12 | max-active: 8 13 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1 14 | max-wait: -1 15 | # 连接池中的最大空闲连接 默认 8 16 | max-idle: 8 17 | # 连接池中的最小空闲连接 默认 0 18 | min-idle: 0 19 | -------------------------------------------------------------------------------- /springboot-redis-lock/src/test/java/cn/ruiyeclub/RedisTest.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import cn.ruiyeclub.utils.RedisLock; 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 | import org.springframework.data.redis.core.StringRedisTemplate; 9 | 10 | @Slf4j 11 | @SpringBootTest(classes = RedisLockApplication.class) 12 | public class RedisTest { 13 | 14 | @Autowired 15 | private StringRedisTemplate stringRedisTemplate; 16 | 17 | private void testLock(String batch) throws Exception { 18 | RedisLock lock = RedisLock.newLock(stringRedisTemplate, "testRedisLock"); 19 | try { 20 | if (lock.tryLock()) { 21 | log.info("方法[ {} ]加锁成功", batch); 22 | Thread.sleep(15000L); 23 | } else { 24 | log.info("方法[ {} ]加锁失败", batch); 25 | } 26 | } finally { 27 | lock.release(); 28 | log.info("方法[ {} ]释放锁成功", batch); 29 | } 30 | } 31 | 32 | @Test 33 | public void testLock1() throws Exception { 34 | testLock("1"); 35 | } 36 | 37 | @Test 38 | public void testLock2() throws Exception { 39 | testLock("2"); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /springboot-redis-mq/README.md: -------------------------------------------------------------------------------- 1 | springboot(三)使用redis实现消息队列 2 | https://blog.csdn.net/u012326462/article/details/80515955 -------------------------------------------------------------------------------- /springboot-redis-mq/src/main/java/cn/ruiyeclub/RedisMQApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/9/23 18:35 9 | */ 10 | @SpringBootApplication 11 | public class RedisMQApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(RedisMQApplication.class,args); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /springboot-redis-mq/src/main/java/cn/ruiyeclub/config/PublisherConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.data.redis.connection.RedisConnectionFactory; 6 | import org.springframework.data.redis.core.StringRedisTemplate; 7 | 8 | /** 9 | * 注册redisTemplate,作为消息队列的发布者 10 | */ 11 | @Configuration 12 | public class PublisherConfig { 13 | 14 | @Bean 15 | public StringRedisTemplate getRedisTemplate(RedisConnectionFactory redisConnectionFactory) { 16 | return new StringRedisTemplate(redisConnectionFactory); 17 | } 18 | } -------------------------------------------------------------------------------- /springboot-redis-mq/src/main/java/cn/ruiyeclub/controller/PublisherController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.service.PublisherService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | @RestController 10 | @RequestMapping("publisher") 11 | public class PublisherController { 12 | 13 | @Autowired 14 | private PublisherService publisherService; 15 | 16 | @RequestMapping("{name}") 17 | public String sendMessage(@PathVariable("name") String name) { 18 | return publisherService.sendMessage(name); 19 | } 20 | } -------------------------------------------------------------------------------- /springboot-redis-mq/src/main/java/cn/ruiyeclub/listener/Receiver.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.listener; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.data.redis.connection.Message; 6 | import org.springframework.data.redis.connection.MessageListener; 7 | import org.springframework.data.redis.core.StringRedisTemplate; 8 | import org.springframework.data.redis.serializer.RedisSerializer; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.annotation.Resource; 12 | 13 | /** 14 | * @author Ray。 15 | * @date 2020/9/23 18:37 16 | */ 17 | @Slf4j 18 | @Component 19 | public class Receiver implements MessageListener { 20 | 21 | @Autowired 22 | private StringRedisTemplate redisTemplate; 23 | 24 | @Override 25 | public void onMessage(Message message, byte[] pattern) { 26 | RedisSerializer valueSerializer = redisTemplate.getStringSerializer(); 27 | String deserialize = valueSerializer.deserialize(message.getBody()); 28 | log.info("收到的mq消息" + deserialize); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /springboot-redis-mq/src/main/java/cn/ruiyeclub/service/PublisherService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.StringRedisTemplate; 5 | import org.springframework.stereotype.Service; 6 | 7 | import javax.annotation.Resource; 8 | 9 | @Service 10 | public class PublisherService { 11 | 12 | @Autowired 13 | private StringRedisTemplate redisTemplate; 14 | 15 | public String sendMessage(String name) { 16 | try { 17 | System.out.println("name"+name); 18 | redisTemplate.convertAndSend("TOPIC_USERNAME", name); 19 | return "消息发送成功了"; 20 | 21 | } catch (Exception e) { 22 | e.printStackTrace(); 23 | return "消息发送失败了"; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /springboot-redis-mq/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | redis: 3 | database: 0 4 | host: localhost 5 | port: 6379 -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/java/cn/ruiyeclub/RedisRateLimitApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2021/3/4 9 | */ 10 | @SpringBootApplication 11 | public class RedisRateLimitApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(RedisRateLimitApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/java/cn/ruiyeclub/annotation/RateLimiter.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.annotation; 2 | 3 | import org.springframework.core.annotation.AliasFor; 4 | 5 | import java.lang.annotation.*; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | /** 9 | * 限流注解 10 | * @author Ray。 11 | * @date Created in 2019/9/30 10:31 12 | */ 13 | @Target(ElementType.METHOD) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | @Documented 16 | public @interface RateLimiter { 17 | long DEFAULT_REQUEST = 10; 18 | 19 | /** 20 | * max 最大请求数 21 | */ 22 | @AliasFor("max") long value() default DEFAULT_REQUEST; 23 | 24 | /** 25 | * max 最大请求数 26 | */ 27 | @AliasFor("value") long max() default DEFAULT_REQUEST; 28 | 29 | /** 30 | * 限流key 31 | */ 32 | String key() default ""; 33 | 34 | /** 35 | * 超时时长,默认1分钟 36 | */ 37 | long timeout() default 1; 38 | 39 | /** 40 | * 超时时间单位,默认 分钟 41 | */ 42 | TimeUnit timeUnit() default TimeUnit.MINUTES; 43 | } -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/java/cn/ruiyeclub/config/RedisConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.core.io.ClassPathResource; 6 | import org.springframework.data.redis.core.script.DefaultRedisScript; 7 | import org.springframework.data.redis.core.script.RedisScript; 8 | import org.springframework.scripting.support.ResourceScriptSource; 9 | 10 | /** 11 | * Redis 配置 12 | * @author Ray。 13 | * @date Created in 2019/9/30 11:37 14 | */ 15 | @Configuration 16 | public class RedisConfig { 17 | @Bean 18 | @SuppressWarnings("unchecked") 19 | public RedisScript limitRedisScript() { 20 | DefaultRedisScript redisScript = new DefaultRedisScript<>(); 21 | redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("scripts/redis/limit.lua"))); 22 | redisScript.setResultType(Long.class); 23 | return redisScript; 24 | } 25 | } -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/java/cn/ruiyeclub/controller/TestController.java: -------------------------------------------------------------------------------- 1 | 2 | package cn.ruiyeclub.controller; 3 | 4 | import cn.hutool.core.lang.Dict; 5 | import cn.ruiyeclub.annotation.RateLimiter; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | /** 11 | * 测试 12 | * @author yangkai.shen 13 | * @date Created in 2019/9/30 10:30 14 | */ 15 | @Slf4j 16 | @RestController 17 | public class TestController { 18 | 19 | @RateLimiter(value = 5) 20 | @GetMapping("/test1") 21 | public Dict test1() { 22 | log.info("【test1】被执行了。。。。。"); 23 | return Dict.create().set("msg", "hello,world!").set("description", "别想一直看到我,不信你快速刷新看看~"); 24 | } 25 | 26 | @GetMapping("/test2") 27 | public Dict test2() { 28 | log.info("【test2】被执行了。。。。。"); 29 | return Dict.create().set("msg", "hello,world!").set("description", "我一直都在,卟离卟弃"); 30 | } 31 | 32 | @RateLimiter(value = 2, key = "测试自定义key") 33 | @GetMapping("/test3") 34 | public Dict test3() { 35 | log.info("【test3】被执行了。。。。。"); 36 | return Dict.create().set("msg", "hello,world!").set("description", "别想一直看到我,不信你快速刷新看看~"); 37 | } 38 | } -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/java/cn/ruiyeclub/hander/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.hander; 2 | 3 | import cn.hutool.core.lang.Dict; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.RestControllerAdvice; 7 | 8 | /** 9 | * 全局异常拦截 10 | * @author Ray。 11 | * @date Created in 2019/9/30 10:30 12 | */ 13 | @Slf4j 14 | @RestControllerAdvice 15 | public class GlobalExceptionHandler { 16 | 17 | @ExceptionHandler(RuntimeException.class) 18 | public Dict handler(RuntimeException ex) { 19 | return Dict.create().set("msg", ex.getMessage()); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | spring: 4 | redis: 5 | host: localhost 6 | # 连接超时时间(记得添加单位,Duration) 7 | timeout: 10000ms 8 | # Redis默认情况下有16个分片,这里配置具体使用的分片 9 | # database: 0 10 | lettuce: 11 | pool: 12 | # 连接池最大连接数(使用负值表示没有限制) 默认 8 13 | max-active: 8 14 | # 连接池最大阻塞等待时间(使用负值表示没有限制) 默认 -1 15 | max-wait: -1ms 16 | # 连接池中的最大空闲连接 默认 8 17 | max-idle: 8 18 | # 连接池中的最小空闲连接 默认 0 19 | min-idle: 0 -------------------------------------------------------------------------------- /springboot-redis-ratelimit/src/main/resources/scripts/redis/limit.lua: -------------------------------------------------------------------------------- 1 | -- 下标从 1 开始 2 | local key = KEYS[1] 3 | local now = tonumber(ARGV[1]) 4 | local ttl = tonumber(ARGV[2]) 5 | local expired = tonumber(ARGV[3]) 6 | -- 最大访问量 7 | local max = tonumber(ARGV[4]) 8 | 9 | -- 清除过期的数据 10 | -- 移除指定分数区间内的所有元素,expired 即已经过期的 score 11 | -- 根据当前时间毫秒数 - 超时毫秒数,得到过期时间 expired 12 | redis.call('zremrangebyscore', key, 0, expired) 13 | 14 | -- 获取 zset 中的当前元素个数 15 | local current = tonumber(redis.call('zcard', key)) 16 | local next = current + 1 17 | 18 | if next > max then 19 | -- 达到限流大小 返回 0 20 | return 0; 21 | else 22 | -- 往 zset 中添加一个值、得分均为当前时间戳的元素,[value,score] 23 | redis.call("zadd", key, now, now) 24 | -- 每次访问均重新设置 zset 的过期时间,单位毫秒 25 | redis.call("pexpire", key, ttl) 26 | return next 27 | end -------------------------------------------------------------------------------- /springboot-redis/src/main/java/cn/ruiyeclub/RedisApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class RedisApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(RedisApplication.class,args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /springboot-redis/src/main/java/cn/ruiyeclub/entity/Student.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | /** 8 | * 实现序列化接口才可以存入redis 9 | */ 10 | @Data 11 | public class Student implements Serializable { 12 | 13 | private Integer id; 14 | private String name; 15 | private Double score; 16 | private Date birthday; 17 | } 18 | -------------------------------------------------------------------------------- /springboot-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | redis: 3 | database: 0 4 | host: localhost 5 | port: 6379 -------------------------------------------------------------------------------- /springboot-scheduled/src/main/java/cn/ruiyeclub/ScheduledApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | 7 | /** 8 | * 开启定时任务 9 | */ 10 | @SpringBootApplication 11 | @EnableScheduling 12 | public class ScheduledApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(ScheduledApplication.class, args); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /springboot-scheduled/src/main/java/cn/ruiyeclub/scheduled/Jobs.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.scheduled; 2 | 3 | import org.springframework.scheduling.annotation.Async; 4 | import org.springframework.scheduling.annotation.Scheduled; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.Date; 8 | 9 | /** 10 | * Scheduled定时任务 11 | * @author Ray。 12 | * @create 2020-05-17 15:01 13 | */ 14 | @Component 15 | @Async 16 | public class Jobs { 17 | 18 | /** 19 | * 定时任务方法 20 | * @Scheduled 表示设置了定时任务 21 | * cron属性 cron表达式。定时任务触发是时间的一个字符串表达形式 22 | */ 23 | @Scheduled(cron = "0/2 * * * * ?") 24 | public void scheduledMethod(){ 25 | System.out.println("定时器被触发"+new Date()); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /springboot-scheduled/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | scheduled: 2 | corePoolSize: 10 3 | maxPoolSize: 100 4 | queueCapacity: 10 5 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/README.md: -------------------------------------------------------------------------------- 1 | shiro-redis-jwt整合 2 | https://blog.csdn.net/qq_41184981/article/details/109401426 -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/ShiroJwtRedisApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ShiroJwtRedisApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ShiroJwtRedisApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/config/CorsConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 5 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 6 | 7 | /** 8 | * 解决跨域问题 9 | */ 10 | @Configuration 11 | public class CorsConfig implements WebMvcConfigurer { 12 | 13 | @Override 14 | public void addCorsMappings(CorsRegistry registry) { 15 | registry.addMapping("/**"). 16 | allowedOrigins("*"). 17 | allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS"). 18 | allowCredentials(true). 19 | maxAge(3600). 20 | allowedHeaders("*"); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | @Configuration 10 | @EnableTransactionManagement 11 | @MapperScan("cn.ruiyeclub.dao") 12 | public class MybatisPlusConfig { 13 | 14 | @Bean 15 | public PaginationInterceptor paginationInterceptor() { 16 | PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); 17 | return paginationInterceptor; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/dao/SysPermissionDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.SysPermission; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * (SysPermission)表数据库访问层 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysPermissionDao extends BaseMapper { 16 | 17 | List findPermissionByRoleId(@Param("roleId") Integer roleId); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/dao/SysRoleDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.SysRole; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * (SysRole)表数据库访问层 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysRoleDao extends BaseMapper { 16 | 17 | List findRoleByUsername(@Param("username") String username); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/dao/SysRolePermissionDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.SysRolePermission; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (SysRolePermission)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysRolePermissionDao extends BaseMapper { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/dao/SysUserDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.SysUser; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (SysUser)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 20:09:43 11 | */ 12 | public interface SysUserDao extends BaseMapper { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/dao/SysUserRoleDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.SysUserRole; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (SysUserRole)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysUserRoleDao extends BaseMapper { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/dto/LoginDto.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dto; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | import java.io.Serializable; 7 | 8 | @Data 9 | public class LoginDto implements Serializable { 10 | 11 | @NotBlank(message = "昵称不能为空") 12 | private String username; 13 | 14 | @NotBlank(message = "密码不能为空") 15 | private String password; 16 | } 17 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/entity/SysRole.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * (SysRole)表实体类 9 | * 10 | * @author Ray。 11 | * @since 2022-05-25 22:30:44 12 | */ 13 | @SuppressWarnings("serial") 14 | public class SysRole extends Model { 15 | 16 | private Integer id; 17 | 18 | private String description; 19 | 20 | private String role; 21 | 22 | 23 | public Integer getId() { 24 | return id; 25 | } 26 | 27 | public void setId(Integer id) { 28 | this.id = id; 29 | } 30 | 31 | public String getDescription() { 32 | return description; 33 | } 34 | 35 | public void setDescription(String description) { 36 | this.description = description; 37 | } 38 | 39 | public String getRole() { 40 | return role; 41 | } 42 | 43 | public void setRole(String role) { 44 | this.role = role; 45 | } 46 | 47 | /** 48 | * 获取主键值 49 | * 50 | * @return 主键值 51 | */ 52 | @Override 53 | protected Serializable pkVal() { 54 | return this.id; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/entity/SysRolePermission.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | 5 | /** 6 | * (SysRolePermission)表实体类 7 | * 8 | * @author Ray。 9 | * @since 2022-05-25 22:30:44 10 | */ 11 | @SuppressWarnings("serial") 12 | public class SysRolePermission extends Model { 13 | 14 | private Integer permissionId; 15 | 16 | private Integer roleId; 17 | 18 | 19 | public Integer getPermissionId() { 20 | return permissionId; 21 | } 22 | 23 | public void setPermissionId(Integer permissionId) { 24 | this.permissionId = permissionId; 25 | } 26 | 27 | public Integer getRoleId() { 28 | return roleId; 29 | } 30 | 31 | public void setRoleId(Integer roleId) { 32 | this.roleId = roleId; 33 | } 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/entity/SysUserRole.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * (SysUserRole)表实体类 10 | * 11 | * @author Ray。 12 | * @since 2022-05-25 22:30:44 13 | */ 14 | @SuppressWarnings("serial") 15 | public class SysUserRole extends Model { 16 | 17 | private Integer roleId; 18 | 19 | @TableId 20 | private Integer uid; 21 | 22 | 23 | public Integer getRoleId() { 24 | return roleId; 25 | } 26 | 27 | public void setRoleId(Integer roleId) { 28 | this.roleId = roleId; 29 | } 30 | 31 | public Integer getUid() { 32 | return uid; 33 | } 34 | 35 | public void setUid(Integer uid) { 36 | this.uid = uid; 37 | } 38 | 39 | /** 40 | * 获取主键值 41 | * 42 | * @return 主键值 43 | */ 44 | @Override 45 | protected Serializable pkVal() { 46 | return this.roleId; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/result/Result.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.result; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class Result implements Serializable { 9 | 10 | private int code; // 200是正常,非200表示异常 11 | private String msg; 12 | private Object data; 13 | 14 | public static Result succ(Object data) { 15 | return succ(200, "操作成功", data); 16 | } 17 | 18 | public static Result succ(int code, String msg, Object data) { 19 | Result r = new Result(); 20 | r.setCode(code); 21 | r.setMsg(msg); 22 | r.setData(data); 23 | return r; 24 | } 25 | 26 | public static Result fail(String msg) { 27 | return fail(400, msg, null); 28 | } 29 | 30 | public static Result fail(String msg, Object data) { 31 | return fail(400, msg, data); 32 | } 33 | 34 | public static Result fail(int code, String msg, Object data) { 35 | Result r = new Result(); 36 | r.setCode(code); 37 | r.setMsg(msg); 38 | r.setData(data); 39 | return r; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/SysPermissionService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.SysPermission; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * (SysPermission)表服务接口 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysPermissionService extends IService { 16 | 17 | /** 18 | * 根据角色ID查询角色对应的权限信息 19 | */ 20 | List findPermissionByRoleId(@Param("roleId") Integer roleId); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/SysRolePermissionService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.SysRolePermission; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (SysRolePermission)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysRolePermissionService extends IService { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/SysRoleService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.SysRole; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * (SysRole)表服务接口 10 | * 11 | * @author Ray。 12 | * @since 2022-05-25 22:30:44 13 | */ 14 | public interface SysRoleService extends IService { 15 | 16 | List findRoleByUsername(String username); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/SysUserRoleService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.SysUserRole; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (SysUserRole)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysUserRoleService extends IService { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.SysUser; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (SysUser)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 20:09:43 11 | */ 12 | public interface SysUserService extends IService { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/impl/SysPermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.SysPermissionDao; 4 | import cn.ruiyeclub.entity.SysPermission; 5 | import cn.ruiyeclub.service.SysPermissionService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | 12 | /** 13 | * (SysPermission)表服务实现类 14 | * 15 | * @author Ray。 16 | * @since 2022-05-25 22:30:44 17 | */ 18 | @Service("sysPermissionService") 19 | public class SysPermissionServiceImpl extends ServiceImpl implements SysPermissionService { 20 | 21 | @Resource 22 | private SysPermissionDao sysPermissionDao; 23 | 24 | @Override 25 | public List findPermissionByRoleId(Integer roleId) { 26 | return sysPermissionDao.findPermissionByRoleId(roleId); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/impl/SysRolePermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.SysRolePermissionDao; 4 | import cn.ruiyeclub.entity.SysRolePermission; 5 | import cn.ruiyeclub.service.SysRolePermissionService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (SysRolePermission)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | @Service("sysRolePermissionService") 16 | public class SysRolePermissionServiceImpl extends ServiceImpl implements SysRolePermissionService { 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/impl/SysRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.SysRoleDao; 4 | import cn.ruiyeclub.entity.SysRole; 5 | import cn.ruiyeclub.service.SysRoleService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | 12 | /** 13 | * (SysRole)表服务实现类 14 | * 15 | * @author Ray。 16 | * @since 2022-05-25 22:30:44 17 | */ 18 | @Service("sysRoleService") 19 | public class SysRoleServiceImpl extends ServiceImpl implements SysRoleService { 20 | @Resource 21 | private SysRoleDao sysRoleDao; 22 | 23 | @Override 24 | public List findRoleByUsername(String username) { 25 | return sysRoleDao.findRoleByUsername(username); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/impl/SysUserRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.SysUserRoleDao; 4 | import cn.ruiyeclub.entity.SysUserRole; 5 | import cn.ruiyeclub.service.SysUserRoleService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (SysUserRole)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | @Service("sysUserRoleService") 16 | public class SysUserRoleServiceImpl extends ServiceImpl implements SysUserRoleService { 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/service/impl/SysUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.SysUserDao; 4 | import cn.ruiyeclub.entity.SysUser; 5 | import cn.ruiyeclub.service.SysUserService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (SysUser)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 20:09:43 14 | */ 15 | @Service("sysUserService") 16 | public class SysUserServiceImpl extends ServiceImpl implements SysUserService { 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/shiro/AccountProfile.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.shiro; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class AccountProfile implements Serializable { 9 | private Integer id; 10 | private String username; 11 | } -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/shiro/JwtToken.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.shiro; 2 | 3 | import org.apache.shiro.authc.AuthenticationToken; 4 | 5 | public class JwtToken implements AuthenticationToken { 6 | 7 | private String token; 8 | 9 | public JwtToken(String jwt) { 10 | this.token = jwt; 11 | } 12 | 13 | @Override 14 | public Object getPrincipal() { 15 | return token; 16 | } 17 | 18 | @Override 19 | public Object getCredentials() { 20 | return token; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/util/MD5Utils.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.util; 2 | 3 | import org.apache.shiro.crypto.hash.SimpleHash; 4 | import org.apache.shiro.util.ByteSource; 5 | 6 | /** 7 | * md5加密工具 8 | * 9 | * @author Ray。 10 | */ 11 | public class MD5Utils { 12 | private static final String SALT = "ruiyeclub"; 13 | private static final String ALGORITH_NAME = "md5"; 14 | private static final int HASH_ITERATIONS = 2; 15 | 16 | public static String encrypt(String pswd) { 17 | String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex(); 18 | return newPassword; 19 | } 20 | 21 | public static String encrypt(String username, String pswd) { 22 | String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username + SALT), 23 | HASH_ITERATIONS).toHex(); 24 | return newPassword; 25 | } 26 | 27 | public static void main(String[] args) { 28 | System.out.println(MD5Utils.encrypt("test", "123456")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/java/cn/ruiyeclub/util/ShiroUtil.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.util; 2 | 3 | import cn.ruiyeclub.shiro.AccountProfile; 4 | import org.apache.shiro.SecurityUtils; 5 | 6 | public class ShiroUtil { 7 | 8 | public static AccountProfile getProfile() { 9 | return (AccountProfile) SecurityUtils.getSubject().getPrincipal(); 10 | } 11 | 12 | public static void logout() { 13 | SecurityUtils.getSubject().logout(); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring配置 2 | # DataSource Config 3 | spring: 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://localhost:8080/boot_hello?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai 7 | username: root 8 | password: admin 9 | 10 | mybatis-plus: 11 | mapper-locations: classpath*:/mapper/**Mapper.xml 12 | server: 13 | port: 8081 14 | markerhub: 15 | jwt: 16 | secret: f4e2e52034348f86b67cde581c0f9eb5 17 | expire: 604800 18 | header: Authorization 19 | 20 | shiro-redis: 21 | enabled: true 22 | redis-manager: 23 | host: 127.0.0.1:6379 -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/resources/mapper/SysPermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 24 | 25 | -------------------------------------------------------------------------------- /springboot-shiro-jwt-redis/src/main/resources/mapper/SysRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 22 | 23 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/ShiroJwtApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ShiroJwtApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ShiroJwtApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.mybatis.spring.annotation.MapperScan; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | @Configuration 10 | @EnableTransactionManagement 11 | @MapperScan("cn.ruiyeclub.dao") 12 | public class MybatisPlusConfig { 13 | 14 | @Bean 15 | public PaginationInterceptor paginationInterceptor() { 16 | PaginationInterceptor paginationInterceptor = new PaginationInterceptor(); 17 | return paginationInterceptor; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/dao/SysPermissionDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import cn.ruiyeclub.entity.SysPermission; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * (SysPermission)表数据库访问层 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysPermissionDao extends BaseMapper { 16 | 17 | List findPermissionByRoleId(@Param("roleId") Integer roleId); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/dao/SysRoleDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import cn.ruiyeclub.entity.SysRole; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * (SysRole)表数据库访问层 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysRoleDao extends BaseMapper { 16 | 17 | List findRoleByUsername(@Param("username") String username); 18 | 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/dao/SysRolePermissionDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import cn.ruiyeclub.entity.SysRolePermission; 5 | 6 | /** 7 | * (SysRolePermission)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysRolePermissionDao extends BaseMapper { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/dao/SysUserDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import cn.ruiyeclub.entity.SysUser; 5 | 6 | /** 7 | * (SysUser)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 20:09:43 11 | */ 12 | public interface SysUserDao extends BaseMapper { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/dao/SysUserRoleDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import cn.ruiyeclub.entity.SysUserRole; 5 | 6 | /** 7 | * (SysUserRole)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysUserRoleDao extends BaseMapper { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/dto/LoginDto.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dto; 2 | 3 | import lombok.Data; 4 | 5 | import javax.validation.constraints.NotBlank; 6 | import java.io.Serializable; 7 | 8 | @Data 9 | public class LoginDto implements Serializable { 10 | 11 | @NotBlank(message = "昵称不能为空") 12 | private String username; 13 | 14 | @NotBlank(message = "密码不能为空") 15 | private String password; 16 | } 17 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/entity/SysPermission.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * (SysPermission)表实体类 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | @SuppressWarnings("serial") 13 | public class SysPermission extends Model { 14 | 15 | private Integer id; 16 | 17 | private String name; 18 | 19 | private String permission; 20 | 21 | private String url; 22 | 23 | 24 | public Integer getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Integer id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getPermission() { 41 | return permission; 42 | } 43 | 44 | public void setPermission(String permission) { 45 | this.permission = permission; 46 | } 47 | 48 | public String getUrl() { 49 | return url; 50 | } 51 | 52 | public void setUrl(String url) { 53 | this.url = url; 54 | } 55 | 56 | /** 57 | * 获取主键值 58 | * 59 | * @return 主键值 60 | */ 61 | @Override 62 | protected Serializable pkVal() { 63 | return this.id; 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/entity/SysRole.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * (SysRole)表实体类 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | @SuppressWarnings("serial") 13 | public class SysRole extends Model { 14 | 15 | private Integer id; 16 | 17 | private String description; 18 | 19 | private String role; 20 | 21 | 22 | public Integer getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Integer id) { 27 | this.id = id; 28 | } 29 | 30 | public String getDescription() { 31 | return description; 32 | } 33 | 34 | public void setDescription(String description) { 35 | this.description = description; 36 | } 37 | 38 | public String getRole() { 39 | return role; 40 | } 41 | 42 | public void setRole(String role) { 43 | this.role = role; 44 | } 45 | 46 | /** 47 | * 获取主键值 48 | * 49 | * @return 主键值 50 | */ 51 | @Override 52 | protected Serializable pkVal() { 53 | return this.id; 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/entity/SysRolePermission.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import java.io.Serializable; 5 | 6 | /** 7 | * (SysRolePermission)表实体类 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | @SuppressWarnings("serial") 13 | public class SysRolePermission extends Model { 14 | 15 | private Integer permissionId; 16 | 17 | private Integer roleId; 18 | 19 | 20 | public Integer getPermissionId() { 21 | return permissionId; 22 | } 23 | 24 | public void setPermissionId(Integer permissionId) { 25 | this.permissionId = permissionId; 26 | } 27 | 28 | public Integer getRoleId() { 29 | return roleId; 30 | } 31 | 32 | public void setRoleId(Integer roleId) { 33 | this.roleId = roleId; 34 | } 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/entity/SysUserRole.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableId; 4 | import com.baomidou.mybatisplus.extension.activerecord.Model; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * (SysUserRole)表实体类 10 | * 11 | * @author Ray。 12 | * @since 2022-05-25 22:30:44 13 | */ 14 | @SuppressWarnings("serial") 15 | public class SysUserRole extends Model { 16 | 17 | private Integer roleId; 18 | 19 | @TableId 20 | private Integer uid; 21 | 22 | 23 | public Integer getRoleId() { 24 | return roleId; 25 | } 26 | 27 | public void setRoleId(Integer roleId) { 28 | this.roleId = roleId; 29 | } 30 | 31 | public Integer getUid() { 32 | return uid; 33 | } 34 | 35 | public void setUid(Integer uid) { 36 | this.uid = uid; 37 | } 38 | 39 | /** 40 | * 获取主键值 41 | * 42 | * @return 主键值 43 | */ 44 | @Override 45 | protected Serializable pkVal() { 46 | return this.roleId; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/result/Result.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.result; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class Result implements Serializable { 9 | 10 | private int code; // 200是正常,非200表示异常 11 | private String msg; 12 | private Object data; 13 | 14 | public static Result succ(Object data) { 15 | return succ(200, "操作成功", data); 16 | } 17 | 18 | public static Result succ(int code, String msg, Object data) { 19 | Result r = new Result(); 20 | r.setCode(code); 21 | r.setMsg(msg); 22 | r.setData(data); 23 | return r; 24 | } 25 | 26 | public static Result fail(String msg) { 27 | return fail(400, msg, null); 28 | } 29 | 30 | public static Result fail(String msg, Object data) { 31 | return fail(400, msg, data); 32 | } 33 | 34 | public static Result fail(int code, String msg, Object data) { 35 | Result r = new Result(); 36 | r.setCode(code); 37 | r.setMsg(msg); 38 | r.setData(data); 39 | return r; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/SysPermissionService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import cn.ruiyeclub.entity.SysPermission; 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * (SysPermission)表服务接口 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysPermissionService extends IService { 16 | 17 | /** 18 | * 根据角色ID查询角色对应的权限信息 19 | */ 20 | List findPermissionByRoleId(@Param("roleId") Integer roleId); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/SysRolePermissionService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import cn.ruiyeclub.entity.SysRolePermission; 5 | 6 | /** 7 | * (SysRolePermission)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysRolePermissionService extends IService { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/SysRoleService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import cn.ruiyeclub.entity.SysRole; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | /** 10 | * (SysRole)表服务接口 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | public interface SysRoleService extends IService { 16 | 17 | List findRoleByUsername(String username); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/SysUserRoleService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import cn.ruiyeclub.entity.SysUserRole; 5 | 6 | /** 7 | * (SysUserRole)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 22:30:44 11 | */ 12 | public interface SysUserRoleService extends IService { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/SysUserService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import com.baomidou.mybatisplus.extension.service.IService; 4 | import cn.ruiyeclub.entity.SysUser; 5 | 6 | /** 7 | * (SysUser)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2022-05-25 20:09:43 11 | */ 12 | public interface SysUserService extends IService { 13 | 14 | } 15 | 16 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/impl/SysPermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import cn.ruiyeclub.dao.SysPermissionDao; 5 | import cn.ruiyeclub.entity.SysPermission; 6 | import cn.ruiyeclub.service.SysPermissionService; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | 12 | /** 13 | * (SysPermission)表服务实现类 14 | * 15 | * @author Ray。 16 | * @since 2022-05-25 22:30:44 17 | */ 18 | @Service("sysPermissionService") 19 | public class SysPermissionServiceImpl extends ServiceImpl implements SysPermissionService { 20 | 21 | @Resource 22 | private SysPermissionDao sysPermissionDao; 23 | 24 | @Override 25 | public List findPermissionByRoleId(Integer roleId) { 26 | return sysPermissionDao.findPermissionByRoleId(roleId); 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/impl/SysRolePermissionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import cn.ruiyeclub.dao.SysRolePermissionDao; 5 | import cn.ruiyeclub.entity.SysRolePermission; 6 | import cn.ruiyeclub.service.SysRolePermissionService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (SysRolePermission)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | @Service("sysRolePermissionService") 16 | public class SysRolePermissionServiceImpl extends ServiceImpl implements SysRolePermissionService { 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/impl/SysRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import cn.ruiyeclub.dao.SysRoleDao; 5 | import cn.ruiyeclub.entity.SysRole; 6 | import cn.ruiyeclub.service.SysRoleService; 7 | import org.springframework.stereotype.Service; 8 | 9 | import javax.annotation.Resource; 10 | import java.util.List; 11 | 12 | /** 13 | * (SysRole)表服务实现类 14 | * 15 | * @author Ray。 16 | * @since 2022-05-25 22:30:44 17 | */ 18 | @Service("sysRoleService") 19 | public class SysRoleServiceImpl extends ServiceImpl implements SysRoleService { 20 | @Resource 21 | private SysRoleDao sysRoleDao; 22 | 23 | @Override 24 | public List findRoleByUsername(String username) { 25 | return sysRoleDao.findRoleByUsername(username); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/impl/SysUserRoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import cn.ruiyeclub.dao.SysUserRoleDao; 5 | import cn.ruiyeclub.entity.SysUserRole; 6 | import cn.ruiyeclub.service.SysUserRoleService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (SysUserRole)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 22:30:44 14 | */ 15 | @Service("sysUserRoleService") 16 | public class SysUserRoleServiceImpl extends ServiceImpl implements SysUserRoleService { 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/service/impl/SysUserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 4 | import cn.ruiyeclub.dao.SysUserDao; 5 | import cn.ruiyeclub.entity.SysUser; 6 | import cn.ruiyeclub.service.SysUserService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (SysUser)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2022-05-25 20:09:43 14 | */ 15 | @Service("sysUserService") 16 | public class SysUserServiceImpl extends ServiceImpl implements SysUserService { 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/shiro/JwtToken.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.shiro; 2 | 3 | import org.apache.shiro.authc.AuthenticationToken; 4 | 5 | public class JwtToken implements AuthenticationToken { 6 | 7 | private String token; 8 | 9 | public JwtToken(String jwt) { 10 | this.token = jwt; 11 | } 12 | 13 | @Override 14 | public Object getPrincipal() { 15 | return token; 16 | } 17 | 18 | @Override 19 | public Object getCredentials() { 20 | return token; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/util/MD5Utils.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.util; 2 | 3 | import org.apache.shiro.crypto.hash.SimpleHash; 4 | import org.apache.shiro.util.ByteSource; 5 | 6 | /** 7 | * md5加密工具 8 | * 9 | * @author Ray。 10 | */ 11 | public class MD5Utils { 12 | private static final String SALT = "ruiyeclub"; 13 | private static final String ALGORITH_NAME = "md5"; 14 | private static final int HASH_ITERATIONS = 2; 15 | 16 | public static String encrypt(String pswd) { 17 | String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(SALT), HASH_ITERATIONS).toHex(); 18 | return newPassword; 19 | } 20 | 21 | public static String encrypt(String username, String pswd) { 22 | String newPassword = new SimpleHash(ALGORITH_NAME, pswd, ByteSource.Util.bytes(username + SALT), 23 | HASH_ITERATIONS).toHex(); 24 | return newPassword; 25 | } 26 | 27 | public static void main(String[] args) { 28 | System.out.println(MD5Utils.encrypt("test", "123456")); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/java/cn/ruiyeclub/util/ShiroUtil.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.util; 2 | 3 | import cn.ruiyeclub.entity.SysUser; 4 | import org.apache.shiro.SecurityUtils; 5 | 6 | public class ShiroUtil { 7 | 8 | public static SysUser getProfile() { 9 | return (SysUser) SecurityUtils.getSubject().getPrincipal(); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # Spring配置 2 | # DataSource Config 3 | spring: 4 | datasource: 5 | driver-class-name: com.mysql.cj.jdbc.Driver 6 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai 7 | username: root 8 | password: admin 9 | 10 | mybatis-plus: 11 | mapper-locations: classpath*:/mapper/**Mapper.xml 12 | server: 13 | port: 8081 14 | markerhub: 15 | jwt: 16 | secret: f4e2e52034348f86b67cde581c0f9eb5 17 | expire: 604800 18 | header: Authorization 19 | 20 | shiro-redis: 21 | enabled: true 22 | redis-manager: 23 | host: 127.0.0.1:6379 -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/resources/mapper/SysPermissionMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 24 | 25 | -------------------------------------------------------------------------------- /springboot-shiro-jwt/src/main/resources/mapper/SysRoleMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 22 | 23 | -------------------------------------------------------------------------------- /springboot-shiro/README.md: -------------------------------------------------------------------------------- 1 | 1.1、什么是Shiro? 2 | Apache Shiro是一个Java安全权限框架。 3 | Shiro可以非常容易的开发出足够好的应用,其不仅可以在javaEE环境。 4 | Shiro可以完成,认证,授权,加密,会话管理,Web集成,缓存等。 5 | 6 | 核心对象 7 | Subject 用户 8 | SecurityManager 管理所有用户 9 | Realm 连接 10 | 11 | Shiro快速开始 12 | Shiro的Subject分析 13 | SpringBoot整合Shiro环境搭建 14 | Shiro实现登录拦截 15 | Shiro实现用户认证 16 | Shiro整合Mybatis 17 | Shiro请求授权实现 18 | Shiro整合Thymeleaf -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/cn/ruiyeclub/ShiroApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ShiroApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ShiroApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/cn/ruiyeclub/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.mapper; 2 | 3 | import cn.ruiyeclub.pojo.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author Raychen 9 | * @date 2020/3/11 20:51 10 | */ 11 | @Mapper 12 | public interface UserMapper { 13 | User queryUserByName(String name); 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/cn/ruiyeclub/pojo/User.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.pojo; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * @author Ray。 9 | * @create 2020-03-11 20:47 10 | */ 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class User { 15 | private int id; 16 | private String name; 17 | private String password; 18 | private String perms; 19 | } -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/cn/ruiyeclub/service/UserService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.pojo.User; 4 | 5 | /** 6 | * @author Ray。 7 | * @create 2020-03-11 21:18 8 | */ 9 | public interface UserService { 10 | public User queryUserByName(String name); 11 | } -------------------------------------------------------------------------------- /springboot-shiro/src/main/java/cn/ruiyeclub/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.mapper.UserMapper; 4 | import cn.ruiyeclub.pojo.User; 5 | import cn.ruiyeclub.service.UserService; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.annotation.Resource; 9 | 10 | /** 11 | * @author Ray。 12 | * @create 2020-03-11 21:19 13 | */ 14 | @Service 15 | public class UserServiceImpl implements UserService { 16 | 17 | @Resource 18 | private UserMapper userMapper; 19 | 20 | @Override 21 | public User queryUserByName(String name) { 22 | return userMapper.queryUserByName(name); 23 | } 24 | } -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | mybatis: 2 | type-aliases-package: cn.ruiyeclub.pojo 3 | mapper-locations: classpath:mapper/*.xml 4 | spring: 5 | datasource: 6 | username: root 7 | password: root 8 | #解决时区的报错 9 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 10 | driver-class-name: com.mysql.cj.jdbc.Driver 11 | type: com.alibaba.druid.pool.DruidDataSource 12 | 13 | # 连接池配置 14 | initial-size: 5 15 | min-idle: 5 16 | max-active: 20 17 | # 连接等待超时时间 18 | max-wait: 30000 19 | # 配置检测可以关闭的空闲连接间隔时间 20 | time-between-eviction-runs-millis: 60000 21 | # 配置连接在池中的最小生存时间 22 | min-evictable-idle-time-millis: 300000 23 | validation-query: select '1' from dual 24 | test-while-idle: true 25 | test-on-borrow: false 26 | test-on-return: false 27 | # 打开PSCache,并且指定每个连接上PSCache的大小 28 | pool-prepared-statements: true 29 | 30 | #配置监控统计拦截的filters,stat:监控统计、wall:防御sql注入 31 | filters: stat,wall 32 | maxPoolPreparedStatementPerConnectionSize: 20 33 | useGlobalDataSourceStat: true 34 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 35 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/mapper/UserMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | Title 7 | 8 | 9 |

首页

10 | 11 |
12 | 登录 13 |
14 |

15 |
16 |
17 | add 18 |
19 |
20 | update 21 |
22 | 23 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

登录

9 |
10 |

11 |
12 |

用户名:

13 |

密码:

14 |

15 |
16 | 17 | -------------------------------------------------------------------------------- /springboot-shiro/src/main/resources/templates/user/add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

add

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

update

9 | 10 | -------------------------------------------------------------------------------- /springboot-sms/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot整合阿里云SMS短信服务 并实现发送短信验证码的功能 Redis Java 短信验证码 2 | https://blog.csdn.net/weixin_43420255/article/details/105916173 -------------------------------------------------------------------------------- /springboot-sms/src/main/java/cn/ruiyeclub/SmsApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2020/12/2 9 | */ 10 | @SpringBootApplication 11 | public class SmsApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SmsApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-sms/src/main/java/cn/ruiyeclub/service/SendSmsService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | public interface SendSmsService { 4 | 5 | /** 6 | * 发送短信验证码的接口 7 | * @param phoneNum 手机号 8 | * @param code 验证码 9 | * @return 10 | */ 11 | boolean sendSms(String phoneNum, String code); 12 | 13 | } -------------------------------------------------------------------------------- /springboot-sms/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8080 3 | spring: 4 | redis: 5 | host: 127.0.0.1 6 | port: 6379 7 | aliyun: 8 | accessKeyID: 你的accessKeyID 9 | accessKeySecret: 你的accessKeySecret -------------------------------------------------------------------------------- /springboot-socket.io/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot(23) 集成socket.io服务端和客户端实现通信 2 | https://blog.csdn.net/qq_38225558/article/details/104217227 -------------------------------------------------------------------------------- /springboot-socket.io/src/main/java/cn/ruiyeclub/SocketIOApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2021/4/20 9 | */ 10 | @SpringBootApplication 11 | public class SocketIOApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SocketIOApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-socket.io/src/main/java/cn/ruiyeclub/controller/SocketIOController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.service.ISocketIOService; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.web.bind.annotation.PostMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @RestController 11 | @RequestMapping("/api/socket.io") 12 | public class SocketIOController { 13 | 14 | @Autowired 15 | private ISocketIOService socketIOService; 16 | 17 | @PostMapping(value = "/pushMessageToUser") 18 | public boolean pushMessageToUser(@RequestParam String userId, @RequestParam String msgContent) { 19 | socketIOService.pushMessageToUser(userId, msgContent); 20 | return true; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /springboot-socket.io/src/main/java/cn/ruiyeclub/service/ISocketIOService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | public interface ISocketIOService { 4 | /** 5 | * 启动服务 6 | */ 7 | void start(); 8 | 9 | /** 10 | * 停止服务 11 | */ 12 | void stop(); 13 | 14 | /** 15 | * 推送信息给指定客户端 16 | * 17 | * @param userId: 客户端唯一标识 18 | * @param msgContent: 消息内容 19 | */ 20 | void pushMessageToUser(String userId, String msgContent); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-socket.io/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 88 3 | 4 | # netty-socketio 配置 5 | socketio: 6 | host: 127.0.0.1 7 | port: 8888 8 | # 设置最大每帧处理数据的长度,防止他人利用大数据来攻击服务器 9 | maxFramePayloadLength: 1048576 10 | # 设置http交互最大内容长度 11 | maxHttpContentLength: 1048576 12 | # socket连接数大小(如只监听一个端口boss线程组为1即可) 13 | bossCount: 1 14 | workCount: 100 15 | allowCustomRequests: true 16 | # 协议升级超时时间(毫秒),默认10秒。HTTP握手升级为ws协议超时时间 17 | upgradeTimeout: 1000000 18 | # Ping消息超时时间(毫秒),默认60秒,这个时间间隔内没有接收到心跳消息就会发送超时事件 19 | pingTimeout: 6000000 20 | # Ping消息间隔(毫秒),默认25秒。客户端向服务器发送一条心跳消息间隔 21 | pingInterval: 25000 -------------------------------------------------------------------------------- /springboot-swagger3/src/main/java/cn/ruiyeclub/Swagger3Application.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import springfox.documentation.oas.annotations.EnableOpenApi; 7 | 8 | /** 9 | * @author Ray。 10 | * @date 2020/7/18 10:07 11 | */ 12 | @EnableOpenApi 13 | @SpringBootApplication 14 | @MapperScan(basePackages = {"cn.ruiyeclub.dao"}) 15 | public class Swagger3Application { 16 | public static void main(String[] args) { 17 | SpringApplication.run(Swagger3Application.class, args); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /springboot-swagger3/src/main/java/cn/ruiyeclub/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020-07-17 21:57 10 | */ 11 | @Configuration 12 | public class MybatisPlusConfig { 13 | /** 14 | * 分页插件 15 | * @return 16 | */ 17 | @Bean 18 | public PaginationInterceptor paginationInterceptor(){ 19 | return new PaginationInterceptor(); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-swagger3/src/main/java/cn/ruiyeclub/dao/UserRecordDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | 6 | /** 7 | * (UserRecord)表数据库访问层 8 | * 9 | * @author Ray。 10 | * @date 2020-07-18 10:15:36 11 | */ 12 | public interface UserRecordDao extends BaseMapper { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-swagger3/src/main/java/cn/ruiyeclub/entity/UserRecord.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.extension.activerecord.Model; 4 | import io.swagger.annotations.ApiModel; 5 | import io.swagger.annotations.ApiModelProperty; 6 | 7 | /** 8 | * (UserRecord)表实体类 9 | * 10 | * @author Ray。 11 | * @date 2020-07-18 10:15:34 12 | */ 13 | @ApiModel("(UserRecord)表实体类") 14 | public class UserRecord extends Model { 15 | 16 | @ApiModelProperty("主键") 17 | private Integer id; 18 | 19 | @ApiModelProperty("名称") 20 | private String name; 21 | 22 | @ApiModelProperty("年龄") 23 | private Integer age; 24 | 25 | @ApiModelProperty("邮箱") 26 | private String email; 27 | 28 | 29 | public Integer getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Integer id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public Integer getAge() { 46 | return age; 47 | } 48 | 49 | public void setAge(Integer age) { 50 | this.age = age; 51 | } 52 | 53 | public String getEmail() { 54 | return email; 55 | } 56 | 57 | public void setEmail(String email) { 58 | this.email = email; 59 | } 60 | } -------------------------------------------------------------------------------- /springboot-swagger3/src/main/java/cn/ruiyeclub/service/UserRecordService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.UserRecord; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * (UserRecord)表服务接口 8 | * 9 | * @author Ray。 10 | * @date 2020-07-18 10:15:37 11 | */ 12 | public interface UserRecordService extends IService { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-swagger3/src/main/java/cn/ruiyeclub/service/impl/UserRecordServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.UserRecordDao; 4 | import cn.ruiyeclub.entity.UserRecord; 5 | import cn.ruiyeclub.service.UserRecordService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * (UserRecord)表服务实现类 11 | * 12 | * @author Ray。 13 | * @date 2020-07-18 10:15:37 14 | */ 15 | @Service("userRecordService") 16 | public class UserRecordServiceImpl extends ServiceImpl implements UserRecordService { 17 | 18 | } -------------------------------------------------------------------------------- /springboot-swagger3/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | #配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: root -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/cn/ruiyeclub/ThymeleafApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ThymeleafApplication { 8 | public static void main(String[] args) { 9 | SpringApplication.run(ThymeleafApplication.class,args); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/cn/ruiyeclub/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.controller; 2 | 3 | import cn.ruiyeclub.entity.Account; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.ui.Model; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | @Controller 12 | public class IndexController { 13 | 14 | @RequestMapping("/account") 15 | public String account(Model m) { 16 | List list = new ArrayList(); 17 | list.add(new Account("KangKang", "康康", "e10adc3949ba59abbe56e", "超级管理员", "17777777777")); 18 | list.add(new Account("Mike", "麦克", "e10adc3949ba59abbe56e", "管理员", "13444444444")); 19 | list.add(new Account("Jane","简","e10adc3949ba59abbe56e","运维人员","18666666666")); 20 | list.add(new Account("Maria", "玛利亚", "e10adc3949ba59abbe56e", "清算人员", "19999999999")); 21 | m.addAttribute("accountList",list); 22 | return "account"; 23 | } 24 | 25 | @RequestMapping(value = {"/","index","index.html"}) 26 | public String toIndex(){ 27 | return "hello"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/java/cn/ruiyeclub/entity/Account.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | 6 | @Data 7 | @AllArgsConstructor 8 | public class Account { 9 | private String account; 10 | private String name; 11 | private String password; 12 | private String accountType; 13 | private String tel; 14 | } 15 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | thymeleaf: 3 | cache: false -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/static/css/style.css: -------------------------------------------------------------------------------- 1 | table { 2 | margin: 20px 40px 20px 0px; 3 | width: 100%; 4 | border-collapse: collapse; 5 | border-spacing: 0; 6 | table-layout: automatic; 7 | word-wrap: break-all 8 | } 9 | table>tbody>tr:nth-of-type(odd) { 10 | background-color: #F7F7F7 11 | } 12 | 13 | th, td { 14 | padding: 8px; 15 | text-align: left; 16 | vertical-align: middle; 17 | font-weight: normal; 18 | font-size: 12px; 19 | border-bottom: 1px solid #fff; 20 | } 21 | 22 | th { 23 | padding-bottom: 10px; 24 | color: #fff; 25 | font-weight: 700; 26 | background: rgba(66, 185, 131, .9) 27 | } 28 | 29 | td { 30 | border-bottom-width: 1px 31 | } 32 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | account 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
noaccountnamepasswordaccountTypetel
27 | 28 | -------------------------------------------------------------------------------- /springboot-thymeleaf/src/main/resources/templates/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Title 6 | 7 | 8 |

hello world!

9 | 10 | -------------------------------------------------------------------------------- /springboot-undertow/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot使用Undertow代替tomcat 2 | https://www.jianshu.com/p/558f4504d591 -------------------------------------------------------------------------------- /springboot-undertow/src/main/java/cn/ruiyeclub/UndertowApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | 7 | /** 8 | * @author Ray。 9 | * @date 2020/8/7 19:56 10 | */ 11 | @SpringBootApplication 12 | public class UndertowApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(UndertowApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-undertow/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 82 3 | undertow: 4 | #每块buffer的空间大小,越小的空间被利用越充分,不要设置太大,以免影响其他应用,合适即可 5 | buffer-size: 1024 6 | #是否分配的直接内存(NIO直接分配的堆外内存) 7 | direct-buffers: true -------------------------------------------------------------------------------- /springboot-upload/src/main/java/cn/ruiyeclub/UploadApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class UploadApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(UploadApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /springboot-upload/src/main/java/cn/ruiyeclub/config/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | /** 4 | * @author Ray。 5 | * @create 2020-04-19 18:05 6 | */ 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 9 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 10 | 11 | /** 12 | * 资源映射路径 13 | */ 14 | @Configuration 15 | public class WebMvcConfig implements WebMvcConfigurer { 16 | @Override 17 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 18 | registry.addResourceHandler("/upload/**").addResourceLocations("file:D:/images/"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-upload/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | server.port=8081 -------------------------------------------------------------------------------- /springboot-validation/README.md: -------------------------------------------------------------------------------- 1 | 使用Spring Validation优雅地校验参数 2 | https://www.cnblogs.com/zhengxl5566/p/13398546.html -------------------------------------------------------------------------------- /springboot-validation/src/main/java/cn/ruiyeclub/ValidationApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/7/30 18:23 9 | */ 10 | @SpringBootApplication 11 | public class ValidationApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ValidationApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-validation/src/main/java/cn/ruiyeclub/entity/UserModel.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import lombok.Data; 4 | import org.hibernate.validator.constraints.Range; 5 | import org.springframework.format.annotation.DateTimeFormat; 6 | 7 | import javax.validation.constraints.NotNull; 8 | import java.util.Date; 9 | 10 | /** 11 | * @description: 12 | * @author: Ray。 13 | * @create: 2020-01-17 15:17 14 | */ 15 | @Data 16 | public class UserModel { 17 | 18 | @NotNull(message = "用户名称不能为空!") 19 | private String userName; 20 | 21 | @NotNull(message = "age不能为null!") 22 | @Range(min = 1, max = 888, message = "范围为1至888") 23 | private Integer age; 24 | 25 | /** 26 | * 日期格式化转换 27 | */ 28 | @NotNull(message = "日期不能为null!") 29 | @DateTimeFormat(pattern = "yyyy-MM-dd") 30 | private Date date; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /springboot-vue-axios/README.md: -------------------------------------------------------------------------------- 1 | SpringBoot+Mybatis+Vue 实现商品模块的crud操作 2 | https://segmentfault.com/a/1190000037468625 -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/java/cn/ruiyeclub/VueAxiosApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2020/10/19 9 | */ 10 | @SpringBootApplication 11 | public class VueAxiosApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(VueAxiosApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/java/cn/ruiyeclub/dao/DeptDao.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.dao; 2 | 3 | import cn.ruiyeclub.entity.Dept; 4 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | * 部门表(Dept)表数据库访问层 9 | * 10 | * @author Ray。 11 | * @since 2020-10-19 16:43:43 12 | */ 13 | @Mapper 14 | public interface DeptDao extends BaseMapper { 15 | 16 | } -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/java/cn/ruiyeclub/entity/Dept.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.entity; 2 | 3 | import com.baomidou.mybatisplus.annotation.IdType; 4 | import com.baomidou.mybatisplus.annotation.TableId; 5 | import com.baomidou.mybatisplus.annotation.TableName; 6 | import com.baomidou.mybatisplus.extension.activerecord.Model; 7 | import lombok.Data; 8 | 9 | /** 10 | * 部门表(Dept)表实体类 11 | * 12 | * @author Ray。 13 | * @since 2020-10-19 16:43:42 14 | */ 15 | @Data 16 | @TableName("dept") 17 | public class Dept extends Model { 18 | 19 | @TableId(value = "deptno", type = IdType.AUTO) 20 | private Long deptno; 21 | 22 | private String dname; 23 | 24 | private String dbSource; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/java/cn/ruiyeclub/service/DeptService.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service; 2 | 3 | import cn.ruiyeclub.entity.Dept; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | /** 7 | * 部门表(Dept)表服务接口 8 | * 9 | * @author Ray。 10 | * @since 2020-10-19 16:43:44 11 | */ 12 | public interface DeptService extends IService { 13 | 14 | } -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/java/cn/ruiyeclub/service/impl/DeptServiceImpl.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.service.impl; 2 | 3 | import cn.ruiyeclub.dao.DeptDao; 4 | import cn.ruiyeclub.entity.Dept; 5 | import cn.ruiyeclub.service.DeptService; 6 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * 部门表(Dept)表服务实现类 11 | * 12 | * @author Ray。 13 | * @since 2020-10-19 16:43:44 14 | */ 15 | @Service("deptService") 16 | public class DeptServiceImpl extends ServiceImpl implements DeptService { 17 | 18 | } -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 81 3 | 4 | # 配置数据源 5 | spring: 6 | datasource: 7 | driver-class-name: com.mysql.cj.jdbc.Driver 8 | url: jdbc:mysql://localhost:3306/boot_hello?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai 9 | username: root 10 | password: admin 11 | 12 | # 配置sql打印日志 13 | mybatis-plus: 14 | configuration: 15 | log-impl: org.apache.ibatis.logging.stdout.StdOutImpl 16 | type-aliases-package: cn.ruiyeclub.entity.* -------------------------------------------------------------------------------- /springboot-vue-axios/src/main/resources/static/dept-vue.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | The Dept Page 6 | 7 | 8 |
9 |

The Dept Page

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
编号名称资源
{{d.deptno}}{{d.dname}}{{d.dbSource}}
27 |
28 | 29 | 30 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /springboot-websocket-server-client/src/main/java/cn/ruiyeclub/Application.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Cr. 8 | * @date 2024/5/30 9 | */ 10 | @SpringBootApplication 11 | public class Application { 12 | public static void main(String[] args) { 13 | SpringApplication.run(Application.class, args); 14 | } 15 | } -------------------------------------------------------------------------------- /springboot-websocket/README.md: -------------------------------------------------------------------------------- 1 | springboot整合websocket 2 | https://mrbird.cc/Spring-Boot%E6%95%B4%E5%90%88WebSocket.html 3 | 4 | https://segmentfault.com/a/1190000016012270 -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/cn/ruiyeclub/WebsocketApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2021/1/20 9 | */ 10 | @SpringBootApplication 11 | public class WebsocketApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(WebsocketApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-websocket/src/main/java/cn/ruiyeclub/config/WebSocketServerConfig.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import cn.ruiyeclub.handler.MyStringWebSocketHandler; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.web.socket.config.annotation.EnableWebSocket; 7 | import org.springframework.web.socket.config.annotation.WebSocketConfigurer; 8 | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; 9 | 10 | @Configuration 11 | @EnableWebSocket 12 | public class WebSocketServerConfig implements WebSocketConfigurer { 13 | 14 | @Autowired 15 | private MyStringWebSocketHandler myStringWebSocketHandler; 16 | 17 | @Override 18 | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 19 | registry.addHandler(myStringWebSocketHandler, "/connect").withSockJS(); 20 | } 21 | } -------------------------------------------------------------------------------- /springboot-wxpay/README.md: -------------------------------------------------------------------------------- 1 | 基于Spring Boot 和 WxJava 实现的微信支付Java后端Demo 2 | https://github.com/binarywang/weixin-java-pay-demo -------------------------------------------------------------------------------- /springboot-wxpay/src/main/java/cn/ruiyeclub/WxpayApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Ray。 8 | * @date 2020/9/17 12:20 9 | */ 10 | @SpringBootApplication 11 | public class WxpayApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(WxpayApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-wxpay/src/main/java/cn/ruiyeclub/config/WxPayProperties.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.config; 2 | 3 | import lombok.Data; 4 | import org.springframework.boot.context.properties.ConfigurationProperties; 5 | 6 | /** 7 | * wxpay pay properties. 8 | * 9 | * @author Binary Wang 10 | */ 11 | @Data 12 | @ConfigurationProperties(prefix = "wx.pay") 13 | public class WxPayProperties { 14 | /** 15 | * 设置微信公众号或者小程序等的appid 16 | */ 17 | private String appId; 18 | 19 | /** 20 | * 微信支付商户号 21 | */ 22 | private String mchId; 23 | 24 | /** 25 | * 微信支付商户密钥 26 | */ 27 | private String mchKey; 28 | 29 | /** 30 | * 服务商模式下的子商户公众账号ID,普通模式请不要配置,请在配置文件中将对应项删除 31 | */ 32 | private String subAppId; 33 | 34 | /** 35 | * 服务商模式下的子商户号,普通模式请不要配置,最好是请在配置文件中将对应项删除 36 | */ 37 | private String subMchId; 38 | 39 | /** 40 | * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定 41 | */ 42 | private String keyPath; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /springboot-wxpay/src/main/java/cn/ruiyeclub/error/ErrorController.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.error; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | /** 8 | *
 9 |  * 出错页面控制器
10 |  * Created by Binary Wang on 2018/8/25.
11 |  * 
12 | * 13 | * @author Binary Wang 14 | */ 15 | @Controller 16 | @RequestMapping("/error") 17 | public class ErrorController { 18 | 19 | @GetMapping(value = "/404") 20 | public String error404() { 21 | return "error"; 22 | } 23 | 24 | @GetMapping(value = "/500") 25 | public String error500() { 26 | return "error"; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /springboot-wxpay/src/main/java/cn/ruiyeclub/error/ErrorPageConfiguration.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.error; 2 | 3 | import org.springframework.boot.web.server.ErrorPage; 4 | import org.springframework.boot.web.server.ErrorPageRegistrar; 5 | import org.springframework.boot.web.server.ErrorPageRegistry; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | *
11 |  * 配置错误状态与对应访问路径
12 |  * Created by Binary Wang on 2018/8/25.
13 |  * 
14 | * 15 | * @author Binary Wang 16 | */ 17 | @Component 18 | public class ErrorPageConfiguration implements ErrorPageRegistrar { 19 | @Override 20 | public void registerErrorPages(ErrorPageRegistry errorPageRegistry) { 21 | errorPageRegistry.addErrorPages( 22 | new ErrorPage(HttpStatus.NOT_FOUND, "/error/404"), 23 | new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500") 24 | ); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /springboot-wxpay/src/main/java/cn/ruiyeclub/utils/PayUtils.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub.utils; 2 | 3 | import java.security.MessageDigest; 4 | import java.util.Random; 5 | 6 | public class PayUtils { 7 | 8 | 9 | /** 10 | * 生成随机字符串nonce_str 11 | */ 12 | public static String get_nonce_str() { 13 | String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 14 | Random random = new Random(); 15 | StringBuffer sb = new StringBuffer(); 16 | for (int i = 0; i < 32; i++) { 17 | int number = random.nextInt(base.length()); 18 | sb.append(base.charAt(number)); 19 | } 20 | return sb.toString(); 21 | } 22 | 23 | public static String MD5(String data){ 24 | StringBuilder sb = new StringBuilder(); 25 | try { 26 | MessageDigest md = MessageDigest.getInstance("MD5"); 27 | byte[] array = md.digest(data.getBytes("UTF-8")); 28 | for (byte item : array) { 29 | sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3)); 30 | } 31 | } catch (Exception e) { 32 | e.printStackTrace(); 33 | } 34 | return sb.toString().toUpperCase(); 35 | } 36 | 37 | public static void main(String[] args) { 38 | System.out.println(get_nonce_str().length()); 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /springboot-wxpay/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | logging: 2 | level: 3 | org.springframework.web: info 4 | com.github.binarywang.demo.wx.pay: debug 5 | com.github.binarywang.wxpay: debug 6 | 7 | wx: 8 | pay: 9 | appId: #微信公众号或者小程序等的appid 10 | mchId: #微信支付商户号 11 | mchKey: #微信支付商户密钥 12 | subAppId: #服务商模式下的子商户公众账号ID 13 | subMchId: #服务商模式下的子商户号 14 | keyPath: # p12证书的位置,可以指定绝对路径,也可以指定类路径(以classpath:开头) 15 | notifyUrl: -------------------------------------------------------------------------------- /springboot-wxpay/src/main/resources/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 出错啦! 5 | 6 | 7 | 8 |

9 |

10 |

11 |

12 |

13 |

14 |

15 | 16 | -------------------------------------------------------------------------------- /springboot-xxl-job/README.md: -------------------------------------------------------------------------------- 1 | 三分钟搞定 XXL-JOB 分布式任务调度平台(ps:搭建该项目需要先运行xxl-job) 2 | https://mp.weixin.qq.com/s/a7dbQD_bfEcsJokZ37tkEQ -------------------------------------------------------------------------------- /springboot-xxl-job/src/main/java/cn/ruiyeclub/XxlJobApplication.java: -------------------------------------------------------------------------------- 1 | package cn.ruiyeclub; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @Author: Ray。 8 | * @Date: 2022/5/17 9 | */ 10 | @SpringBootApplication 11 | public class XxlJobApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(XxlJobApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-xxl-job/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | # web port 2 | server: 3 | port: 8081 4 | 5 | xxl: 6 | job: 7 | admin: 8 | # 调度中心部署跟地址 [选填]:如调度中心集群部署存在多个地址则用逗号分隔。 9 | # 执行器将会使用该地址进行"执行器心跳注册"和"任务结果回调";为空则关闭自动注册; 10 | addresses: http://127.0.0.1:8080/xxl-job-admin 11 | # 执行器通讯TOKEN [选填]:非空时启用; 12 | accessToken: 13 | executor: 14 | # 执行器AppName [选填]:执行器心跳注册分组依据;为空则关闭自动注册 15 | appname: springboot-xxl-job 16 | # 执行器注册 [选填]:优先使用该配置作为注册地址,为空时使用内嵌服务 ”IP:PORT“ 作为注册地址。 17 | #从而更灵活的支持容器类型执行器动态IP和动态映射端口问题。 18 | address: 19 | # 执行器IP [选填]:默认为空表示自动获取IP,多网卡时可手动设置指定IP,该IP不会绑定Host仅作为通讯实用; 20 | # 地址信息用于 "执行器注册" 和 "调度中心请求并触发任务"; 21 | ip: 22 | # 执行器端口号 [选填]:小于等于0则自动获取;默认端口为9999,单机部署多个执行器时,注意要配置不同执行器端口; 23 | port: 9999 24 | # 执行器运行日志文件存储磁盘路径 [选填] :需要对该路径拥有读写权限;为空则使用默认路径; 25 | logpath: /data/applogs/xxl-job/jobhandler 26 | # 执行器日志文件保存天数 [选填] : 过期日志自动清理, 限制值大于等于3时生效; 否则, 如-1, 关闭自动清理功能; 27 | logretentiondays: 30 28 | logging: 29 | config: classpath:logback.xml -------------------------------------------------------------------------------- /springboot-xxl-job/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | logback 5 | 6 | 7 | 8 | 9 | %d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n 10 | 11 | 12 | 13 | 14 | ${log.path} 15 | 16 | ${log.path}.%d{yyyy-MM-dd}.zip 17 | 18 | 19 | %date %level [%thread] %logger{36} [%file : %line] %msg%n 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | --------------------------------------------------------------------------------