├── springboot-learn-custom-event ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── custom │ └── event │ ├── SpringBootEventApplication.java │ ├── emailevents │ ├── EmailEventPublish.java │ ├── EmailEvent.java │ └── EmailEventListener.java │ ├── controller │ ├── GlobalExceptionController.java │ └── MailEventController.java │ └── configuration │ └── ThreadPool.java ├── springboot-learn-threadlocal ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── thread │ ├── entity │ └── User.java │ ├── ThreadLocalApplication.java │ ├── base │ └── Message.java │ ├── interceptor │ ├── UserContextHolder.java │ ├── WebMvcConfig.java │ └── AuthActionInterceptor.java │ └── controller │ └── ThreadController.java ├── springboot-learn-staticftl ├── src │ └── main │ │ ├── resources │ │ ├── static │ │ │ ├── css │ │ │ │ └── test.css │ │ │ └── html │ │ │ │ └── 1574062245007.html │ │ ├── templates │ │ │ ├── index.html │ │ │ └── blog │ │ │ │ └── detail.html │ │ └── application.yml │ │ └── java │ │ └── com │ │ └── plf │ │ └── learn │ │ └── staticftl │ │ ├── bean │ │ └── Blog.java │ │ ├── repository │ │ └── BlogRepository.java │ │ ├── SpringBootStaticFtlApplication.java │ │ ├── controller │ │ ├── TestController.java │ │ └── BlogController.java │ │ ├── component │ │ └── ActiveMQProducer.java │ │ └── listener │ │ └── BlogStaticFtlListener.java └── build.gradle ├── springboot-learn-mail ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── mail │ ├── SpringBootMailApplication.java │ ├── controller │ └── MailController.java │ └── config │ └── ThreadPoolTaskConfig.java ├── springboot-learn-mongodb ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── mongodb │ ├── MongoDBApplication.java │ ├── repository │ └── CommentRepository.java │ ├── bean │ └── Comment.java │ ├── controller │ └── CommentController.java │ └── service │ └── CommentService.java ├── springboot-learn-solr ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── solr │ ├── SolrApplication.java │ ├── entity │ └── Worker.java │ └── controller │ └── SolrController.java ├── springboot-learn-document ├── build.gradle └── src │ └── main │ ├── resources │ ├── application.yml │ └── templates │ │ └── word │ │ └── template.doc │ └── java │ └── com │ └── plf │ └── learn │ └── document │ ├── enums │ └── DocumentEnums.java │ ├── utils │ ├── interfaces │ │ └── OperateDocument.java │ └── CloseUtils.java │ ├── SpringBootDocumentApplication.java │ ├── service │ └── AnalysisFileService.java │ ├── controller │ └── UploadFileController.java │ └── container │ └── DocumentContext.java ├── springboot-learn-jetcache ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── jetcache │ ├── bean │ └── Person.java │ ├── service │ ├── PersonService.java │ └── impl │ │ └── PersonServiceImpl.java │ ├── SpringBootJetcacheApplication.java │ └── controller │ └── PersonController.java ├── springboot-learn-kafka ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── kafka │ │ ├── KafkaApplication.java │ │ ├── message │ │ └── Message.java │ │ ├── consumer │ │ └── KafkaConsumer.java │ │ ├── producer │ │ └── KafkaProducer.java │ │ └── controller │ │ └── KafkaController.java │ └── resources │ └── application.yml ├── springboot-learn-neo4j ├── build.gradle └── src │ ├── main │ ├── resources │ │ └── application.yml │ └── java │ │ └── com │ │ └── plf │ │ └── learn │ │ └── neo4j │ │ ├── Neo4jApplication.java │ │ ├── entity │ │ └── MinFamily.java │ │ ├── controllrt │ │ └── Neo4jController.java │ │ └── dao │ │ └── MinFamilyRepository.java │ └── test │ └── java │ └── com │ └── plf │ └── learn │ └── neo4j │ └── Neo4jTest.java ├── springboot-learn-api-limiter ├── src │ ├── main │ │ ├── resources │ │ │ ├── test.http │ │ │ └── application.yml │ │ └── java │ │ │ └── com │ │ │ └── plf │ │ │ └── learn │ │ │ └── limiter │ │ │ ├── SpringBootApiLimiterApplication.java │ │ │ ├── controller │ │ │ └── ApiController.java │ │ │ └── annotations │ │ │ └── ApiRateLimiter.java │ └── test │ │ └── java │ │ └── com │ │ └── plf │ │ └── learn │ │ └── httpclient │ │ └── HttpTest.java └── build.gradle ├── springboot-learn-elasticsearch ├── build.gradle └── src │ └── main │ ├── resources │ ├── application.yml │ └── readme.txt │ └── java │ └── com │ └── plf │ └── learn │ └── elasticsearch │ ├── repository │ └── BookRepository.java │ ├── ElasticSearchApplication.java │ ├── bean │ └── Book.java │ ├── service │ ├── IndexService.java │ └── BookService.java │ └── controller │ └── BookController.java ├── springboot-learn-jpa ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── jpa │ │ ├── dto │ │ └── StudentDto.java │ │ ├── SpringBootJpaApplication.java │ │ ├── bean │ │ ├── School.java │ │ └── Student.java │ │ ├── repository │ │ └── StudentRepository.java │ │ ├── controller │ │ └── StudentController.java │ │ └── service │ │ └── StudentService.java │ └── resources │ └── application.yml ├── springboot-learn-log ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── log │ ├── repository │ └── LogMessageRepository.java │ ├── LogApplication.java │ ├── service │ └── LogMessageService.java │ ├── entity │ └── LogMessage.java │ ├── controller │ └── LogController.java │ └── annotation │ └── Loggable.java ├── springboot-learn-caffeine ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── caffeine │ ├── SpringBootCaffeineApplication.java │ ├── dao │ └── UserInfoDao.java │ ├── controller │ └── CaffeineController.java │ ├── service │ └── UserInfoService.java │ └── config │ ├── CaffeineConfig.java │ └── CaffeineMonitorAspect.java ├── springboot-learn-redis ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── redis │ │ ├── annotations │ │ └── ApiIdempotent.java │ │ ├── RedisSentinelApplication.java │ │ ├── service │ │ ├── TokenService.java │ │ └── impl │ │ │ └── TokenServiceImpl.java │ │ ├── configuration │ │ ├── GlobalExceptionHandler.java │ │ └── WebConfiguration.java │ │ ├── controller │ │ └── RedisController.java │ │ ├── utils │ │ └── RedisUtils.java │ │ └── interceptor │ │ └── ApiIdempotentInterceptor.java │ └── resources │ └── application.yml ├── springboot-learn-mybatis-plus ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── mybatisplus │ │ ├── mapper │ │ ├── UserMapper.java │ │ └── LogMapper.java │ │ ├── service │ │ ├── UserService.java │ │ ├── LogService.java │ │ └── impl │ │ │ ├── UserServiceImpl.java │ │ │ └── LogServiceImpl.java │ │ ├── dto │ │ └── LogDto.java │ │ ├── SpringBootMybatisPlusApplication.java │ │ ├── entity │ │ ├── User.java │ │ └── Log.java │ │ ├── config │ │ ├── MybatisPlusConfig.java │ │ └── MyMetaObjectHandler.java │ │ └── controller │ │ └── LogController.java │ └── resources │ └── application.yml ├── springboot-learn-share-session ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── share │ │ └── session │ │ ├── SpringBootShareSessionApplication.java │ │ └── controller │ │ └── ShareSessionController.java │ └── resources │ └── application.yml ├── springboot-learn-websocket ├── build.gradle └── src │ └── main │ ├── resources │ ├── application.yml │ └── note.txt │ └── java │ └── com │ └── plf │ └── learn │ └── websocket │ ├── entity │ ├── RequestMessage.java │ └── ResponseMessage.java │ ├── WebSocketApplication.java │ ├── service │ └── WebSocketService.java │ ├── config │ └── WebSocketConfig.java │ └── controller │ └── WebSocketController.java ├── springboot-learn-aop-multidata ├── build.gradle └── src │ └── main │ ├── resources │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── aop │ └── multidata │ ├── SpringBootMultidata.java │ ├── annotation │ └── TargetDataSource.java │ ├── config │ ├── DynamicDataSource.java │ └── DynamicDataSourceHolder.java │ ├── service │ └── CountTablesService.java │ └── controller │ └── CountTablesController.java ├── springboot-learn-sharding-jdbc ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── sharding │ │ ├── bean │ │ └── Order.java │ │ ├── test │ │ └── SnowTest.java │ │ ├── mapper │ │ └── OrderMapper.java │ │ ├── service │ │ └── OrderService.java │ │ ├── SpringBootShardingApplication.java │ │ └── controller │ │ └── OrderController.java │ └── resources │ ├── sql │ ├── ds0.sql │ └── ds1.sql │ └── application.yml ├── springboot-learn-distributed-lock ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── lock │ │ ├── SpringBootLockApplication.java │ │ ├── config │ │ ├── RedissonConfig.java │ │ └── CuratorConfig.java │ │ ├── utils │ │ └── StringUtils.java │ │ ├── test │ │ └── BuyTest.java │ │ └── redis │ │ ├── RedissonDistributionLock.java │ │ └── RedisUtils.java │ └── resources │ └── application.yml ├── springboot-learn-elastic-job ├── build.gradle └── src │ └── main │ ├── resources │ ├── application.yml │ └── readme.txt │ └── java │ └── com │ └── plf │ └── learn │ └── elastic │ ├── bean │ └── FileCustom.java │ ├── SpringBootElasticApplication.java │ ├── service │ └── FileCustomService.java │ ├── mapper │ └── FileCustomMapper.java │ ├── config │ └── ElasticJobRegistryCenterConfig.java │ └── job │ └── FileBackupJob.java ├── springboot-learn-jwt ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── jwt │ │ ├── bean │ │ └── Person.java │ │ ├── SpringBootJwtApplication.java │ │ ├── repository │ │ └── PersonRepository.java │ │ ├── common │ │ ├── JwtResult.java │ │ └── ResponseData.java │ │ ├── service │ │ └── PersonService.java │ │ ├── utils │ │ └── RedisUtils.java │ │ └── filter │ │ └── JwtFilter.java │ └── resources │ ├── application.yml │ └── readme.txt ├── springboot-learn-shiro ├── build.gradle └── src │ └── main │ ├── resources │ ├── templates │ │ ├── fail.html │ │ ├── noperssion.html │ │ ├── user.html │ │ ├── admin.html │ │ ├── defaultException.html │ │ ├── hello.html │ │ ├── success.html │ │ └── login.html │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── shiro │ ├── repository │ └── UserRepository.java │ ├── service │ ├── AdminActionService.java │ └── UserService.java │ ├── SpringBootShiroApplication.java │ ├── utils │ ├── KeyDecode.java │ └── EncryptionPassword.java │ ├── config │ └── GlobalDefaultExceptionHandler.java │ └── bean │ └── User.java ├── springboot-learn-dataway ├── build.gradle └── src │ └── main │ ├── resources │ ├── readme.txt │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── dataway │ ├── SpringBootDatawayApplication.java │ └── hasor │ └── module │ └── HasorModule.java ├── springboot-learn-security ├── build.gradle └── src │ └── main │ ├── resources │ ├── templates │ │ ├── 403.html │ │ ├── product │ │ │ ├── add.html │ │ │ ├── delete.html │ │ │ ├── list.html │ │ │ └── update.html │ │ ├── index.html │ │ └── login.html │ └── application.yml │ └── java │ └── com │ └── plf │ └── learn │ └── security │ ├── entity │ ├── Role.java │ ├── Permission.java │ └── User.java │ ├── SecurityApplication.java │ ├── controller │ ├── IndexController.java │ └── ProductController.java │ ├── config │ └── ErrorPageConfig.java │ ├── mapper │ └── UserMapper.java │ ├── handler │ └── MyAuthenticationFailtureHandler.java │ └── service │ └── MyUserDetailService.java ├── springboot-learn-druid-monitor ├── build.gradle └── src │ └── main │ ├── java │ └── com │ │ └── plf │ │ └── learn │ │ └── monitor │ │ ├── bean │ │ └── Person.java │ │ ├── mapper │ │ └── PersonMapper.java │ │ ├── SpringBootMonitorApplication.java │ │ ├── service │ │ └── PersonService.java │ │ ├── controller │ │ └── PersonController.java │ │ └── config │ │ └── DruidConfiguration.java │ └── resources │ ├── mapper │ └── PersonMapper.xml │ └── application.yml ├── .gitignore └── settings.gradle /springboot-learn-custom-event/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | 3 | } -------------------------------------------------------------------------------- /springboot-learn-threadlocal/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | 3 | } 4 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/resources/static/css/test.css: -------------------------------------------------------------------------------- 1 | h1 span {color:red} -------------------------------------------------------------------------------- /springboot-learn-mail/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.mail 3 | } 4 | -------------------------------------------------------------------------------- /springboot-learn-mongodb/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.mongodb 3 | } -------------------------------------------------------------------------------- /springboot-learn-solr/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.solr 3 | } 4 | -------------------------------------------------------------------------------- /springboot-learn-document/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.word 3 | } 4 | -------------------------------------------------------------------------------- /springboot-learn-jetcache/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.jetcache 3 | } -------------------------------------------------------------------------------- /springboot-learn-kafka/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.kafka 3 | } 4 | 5 | -------------------------------------------------------------------------------- /springboot-learn-neo4j/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.neo4j 3 | } 4 | 5 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/src/main/resources/test.http: -------------------------------------------------------------------------------- 1 | GET http://localhost:8080/api/limiter/hello -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.elasticsearch 3 | } 4 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | servlet: 3 | context-path: /api/limiter -------------------------------------------------------------------------------- /springboot-learn-jpa/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.mysql 3 | implementation libs.jpa 4 | } 5 | -------------------------------------------------------------------------------- /springboot-learn-log/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.mongodb 3 | implementation libs.aop 4 | } 5 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.guava 3 | implementation libs.aop 4 | } 5 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.caffeine 3 | implementation libs.aop 4 | } 5 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8100 3 | servlet: 4 | context-path: /document -------------------------------------------------------------------------------- /springboot-learn-redis/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.redis 3 | implementation libs.commonspool 4 | } 5 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.mysql 3 | implementation libs.mybatisplus 4 | } -------------------------------------------------------------------------------- /springboot-learn-share-session/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.redis 3 | implementation libs.springsession 4 | } -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8026 3 | servlet: 4 | context-path: /thread 5 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8001 3 | servlet: 4 | context-path: /customevent 5 | -------------------------------------------------------------------------------- /springboot-learn-websocket/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.websocket 3 | implementation libs.thymeleaf 4 | } 5 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8026 3 | sprnig: 4 | thymeleaf: 5 | cache: false 6 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.mysql 3 | implementation libs.aop 4 | implementation libs.jdbc 5 | } 6 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.mysql 3 | implementation libs.mybatis 4 | implementation libs.sharding 5 | } -------------------------------------------------------------------------------- /springboot-learn-staticftl/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.freemarker 3 | implementation libs.mongodb 4 | implementation libs.activemq 5 | } -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.redis 3 | implementation libs.redisson 4 | implementation libs.curator 5 | } 6 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.mysql 3 | implementation libs.elasticjob 4 | implementation libs.mybatis 5 | } 6 | -------------------------------------------------------------------------------- /springboot-learn-jwt/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.jwt 3 | implementation libs.mysql 4 | implementation libs.jpa 5 | implementation libs.redis 6 | } 7 | -------------------------------------------------------------------------------- /springboot-learn-neo4j/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | data: 3 | neo4j: 4 | username: neo4j 5 | password: 12345678 6 | uri: bolt://192.168.164.130:7687 -------------------------------------------------------------------------------- /springboot-learn-shiro/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.shiro 3 | implementation libs.thymeleaf 4 | implementation libs.mysql 5 | implementation libs.jpa 6 | } 7 | -------------------------------------------------------------------------------- /springboot-learn-dataway/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.dataway 3 | implementation libs.druid 4 | implementation libs.mysql 5 | implementation libs.jdbc 6 | } 7 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/resources/templates/word/template.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Panlf/springboot-learn/HEAD/springboot-learn-document/src/main/resources/templates/word/template.doc -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8089 3 | servlet: 4 | context-path: /caffeine 5 | 6 | spring: 7 | main: 8 | allow-bean-definition-overriding: true -------------------------------------------------------------------------------- /springboot-learn-security/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | implementation libs.thymeleaf 3 | implementation libs.mybatis 4 | implementation libs.mysql 5 | implementation libs.springsecurity 6 | } 7 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/403.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 6 | 7 | 8 | 你无权访问 9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-solr/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8025 3 | servlet: 4 | context-path: /solr 5 | spring: 6 | data: 7 | solr: 8 | host: http://127.0.0.1:8983/solr/test_solr2 -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/templates/fail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录失败 6 | 7 | 8 |

登录失败

9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/templates/noperssion.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Shiro异常页面 6 | 7 | 8 | 没有权限 9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/product/add.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 商品添加 6 | 7 | 8 | 这是商品添加页面 9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/product/delete.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 商品删除 6 | 7 | 8 | 这是商品删除页面 9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/product/list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 商品列表 6 | 7 | 8 | 这是商品列表页面 9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/product/update.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 商品更新 6 | 7 | 8 | 这是商品更新页面 9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/templates/user.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | user 6 | 7 | 8 |

USER PAGE

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

ADMIN PAGE

9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/templates/defaultException.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 异常页面 6 | 7 | 8 |

不好意思,出现异常

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

Hello,Thymeleaf

9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies{ 2 | implementation libs.postgresql 3 | implementation libs.pagehelper 4 | implementation libs.mybatis 5 | implementation libs.log4j 6 | implementation libs.druid 7 | } 8 | 9 | -------------------------------------------------------------------------------- /springboot-learn-log/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8012 3 | servlet: 4 | context-path: /log 5 | 6 | spring: 7 | data: 8 | mongodb: 9 | host: 127.0.0.1 10 | port: 27017 11 | database: log 12 | -------------------------------------------------------------------------------- /springboot-learn-dataway/src/main/resources/readme.txt: -------------------------------------------------------------------------------- 1 | hasor-dataway的Jar包中的META-INF中选择初始化的数据表 2 | 3 | 1、http://127.0.0.1:8066/dataway/interface-ui/ 访问管理页面,进行新建接口 4 | 2、配置好SQL或者DataQL,然后Smoke Test测试,测试通过Publish接口 5 | 3、根据配置的接口进行调用http://127.0.0.1:8066/dataway/api/ -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/resources/static/html/1574062245007.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |

母猪的产后护理

9 |

母猪

10 |
吃了算了
11 | 12 | -------------------------------------------------------------------------------- /springboot-learn-mongodb/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8018 3 | servlet: 4 | context-path: /mongodb 5 | 6 | spring: 7 | data: 8 | mongodb: 9 | host: 127.0.0.1 10 | port: 27017 11 | database: articledb 12 | 13 | 14 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8013 3 | servlet: 4 | context-path: /elastic 5 | 6 | 7 | spring: 8 | data: 9 | elasticsearch: 10 | cluster-name: my-application 11 | cluster-nodes: 127.0.0.1:9300 12 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/entity/Role.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Role { 7 | 8 | private Integer id; 9 | 10 | private String roleName; 11 | 12 | private String roleDesc; 13 | } 14 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/entity/Permission.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.entity; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Permission { 7 | private Integer id; 8 | 9 | private String permName; 10 | 11 | private String permTag; 12 | } 13 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/templates/success.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录成功 6 | 7 | 8 |

登录成功

9 | 10 |
11 | 12 | 13 | Test ShiroService 14 | 15 | -------------------------------------------------------------------------------- /springboot-learn-mail/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8002 3 | servlet: 4 | context-path: /mail 5 | 6 | spring: 7 | mail: 8 | # smtp.126.com smtp.qq.com 9 | host: smtp.163.com 10 | username: plflovecw@163.com 11 | password: cw0713 12 | default-encoding: UTF-8 13 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.plf.learn.mybatisplus.entity.User; 5 | 6 | public interface UserMapper extends BaseMapper{ 7 | 8 | } 9 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Test 5 | 6 | 7 | 8 |

Hello,My Name is ${name}

9 | 10 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/resources/templates/blog/detail.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ${blog.title} 6 | 7 | 8 |

${blog.title}

9 |

${blog.author}

10 |
${blog.content}
11 | 12 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.service; 2 | 3 | import java.util.List; 4 | 5 | import com.plf.learn.mybatisplus.entity.User; 6 | 7 | public interface UserService { 8 | public List listUser(String username); 9 | } 10 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/dto/LogDto.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.dto; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | @Data 8 | public class LogDto{ 9 | private String content; 10 | 11 | private Date createtime; 12 | 13 | private String username; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/java/com/plf/learn/monitor/bean/Person.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.monitor.bean; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/7/11 8 | */ 9 | @Data 10 | public class Person { 11 | private Integer id; 12 | private String name; 13 | private Integer age; 14 | } 15 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8022 3 | servlet: 4 | context-path: /elastic 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 首页 6 | 7 | 8 | 以下是网站的功能
9 | 商品添加
10 | 商品删除
11 | 商品列表
12 | 商品更新
13 | 14 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录页 6 | 7 | 8 |
9 | username: 10 | password: 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/bean/Blog.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl.bean; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/11/15 8 | */ 9 | @Data 10 | public class Blog { 11 | 12 | private String id; 13 | 14 | private String title; 15 | 16 | private String author; 17 | 18 | private String content; 19 | 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-log/src/main/java/com/plf/learn/log/repository/LogMessageRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.log.repository; 2 | 3 | import com.plf.learn.log.entity.LogMessage; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2020/3/18 9 | */ 10 | public interface LogMessageRepository extends MongoRepository { 11 | } 12 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/resources/mapper/PersonMapper.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/java/com/plf/learn/monitor/mapper/PersonMapper.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.monitor.mapper; 2 | 3 | import com.plf.learn.monitor.bean.Person; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/7/11 11 | */ 12 | @Repository 13 | public interface PersonMapper { 14 | public List findPerson(); 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 登录 6 | 7 | 8 | 9 |

登录页面

10 |
11 | 用户名:
12 | 密码:
13 | 14 |
15 | 16 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/java/com/plf/learn/sharding/bean/Order.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.sharding.bean; 2 | 3 | import lombok.Data; 4 | import org.apache.ibatis.type.Alias; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/6/12 9 | */ 10 | @Data 11 | @Alias("t_order") 12 | public class Order { 13 | private Long id; 14 | private Long orderId; 15 | private Long userId; 16 | private String username; 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/java/com/plf/learn/websocket/entity/RequestMessage.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.websocket.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * 请求的消息类 9 | * @author Panlf 10 | * @date 2020/3/20 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class RequestMessage { 16 | private String name; 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/java/com/plf/learn/websocket/entity/ResponseMessage.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.websocket.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * 响应的消息类 9 | * @author Panlf 10 | * @date 2020/3/20 11 | */ 12 | @Data 13 | @AllArgsConstructor 14 | @NoArgsConstructor 15 | public class ResponseMessage { 16 | private String content; 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/resources/note.txt: -------------------------------------------------------------------------------- 1 | WebSocket 2 | WebSocket 是一种网络通信协议。 3 | 4 | WebSocket 是 HTML5 开始提供的一种在单个 TCP 连接上进行全双工(full-duplex)通讯的协议。 5 | 没有了 Request 和 Response 的概念,两者地位完全平等,连接一旦建立, 6 | 就建立了真•持久性连接,双方可以随时向对方发送数据。 7 | 8 | WebSocket的出现历程 9 | 短轮询效率低,非常浪费资源(网络带宽和计算资源)。有一定延迟、服务器压力较大,并且大部分是无效请求。 10 | 11 | 长轮询虽然省去了大量无效请求,减少了服务器压力和一定的网络带宽的占用,但是还是需要保持大量的连接。 12 | 13 | 最后到了基于流的方式,在服务器往客户端推送,这个方向的流实时性比较好。 14 | 但是依旧是单向的,客户端请求服务器依然还需要一次 HTTP 请求。 15 | 16 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/dto/StudentDto.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa.dto; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class StudentDto { 11 | private Integer id; 12 | 13 | private String name; 14 | 15 | private Integer age; 16 | 17 | private Integer schoolId; 18 | 19 | private String schoolName; 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread.entity; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2020/3/20 10 | */ 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class User { 15 | private String id; 16 | 17 | private String username; 18 | 19 | private String password; 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/enums/DocumentEnums.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document.enums; 2 | 3 | /** 4 | * @author Panlf 5 | * @date 2020/2/13 6 | */ 7 | public enum DocumentEnums { 8 | TXT("txt"),WORD_DOC("word_doc"),WORD_DOCX("word_docx"); 9 | 10 | private String name; 11 | 12 | DocumentEnums(){} 13 | 14 | DocumentEnums(String name){ 15 | this.name= name; 16 | } 17 | 18 | public String getName(){ 19 | return name; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/repository/BlogRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl.repository; 2 | 3 | import com.plf.learn.staticftl.bean.Blog; 4 | import org.springframework.data.mongodb.repository.MongoRepository; 5 | import org.springframework.stereotype.Repository; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/11/18 10 | */ 11 | @Repository 12 | public interface BlogRepository extends MongoRepository { 13 | } 14 | -------------------------------------------------------------------------------- /springboot-learn-log/src/main/java/com/plf/learn/log/LogApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.log; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * 8 | * @author Panlf 9 | * @date 2020/3/18 10 | */ 11 | @SpringBootApplication 12 | public class LogApplication { 13 | public static void main(String[] args) { 14 | SpringApplication.run(LogApplication.class,args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-learn-neo4j/src/main/java/com/plf/learn/neo4j/Neo4jApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.neo4j; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | /** 6 | * @author panlf 7 | * @date 2021/12/25 8 | */ 9 | @SpringBootApplication 10 | public class Neo4jApplication { 11 | public static void main(String[] args) { 12 | SpringApplication.run(Neo4jApplication.class,args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /springboot-learn-solr/src/main/java/com/plf/learn/solr/SolrApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.solr; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2020/3/18 9 | */ 10 | @SpringBootApplication 11 | public class SolrApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SolrApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | /target/ 24 | */build/* 25 | 26 | gradlew 27 | gradlew.bat 28 | gradle/ 29 | out/ 30 | .idea/ 31 | .gradle/ 32 | .git/ 33 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/java/com/plf/learn/elasticsearch/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elasticsearch.repository; 2 | 3 | import com.plf.learn.elasticsearch.bean.Book; 4 | import org.springframework.data.elasticsearch.repository.ElasticsearchRepository; 5 | 6 | /** 7 | * ElasticsearchCrudRepository 就是SpringBoot自带的CRUD 8 | * @author Panlf 9 | * @date 2019/12/27 10 | */ 11 | public interface BookRepository extends ElasticsearchRepository { 12 | } 13 | -------------------------------------------------------------------------------- /springboot-learn-kafka/src/main/java/com/plf/learn/kafka/KafkaApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.kafka; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/12/26 9 | */ 10 | @SpringBootApplication 11 | public class KafkaApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(KafkaApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/SpringBootMybatisPlusApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class SpringBootMybatisPlusApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(SpringBootMybatisPlusApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/annotations/ApiIdempotent.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.annotations; 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 | * @author Panlf 10 | * @date 2019/12/26 11 | */ 12 | @Target({ElementType.METHOD}) 13 | @Retention(RetentionPolicy.RUNTIME) 14 | public @interface ApiIdempotent { 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/java/com/plf/learn/elastic/bean/FileCustom.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elastic.bean; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | @Data 8 | @AllArgsConstructor 9 | @NoArgsConstructor 10 | public class FileCustom { 11 | 12 | private String id; 13 | 14 | private String name; 15 | 16 | private String type; 17 | 18 | private String path; 19 | 20 | private Boolean backUp=false; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-learn-mongodb/src/main/java/com/plf/learn/mongodb/MongoDBApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mongodb; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2020/3/2 9 | */ 10 | @SpringBootApplication 11 | public class MongoDBApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(MongoDBApplication.class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/bean/Person.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.bean; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/5/16 10 | */ 11 | @Entity 12 | @Data 13 | public class Person { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Integer id; 18 | 19 | @Column 20 | private String username; 21 | 22 | @Column 23 | private String password; 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/SpringBootJpaApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/5/5 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootJpaApplication { 12 | public static void main(String[] args){ 13 | SpringApplication.run(SpringBootJpaApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/SpringBootJwtApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/5/14 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootJwtApplication { 12 | public static void main(String[] args){ 13 | SpringApplication.run(SpringBootJwtApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/SecurityApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2020/3/13 9 | */ 10 | @SpringBootApplication 11 | public class SecurityApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SecurityApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/RedisSentinelApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/12/26 9 | */ 10 | @SpringBootApplication 11 | public class RedisSentinelApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(RedisSentinelApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/ThreadLocalApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2020/3/20 9 | */ 10 | @SpringBootApplication 11 | public class ThreadLocalApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ThreadLocalApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/java/com/plf/learn/websocket/WebSocketApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.websocket; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2020/3/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-learn-aop-multidata/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8008 3 | servlet: 4 | context-path: /aop 5 | 6 | spring: 7 | datasource: 8 | url_user: jdbc:mysql://localhost:3306/house_user?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | url_comment: jdbc:mysql://localhost:3306/house_comment?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 10 | username: root 11 | password: root 12 | driver-class-name: com.mysql.cj.jdbc.Driver -------------------------------------------------------------------------------- /springboot-learn-mail/src/main/java/com/plf/learn/mail/SpringBootMailApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mail; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/4/20 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootMailApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringBootMailApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/src/main/java/com/plf/learn/aop/multidata/SpringBootMultidata.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.aop.multidata; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/8/7 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootMultidata { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringBootMultidata.class,args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/SpringBootLockApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/4/19 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootLockApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootLockApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/repository/UserRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.repository; 2 | 3 | import com.plf.learn.shiro.bean.User; 4 | import org.springframework.data.jpa.repository.JpaRepository; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/6/6 9 | */ 10 | public interface UserRepository extends JpaRepository { 11 | 12 | /** 13 | * 根据用户名查找用户 14 | * @param username 15 | * @return 16 | */ 17 | User findDistinctByUsername(String username); 18 | } 19 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/java/com/plf/learn/elastic/SpringBootElasticApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elastic; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/12/2 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootElasticApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootElasticApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/repository/PersonRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.repository; 2 | 3 | import com.plf.learn.jwt.bean.Person; 4 | import org.springframework.data.repository.CrudRepository; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/5/16 9 | */ 10 | public interface PersonRepository extends CrudRepository { 11 | 12 | /** 13 | * 根据用户名查找用户 14 | * @param username 15 | * @return 16 | */ 17 | public Person findPersonByUsername(String username); 18 | } 19 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/java/com/plf/learn/caffeine/SpringBootCaffeineApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.caffeine; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author panlf 8 | * @date 2021/8/16 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootCaffeineApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootCaffeineApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/java/com/plf/learn/elasticsearch/ElasticSearchApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elasticsearch; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/12/27 9 | */ 10 | @SpringBootApplication 11 | public class ElasticSearchApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(ElasticSearchApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/common/JwtResult.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.common; 2 | 3 | import io.jsonwebtoken.Claims; 4 | import lombok.Data; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/5/14 9 | */ 10 | @Data 11 | public class JwtResult { 12 | 13 | /** 14 | * 错误编码 在JwtUtils中定义常量 15 | * 16 | * 200为正确 17 | */ 18 | private int errCode; 19 | 20 | /** 21 | * 是否成功 22 | */ 23 | private boolean success; 24 | 25 | /** 26 | * 验证过程中payload中的数据 27 | */ 28 | private Claims claims; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/src/main/java/com/plf/learn/limiter/SpringBootApiLimiterApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.limiter; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author panlf 8 | * @date 2021/9/1 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootApiLimiterApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootApiLimiterApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/SpringBootEventApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/4/19 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootEventApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootEventApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/bean/School.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa.bean; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | 12 | @Entity 13 | @Data 14 | public class School { 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Integer id; 18 | 19 | @Column 20 | private String schoolName; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/SpringBootStaticFtlApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | /** 7 | * @author Panlf 8 | * @date 2019/11/15 9 | */ 10 | @SpringBootApplication 11 | public class SpringBootStaticFtlApplication { 12 | public static void main(String[] args) { 13 | SpringApplication.run(SpringBootStaticFtlApplication.class,args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/src/main/java/com/plf/learn/aop/multidata/annotation/TargetDataSource.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.aop.multidata.annotation; 2 | 3 | import java.lang.annotation.Retention; 4 | import java.lang.annotation.Target; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.ElementType; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/8/7 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target(ElementType.METHOD) 14 | public @interface TargetDataSource { 15 | String value() default ""; 16 | } 17 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8012 3 | servlet: 4 | context-path: /redis 5 | 6 | spring: 7 | redis: 8 | sentinel: 9 | #哨兵监听redis server名称 10 | master: mymaster 11 | #哨兵的配置列表 12 | nodes: 127.0.0.1:26000,127.0.0.1:26001,127.0.0.1:26002 13 | lettuce: 14 | pool: 15 | #最大连接数 16 | max-active: 8 17 | #最大阻塞等待时间(负数表示没限制) 18 | max-wait: -1 19 | #最大空闲 20 | max-idle: 8 21 | #最小空闲 22 | min-idle: 0 23 | timeout: 10000ms 24 | 25 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/utils/interfaces/OperateDocument.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document.utils.interfaces; 2 | 3 | /** 4 | * @author Panlf 5 | * @date 2020/2/13 6 | */ 7 | public interface OperateDocument { 8 | 9 | /** 10 | * 读文档 11 | * @param path 12 | * @return 13 | */ 14 | public String readDocument(String path); 15 | 16 | /** 17 | * 写文档 18 | * @param path 19 | * @param content 20 | * @return 21 | */ 22 | public boolean writeDocument(String path,String content); 23 | } 24 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/service/AdminActionService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.service; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.shiro.authz.annotation.RequiresRoles; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * admin 用户权限测试 9 | * @author Panlf 10 | * @date 2019/6/5 11 | */ 12 | @Service 13 | @Slf4j 14 | public class AdminActionService { 15 | 16 | @RequiresRoles("admin") 17 | public void logVisitService(){ 18 | log.info("AdminActionService Admin Role Visit--"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-kafka/src/main/java/com/plf/learn/kafka/message/Message.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.kafka.message; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | import java.util.Date; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/12/26 11 | */ 12 | @Data 13 | public class Message implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | private Integer id; 18 | 19 | private String topic; 20 | 21 | private Integer partition; 22 | 23 | private String content; 24 | 25 | private Date createTime; 26 | } 27 | -------------------------------------------------------------------------------- /springboot-learn-jetcache/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8005 3 | servlet: 4 | context-path: /jetcache 5 | 6 | 7 | jetcache: 8 | statIntervalMinutes: 15 9 | areaInCacheName: false 10 | local: 11 | default: 12 | type: linkedhashmap 13 | keyConvertor: fastjson 14 | remote: 15 | default: 16 | type: redis 17 | keyConvertor: fastjson 18 | valueEncoder: java 19 | valueDecoder: java 20 | poolConfig: 21 | minIdle: 5 22 | maxIdle: 20 23 | maxTotal: 50 24 | host: 127.0.0.1 25 | port: 6379 26 | -------------------------------------------------------------------------------- /springboot-learn-mongodb/src/main/java/com/plf/learn/mongodb/repository/CommentRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mongodb.repository; 2 | 3 | import com.plf.learn.mongodb.bean.Comment; 4 | import org.springframework.data.domain.Page; 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.mongodb.repository.MongoRepository; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2020/3/2 11 | */ 12 | public interface CommentRepository extends MongoRepository{ 13 | 14 | public Page findByParentid(String parentid, Pageable pageable); 15 | } 16 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8025 3 | servlet: 4 | context-path: /security 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/practice?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | mybatis: 13 | type-aliases-package: com.plf.learn.security 14 | 15 | logging: 16 | level: 17 | com: 18 | plf: 19 | learn: 20 | security: 21 | mapper: debug 22 | -------------------------------------------------------------------------------- /springboot-learn-solr/src/main/java/com/plf/learn/solr/entity/Worker.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.solr.entity; 2 | 3 | import lombok.Data; 4 | import org.apache.solr.client.solrj.beans.Field; 5 | import org.springframework.data.solr.core.mapping.SolrDocument; 6 | 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2020/3/18 11 | */ 12 | @Data 13 | @SolrDocument(solrCoreName = "worker") 14 | public class Worker { 15 | @Field("workid") 16 | private String workid; 17 | 18 | @Field("position") 19 | private String position; 20 | 21 | @Field("salary") 22 | private double salary; 23 | } 24 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/src/main/java/com/plf/learn/aop/multidata/config/DynamicDataSource.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.aop.multidata.config; 2 | 3 | import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource; 4 | 5 | /** 6 | * 动态数据源的实现类 7 | * @author Panlf 8 | * @date 2019/8/7 9 | */ 10 | public class DynamicDataSource extends AbstractRoutingDataSource { 11 | 12 | /** 13 | * 数据源路由,此方用于产生要选取的数据源逻辑名称 14 | */ 15 | @Override 16 | protected Object determineCurrentLookupKey() { 17 | return DynamicDataSourceHolder.getDataSource(); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.ui.Model; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/11/15 10 | */ 11 | @Controller 12 | public class TestController { 13 | 14 | 15 | @RequestMapping("/index") 16 | public String toIndex(Model model) { 17 | model.addAttribute("name", "lisi"); 18 | return "index"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-jetcache/src/main/java/com/plf/learn/jetcache/bean/Person.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jetcache.bean; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import java.io.Serializable; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/5/24 13 | */ 14 | @Data 15 | @AllArgsConstructor 16 | @NoArgsConstructor 17 | public class Person implements Serializable{ 18 | 19 | private Integer id; 20 | 21 | private String name; 22 | 23 | private Integer age; 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/controller/IndexController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | 6 | @Controller 7 | public class IndexController { 8 | 9 | @RequestMapping("/index") 10 | public String index() { 11 | return "index"; 12 | } 13 | 14 | @RequestMapping("/403") 15 | public String forbidden() { 16 | return "403"; 17 | } 18 | 19 | @RequestMapping("/login") 20 | public String login() { 21 | return "login"; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/SpringBootShiroApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cache.annotation.EnableCaching; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/6/5 10 | */ 11 | @SpringBootApplication 12 | @EnableCaching 13 | public class SpringBootShiroApplication { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(SpringBootShiroApplication.class,args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot-learn-dataway/src/main/java/com/plf/learn/dataway/SpringBootDatawayApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.dataway; 2 | 3 | import net.hasor.spring.boot.EnableHasor; 4 | import net.hasor.spring.boot.EnableHasorWeb; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | @EnableHasor() 9 | @EnableHasorWeb() 10 | @SpringBootApplication 11 | public class SpringBootDatawayApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(SpringBootDatawayApplication.class,args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/SpringBootDocumentApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableAsync; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2020/2/13 10 | */ 11 | @SpringBootApplication 12 | @EnableAsync 13 | public class SpringBootDocumentApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringBootDocumentApplication.class,args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/service/TokenService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.service; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/12/26 8 | */ 9 | public interface TokenService { 10 | /** 11 | * 创建token 12 | * @param username 用户名 13 | * @return 14 | */ 15 | public String createToken(String username); 16 | 17 | /** 18 | * 检验Token 19 | * @param request 20 | * @return 21 | * @throws Exception 22 | */ 23 | public boolean checkToken(HttpServletRequest request) throws Exception; 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-jetcache/src/main/java/com/plf/learn/jetcache/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jetcache.service; 2 | 3 | import com.plf.learn.jetcache.bean.Person; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/5/24 8 | */ 9 | public interface PersonService { 10 | /** 11 | * 根据Id获取用户 12 | * @param id 13 | * @return 14 | */ 15 | Person getPersonById(Integer id); 16 | 17 | /** 18 | * 更新用户 19 | * @param person 20 | */ 21 | void updatePerson(Person person); 22 | 23 | /** 24 | * 删除用户 25 | * @param id 26 | */ 27 | void deletePerson(Integer id); 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/bean/Student.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa.bean; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | 11 | @Entity 12 | @Data 13 | public class Student { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Integer id; 18 | 19 | @Column 20 | private String name; 21 | 22 | @Column 23 | private Integer age; 24 | 25 | @Column 26 | private Integer schoolId; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-neo4j/src/main/java/com/plf/learn/neo4j/entity/MinFamily.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.neo4j.entity; 2 | 3 | import lombok.Data; 4 | import lombok.NoArgsConstructor; 5 | import org.springframework.data.neo4j.core.schema.*; 6 | 7 | import java.util.Set; 8 | 9 | /** 10 | * @author panlf 11 | * @date 2021/12/25 12 | */ 13 | @Data 14 | @Node(labels = "minFamily") 15 | @NoArgsConstructor 16 | public class MinFamily { 17 | 18 | @Id 19 | @GeneratedValue 20 | private Long id; 21 | @Property 22 | private String name; 23 | 24 | public MinFamily(String name){ 25 | this.name = name; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.entity; 2 | 3 | import java.util.Date; 4 | 5 | import com.baomidou.mybatisplus.annotation.TableField; 6 | import com.baomidou.mybatisplus.annotation.TableId; 7 | import com.baomidou.mybatisplus.annotation.TableName; 8 | import lombok.Data; 9 | 10 | @TableName 11 | @Data 12 | public class User { 13 | @TableId 14 | private Integer id; 15 | @TableField 16 | private String username; 17 | @TableField 18 | private Date birthday; 19 | @TableField 20 | private Integer sex; 21 | @TableField 22 | private String address; 23 | 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/java/com/plf/learn/sharding/test/SnowTest.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.sharding.test; 2 | 3 | import org.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/6/12 8 | */ 9 | public class SnowTest { 10 | public static void main(String[] args) { 11 | SnowflakeShardingKeyGenerator keyGenerator = new SnowflakeShardingKeyGenerator(); 12 | System.out.println(keyGenerator.generateKey()); 13 | System.out.println(keyGenerator.generateKey()); 14 | System.out.println(keyGenerator.generateKey()); 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/utils/CloseUtils.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document.utils; 2 | 3 | import java.io.Closeable; 4 | import java.io.IOException; 5 | /** 6 | * @author Panlf 7 | * @date 2020/2/13 8 | */ 9 | public class CloseUtils { 10 | public static void close(Closeable...closeables) { 11 | if(closeables==null) { 12 | return; 13 | } 14 | for(Closeable closeable:closeables) { 15 | try { 16 | closeable.close(); 17 | } catch (IOException e) { 18 | e.printStackTrace(); 19 | } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.service; 2 | 3 | import com.plf.learn.shiro.bean.User; 4 | import com.plf.learn.shiro.repository.UserRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/6/6 11 | */ 12 | @Service 13 | public class UserService { 14 | 15 | @Autowired 16 | private UserRepository userRepository; 17 | 18 | public User findByUsername(String username){ 19 | return userRepository.findDistinctByUsername(username); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/java/com/plf/learn/monitor/SpringBootMonitorApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.monitor; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.boot.SpringApplication; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/7/11 11 | */ 12 | @SpringBootApplication 13 | @MapperScan(basePackages={"com.plf.learn.monitor.mapper"}) 14 | public class SpringBootMonitorApplication { 15 | public static void main(String[] args) { 16 | SpringApplication.run(SpringBootMonitorApplication.class,args); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8002 3 | servlet: 4 | context-path: /jpa 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | jpa: 13 | database: MYSQL 14 | show-sql: true 15 | hibernate: 16 | ddl-auto: update 17 | naming: 18 | physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy 19 | database-platform: org.hibernate.dialect.MySQL5InnoDBDialect -------------------------------------------------------------------------------- /springboot-learn-log/src/main/java/com/plf/learn/log/service/LogMessageService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.log.service; 2 | 3 | import com.plf.learn.log.entity.LogMessage; 4 | import com.plf.learn.log.repository.LogMessageRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2020/3/18 11 | */ 12 | @Service 13 | public class LogMessageService { 14 | @Autowired 15 | private LogMessageRepository logMessageRepository; 16 | 17 | public void save(LogMessage logMessage){ 18 | logMessageRepository.save(logMessage); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/entity/Log.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.entity; 2 | 3 | import java.util.Date; 4 | 5 | import com.baomidou.mybatisplus.annotation.*; 6 | import lombok.Data; 7 | 8 | @TableName 9 | @Data 10 | public class Log { 11 | @TableId 12 | private Integer id; 13 | 14 | @TableId 15 | private Integer userId; 16 | 17 | @TableField 18 | private String content; 19 | 20 | @TableField(fill = FieldFill.INSERT) 21 | private Date createtime; 22 | 23 | @TableField(fill=FieldFill.UPDATE) 24 | private Date updatetime; 25 | 26 | @TableField 27 | @TableLogic 28 | private Integer delstatus; 29 | } 30 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/src/main/java/com/plf/learn/aop/multidata/config/DynamicDataSourceHolder.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.aop.multidata.config; 2 | 3 | /** 4 | * 动态数据源的增加获取删除 5 | * @author Panlf 6 | * @date 2019/8/7 7 | */ 8 | public class DynamicDataSourceHolder { 9 | private static final ThreadLocal THREAD_LOCAL = new ThreadLocal<>(); 10 | 11 | public static void putDataSource(String name) { 12 | THREAD_LOCAL.set(name); 13 | } 14 | 15 | public static String getDataSource() { 16 | return THREAD_LOCAL.get(); 17 | } 18 | 19 | public static void removeDataSource() { 20 | THREAD_LOCAL.remove(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/service/LogService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.service; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | import com.plf.learn.mybatisplus.dto.LogDto; 6 | import com.plf.learn.mybatisplus.entity.Log; 7 | 8 | public interface LogService extends IService{ 9 | 10 | public void insertLog(Log log); 11 | 12 | public void deleteLog(Integer id); 13 | 14 | public Page getPageLog(Page page, String strattime); 15 | 16 | public Page getLogAndName(Page page, String username); 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/config/RedissonConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock.config; 2 | 3 | import org.redisson.Redisson; 4 | import org.redisson.config.Config; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/5/20 11 | */ 12 | @Configuration 13 | public class RedissonConfig { 14 | 15 | @Bean 16 | public Redisson redisson(){ 17 | Config config = new Config(); 18 | config.useSingleServer().setAddress("redis://127.0.0.1:6379").setDatabase(0); 19 | return (Redisson)Redisson.create(config); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-log/src/main/java/com/plf/learn/log/entity/LogMessage.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.log.entity; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.Date; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2020/3/18 10 | */ 11 | @Data 12 | public class LogMessage { 13 | private String id; 14 | /** 15 | * 操作描述 16 | */ 17 | private String description; 18 | private String ip; 19 | /** 20 | * 操作人 21 | */ 22 | private String operateName; 23 | private String uri; 24 | private String url; 25 | /** 26 | * 操作花费的时间 27 | */ 28 | private Long duration; 29 | 30 | private Date startTime; 31 | 32 | private Date endTime; 33 | } 34 | -------------------------------------------------------------------------------- /springboot-learn-share-session/src/main/java/com/plf/learn/share/session/SpringBootShareSessionApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.share.session; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/4/19 10 | */ 11 | @SpringBootApplication 12 | @EnableRedisHttpSession 13 | public class SpringBootShareSessionApplication { 14 | public static void main(String[] args) { 15 | SpringApplication.run(SpringBootShareSessionApplication.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8006 3 | servlet: 4 | context-path: /shiro 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/bootlearn?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | jpa: 13 | database: MYSQL 14 | show-sql: true 15 | hibernate: 16 | ddl-auto: update 17 | naming: 18 | physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy 19 | database-platform: org.hibernate.dialect.MySQL5InnoDBDialect 20 | 21 | 22 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/emailevents/EmailEventPublish.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event.emailevents; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/4/19 10 | */ 11 | @Component 12 | public class EmailEventPublish { 13 | @Autowired 14 | private ApplicationContext applicationContext; 15 | 16 | public void publishEvent(String emailAddress) { 17 | EmailEvent event = new EmailEvent(emailAddress); 18 | applicationContext.publishEvent(event); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/base/Message.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread.base; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2020/3/20 10 | */ 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class Message { 15 | private Integer code; 16 | private String message; 17 | private Object data; 18 | 19 | public static Message success(String message,Object data){ 20 | return new Message(200,message,data); 21 | } 22 | 23 | public static Message fail(String message,Object data){ 24 | return new Message(500,message,data); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/emailevents/EmailEvent.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event.emailevents; 2 | 3 | import org.springframework.context.ApplicationEvent; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/4/19 8 | */ 9 | public class EmailEvent extends ApplicationEvent { 10 | 11 | private String emailAddress; 12 | 13 | public EmailEvent(String emailAddress) { 14 | super(emailAddress); 15 | this.emailAddress = emailAddress; 16 | } 17 | 18 | public String getEmailAddress() { 19 | return emailAddress; 20 | } 21 | 22 | public void setEmailAddress(String emailAddress) { 23 | this.emailAddress = emailAddress; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8004 3 | servlet: 4 | context-path: /lock 5 | 6 | spring: 7 | redis: 8 | #数据库索引 9 | database: 0 10 | host: 127.0.0.1 11 | port: 6379 12 | lettuce: 13 | pool: 14 | #最大连接数 15 | max-active: 8 16 | #最大阻塞等待时间(负数表示没限制) 17 | max-wait: -1 18 | #最大空闲 19 | max-idle: 8 20 | #最小空闲 21 | min-idle: 0 22 | #连接超时时间 23 | timeout: 10000 24 | 25 | 26 | curator: 27 | retryCount: 5 #重试次数 28 | elapsedTimeMs: 5000 #重试间隔时间 29 | connectString: 127.0.0.1:2181 # zookeeper 地址 30 | sessionTimeoutMs: 60000 # session超时时间 31 | connectionTimeoutMs: 5000 # 连接超时时间 32 | 33 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/java/com/plf/learn/sharding/mapper/OrderMapper.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.sharding.mapper; 2 | 3 | import com.plf.learn.sharding.bean.Order; 4 | import org.apache.ibatis.annotations.Insert; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Param; 7 | import org.apache.ibatis.annotations.Select; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/6/12 12 | */ 13 | @Mapper 14 | public interface OrderMapper { 15 | 16 | @Insert("insert into t_order values(#{id},#{orderId},#{userId},#{username})") 17 | public void insertOrder(Order order); 18 | 19 | @Select("select * from t_order where id=#{id}") 20 | public Order findById(@Param("id") long id); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock.utils; 2 | 3 | /** 4 | * @author Panlf 5 | * @date 2019/5/20 6 | */ 7 | public class StringUtils { 8 | 9 | /** 10 | * 判断字符串是否为空 11 | * @param str 12 | * @return Null或者空串返回false,否则返回true 13 | */ 14 | public static boolean isNotEmpty(String str){ 15 | if(str==null || str.trim().length()<=0){ 16 | return false; 17 | } 18 | return true; 19 | } 20 | 21 | /** 22 | * 判断字符串是否为空 23 | * @param str 24 | * @return Null或者空串返回true,否则返回false 25 | */ 26 | public static boolean isEmpty(String str){ 27 | return !isNotEmpty(str); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/src/main/java/com/plf/learn/limiter/controller/ApiController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.limiter.controller; 2 | 3 | import com.plf.learn.limiter.annotations.ApiRateLimiter; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | /** 10 | * @author panlf 11 | * @date 2021/9/1 12 | */ 13 | @RestController 14 | public class ApiController { 15 | 16 | private AtomicInteger num = new AtomicInteger(0); 17 | 18 | @ApiRateLimiter(token = 1,timeout = 1) 19 | @GetMapping("hello") 20 | public String hello(){ 21 | return "处理成功 --- "+num.incrementAndGet(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.service; 2 | 3 | import com.plf.learn.jwt.bean.Person; 4 | import com.plf.learn.jwt.repository.PersonRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/5/16 11 | */ 12 | @Service 13 | public class PersonService { 14 | 15 | @Autowired 16 | private PersonRepository personRepository; 17 | 18 | /** 19 | * 根据用户名查找用户 20 | * @param username 21 | * @return 22 | */ 23 | public Person findPersonByUsername(String username){ 24 | return personRepository.findPersonByUsername(username); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8003 3 | servlet: 4 | context-path: /mybatisplus 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | logging: 13 | level: 14 | com: 15 | plf: 16 | learn: 17 | mybatisplus: 18 | mapper: debug 19 | 20 | mybatis-plus: 21 | type-aliases-package: com.plf.learn.mybatisplus.entity 22 | global-config: 23 | db-config: 24 | id-type: AUTO 25 | table-underline: true 26 | logic-delete-value: 1 27 | logic-not-delete-value: 0 -------------------------------------------------------------------------------- /springboot-learn-jetcache/src/main/java/com/plf/learn/jetcache/SpringBootJetcacheApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jetcache; 2 | 3 | import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation; 4 | import com.alicp.jetcache.anno.config.EnableMethodCache; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/5/24 11 | */ 12 | @SpringBootApplication 13 | @EnableMethodCache(basePackages = "com.plf.learn.jetcache") 14 | @EnableCreateCacheAnnotation 15 | public class SpringBootJetcacheApplication { 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(SpringBootJetcacheApplication.class,args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/component/ActiveMQProducer.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl.component; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.jms.core.JmsMessagingTemplate; 5 | import org.springframework.stereotype.Component; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/11/18 10 | */ 11 | @Component 12 | public class ActiveMQProducer { 13 | 14 | @Autowired 15 | private JmsMessagingTemplate jmsMessagingTemplate; 16 | 17 | /** 18 | * 19 | * @param destination 队列 20 | * @param message 信息 21 | */ 22 | public void sendMessage(String destination,String message){ 23 | jmsMessagingTemplate.convertAndSend(destination,message); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/utils/KeyDecode.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.utils; 2 | 3 | import org.apache.shiro.codec.Base64; 4 | 5 | import javax.crypto.KeyGenerator; 6 | import javax.crypto.SecretKey; 7 | import java.security.NoSuchAlgorithmException; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/6/5 12 | */ 13 | public class KeyDecode { 14 | public static void main(String[] args) { 15 | KeyGenerator keygen = null; 16 | try { 17 | keygen = KeyGenerator.getInstance("AES"); 18 | } catch (NoSuchAlgorithmException e) { 19 | e.printStackTrace(); 20 | } 21 | SecretKey deskey = keygen.generateKey(); 22 | System.out.println(Base64.encodeToString(deskey.getEncoded())); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/src/main/java/com/plf/learn/limiter/annotations/ApiRateLimiter.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.limiter.annotations; 2 | 3 | import java.lang.annotation.*; 4 | import java.util.concurrent.TimeUnit; 5 | 6 | /** 7 | * @author panlf 8 | * @date 2021/9/1 9 | */ 10 | @Documented 11 | @Target(ElementType.METHOD) 12 | @Retention(RetentionPolicy.RUNTIME) 13 | public @interface ApiRateLimiter { 14 | String value() default ""; 15 | 16 | /** 17 | * 每秒令牌数 18 | * @return 19 | */ 20 | long token() default Long.MAX_VALUE; 21 | 22 | /** 23 | * 获取令牌的等待时间 24 | * @return 25 | */ 26 | int timeout() default 1; 27 | 28 | /** 29 | * 超时时间单位 30 | * @return 31 | */ 32 | TimeUnit timeunit() default TimeUnit.SECONDS; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /springboot-learn-kafka/src/main/java/com/plf/learn/kafka/consumer/KafkaConsumer.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.kafka.consumer; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.apache.kafka.clients.consumer.ConsumerRecord; 5 | import org.springframework.kafka.annotation.KafkaListener; 6 | import org.springframework.stereotype.Component; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/12/26 11 | */ 12 | @Component 13 | @Slf4j 14 | public class KafkaConsumer { 15 | 16 | @KafkaListener(topics = "kafka-test") 17 | public void receive(ConsumerRecord consumer){ 18 | log.info("topic name:{},key:{},partition:{},offset:{},message:{}", 19 | consumer.topic(),consumer.key(), 20 | consumer.partition(),consumer.offset(),consumer.value()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/config/GlobalDefaultExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.config; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.apache.shiro.authz.UnauthorizedException; 6 | import org.springframework.web.bind.annotation.ControllerAdvice; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | /** 9 | * @author Panlf 10 | * @date 2019/6/5 11 | */ 12 | @ControllerAdvice 13 | public class GlobalDefaultExceptionHandler { 14 | 15 | @ExceptionHandler(Exception.class) 16 | public String defaultExceptionHandler(HttpServletRequest req,Exception e){ 17 | if(e instanceof UnauthorizedException){ 18 | return "noperssion"; 19 | } 20 | return "defaultException"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/bean/User.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.bean; 2 | 3 | import lombok.Data; 4 | 5 | import javax.persistence.*; 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2019/6/5 11 | */ 12 | @Data 13 | @Entity 14 | public class User implements Serializable { 15 | 16 | private static final long serialVersionUID = -9043123869071313256L; 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.IDENTITY) 20 | private Integer id; 21 | 22 | @Column 23 | private String username; 24 | 25 | @Column 26 | private String password; 27 | 28 | @Column 29 | private String salt; 30 | 31 | @Column 32 | private String permissions; 33 | 34 | @Column 35 | private String roles; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /springboot-learn-log/src/main/java/com/plf/learn/log/controller/LogController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.log.controller; 2 | 3 | import com.plf.learn.log.annotation.Loggable; 4 | import org.springframework.web.bind.annotation.PathVariable; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Panlf 10 | * @date 2020/3/18 11 | */ 12 | @RestController 13 | public class LogController { 14 | 15 | @Loggable(value = "日志查询操作") 16 | @RequestMapping("/get") 17 | public String getLog(){ 18 | return "success"; 19 | } 20 | 21 | @Loggable(value = "带参数日志查询操作") 22 | @RequestMapping("/get/{name}") 23 | public String getLogWithValue(@PathVariable String name){ 24 | return name; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-learn-log/src/main/java/com/plf/learn/log/annotation/Loggable.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.log.annotation; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * 注解作用于方法级别且运行时起作用 10 | * @author Panlf 11 | * @date 2020/3/18 12 | */ 13 | @Target({ElementType.METHOD}) 14 | @Retention(RetentionPolicy.RUNTIME) 15 | public @interface Loggable { 16 | 17 | /** 18 | * 日志信息描述 19 | * @return 20 | */ 21 | String value() default ""; 22 | 23 | 24 | /** 25 | * 是否保存到数据库 26 | * @return 27 | */ 28 | boolean save() default true; 29 | 30 | /** 31 | * 是否输出到控制台 32 | * @return 33 | */ 34 | boolean console() default true; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/configuration/GlobalExceptionHandler.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.configuration; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.web.bind.annotation.ControllerAdvice; 5 | import org.springframework.web.bind.annotation.ExceptionHandler; 6 | import org.springframework.web.bind.annotation.ResponseBody; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * 全局异常类 11 | * @author Panlf 12 | * @date 2019/12/26 13 | */ 14 | @ControllerAdvice 15 | @Slf4j 16 | public class GlobalExceptionHandler { 17 | 18 | @ResponseBody 19 | @ExceptionHandler(value =Exception.class) 20 | public String exceptionHandler(Exception e){ 21 | log.error("捕获异常为{}",e.getMessage()); 22 | return e.getMessage(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.stereotype.Service; 6 | 7 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 9 | import com.plf.learn.mybatisplus.entity.User; 10 | import com.plf.learn.mybatisplus.mapper.UserMapper; 11 | import com.plf.learn.mybatisplus.service.UserService; 12 | 13 | @Service 14 | public class UserServiceImpl extends ServiceImpl implements UserService { 15 | 16 | @Override 17 | public List listUser(String username) { 18 | return baseMapper.selectList(new QueryWrapper().like("username", username)); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/common/ResponseData.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.common; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.Data; 5 | import lombok.NoArgsConstructor; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/5/14 10 | */ 11 | @Data 12 | @AllArgsConstructor 13 | @NoArgsConstructor 14 | public class ResponseData { 15 | /** 16 | * 返回码 17 | */ 18 | private Integer code; 19 | 20 | /** 21 | * 业务数据 22 | */ 23 | private Object data; 24 | 25 | /** 26 | * 返回描述 27 | */ 28 | private String msg; 29 | 30 | /** 31 | * 身份标识 32 | */ 33 | private String token; 34 | 35 | public static ResponseData result(Integer code,Object data,String msg,String token){ 36 | return new ResponseData(code,data,msg,token); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/java/com/plf/learn/sharding/service/OrderService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.sharding.service; 2 | 3 | import com.plf.learn.sharding.bean.Order; 4 | import com.plf.learn.sharding.mapper.OrderMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | import org.springframework.transaction.annotation.Transactional; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/6/12 12 | */ 13 | @Service 14 | public class OrderService { 15 | 16 | @Autowired 17 | private OrderMapper orderMapper; 18 | 19 | @Transactional(rollbackFor = Exception.class) 20 | public void save(Order order){ 21 | orderMapper.insertOrder(order); 22 | } 23 | 24 | public Order findById(Long id){ 25 | return orderMapper.findById(id); 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/interceptor/UserContextHolder.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread.interceptor; 2 | 3 | import com.plf.learn.thread.entity.User; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2020/3/20 8 | */ 9 | public class UserContextHolder { 10 | private static final ThreadLocal USER_CONTEXT_HOLDER = new ThreadLocal<>(); 11 | 12 | /** 13 | * 填入User 14 | * @param user 15 | */ 16 | public static void setUser(User user){ 17 | USER_CONTEXT_HOLDER.set(user); 18 | } 19 | 20 | /** 21 | * 擦除User 22 | */ 23 | public static void remove(){ 24 | USER_CONTEXT_HOLDER.remove(); 25 | } 26 | 27 | /** 28 | * 获取User 29 | * @return 30 | */ 31 | public static User getUser(){ 32 | return USER_CONTEXT_HOLDER.get(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/controller/GlobalExceptionController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event.controller; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import org.springframework.web.bind.annotation.ControllerAdvice; 7 | import org.springframework.web.bind.annotation.ExceptionHandler; 8 | import org.springframework.web.bind.annotation.ResponseBody; 9 | 10 | /** 11 | * 全局捕获异常控制器 12 | * @author Panlf 13 | * @date 2019/4/19 14 | */ 15 | public class GlobalExceptionController { 16 | 17 | @ExceptionHandler(RuntimeException.class) 18 | @ResponseBody 19 | public Map resultError(){ 20 | Map result = new HashMap<>(); 21 | result.put("errCode", "500"); 22 | result.put("errMsg", "系统错误"); 23 | return result; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8015 3 | servlet: 4 | context-path: /staticftl 5 | 6 | # freemarker静态资源配置 7 | # 文件路径 8 | spring: 9 | freemarker: 10 | tempalte-loader-path: classpath:/templates 11 | # 关闭缓存,及时刷新 12 | cache: false 13 | charset: UTF-8 14 | content-type: text/html 15 | suffix: .html 16 | mvc: 17 | static-path-pattern: /static/** 18 | data: 19 | mongodb: 20 | host: 127.0.0.1 21 | port: 27017 22 | database: staticftl 23 | activemq: 24 | broker-url: tcp://localhost:61616 25 | #true 表示使用内置的MQ,false则连接服务器 26 | in-memory: false 27 | #true表示使用连接池;false时,每发送一条数据创建一个连接 28 | pool: 29 | enabled: true 30 | #连接池最大连接数 31 | max-connections: 10 32 | idle-timeout: 30000 33 | user: admin 34 | password: admin 35 | 36 | 37 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/java/com/plf/learn/elastic/service/FileCustomService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elastic.service; 2 | 3 | import com.plf.learn.elastic.bean.FileCustom; 4 | import com.plf.learn.elastic.mapper.FileCustomMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/12/2 13 | */ 14 | @Service 15 | public class FileCustomService { 16 | 17 | @Autowired 18 | private FileCustomMapper fileCustomMapper; 19 | 20 | public List findFileCustomList(String type,int limitnum){ 21 | return fileCustomMapper.findFileCustomByTypeLimit(type,limitnum); 22 | } 23 | 24 | public void updateFileCustom(String id){ 25 | fileCustomMapper.updateBackUp(id); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /springboot-learn-dataway/src/main/java/com/plf/learn/dataway/hasor/module/HasorModule.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.dataway.hasor.module; 2 | 3 | import net.hasor.core.ApiBinder; 4 | import net.hasor.core.DimModule; 5 | import net.hasor.db.JdbcModule; 6 | import net.hasor.db.Level; 7 | import net.hasor.spring.SpringModule; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Component; 10 | 11 | import javax.sql.DataSource; 12 | 13 | 14 | @DimModule 15 | @Component 16 | public class HasorModule implements SpringModule { 17 | @Autowired 18 | private DataSource dataSource = null; 19 | 20 | @Override 21 | public void loadModule(ApiBinder apiBinder) throws Throwable { 22 | // DataSource form Spring boot into Hasor 23 | apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/mapper/LogMapper.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.mapper; 2 | 3 | import java.util.List; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 10 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 11 | import com.plf.learn.mybatisplus.dto.LogDto; 12 | import com.plf.learn.mybatisplus.entity.Log; 13 | 14 | @Repository 15 | public interface LogMapper extends BaseMapper{ 16 | 17 | @Select("select l.content,u.username,l.createtime from log l" 18 | + " left join user u on l.user_id=u.id" 19 | + " where u.username=#{username}") 20 | public List getLogAndName(Page page, @Param("username") String username); 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/config/MybatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.config; 2 | 3 | import org.mybatis.spring.annotation.MapperScan; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | import com.baomidou.mybatisplus.core.injector.ISqlInjector; 8 | import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector; 9 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 10 | 11 | @Configuration 12 | @MapperScan("com.plf.learn.mybatisplus.mapper*") 13 | public class MybatisPlusConfig { 14 | @Bean 15 | public PaginationInterceptor paginationInterceptor() { 16 | return new PaginationInterceptor(); 17 | } 18 | 19 | @Bean 20 | public ISqlInjector sqlInjector(){ 21 | return new LogicSqlInjector(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/java/com/plf/learn/monitor/service/PersonService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.monitor.service; 2 | 3 | import com.plf.learn.monitor.bean.Person; 4 | import com.plf.learn.monitor.mapper.PersonMapper; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.github.pagehelper.PageHelper; 9 | import com.github.pagehelper.PageInfo; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author Panlf 15 | * @date 2019/7/11 16 | */ 17 | @Service 18 | public class PersonService { 19 | @Autowired 20 | private PersonMapper personMapper; 21 | 22 | public PageInfo findPerson(Integer pageNum, Integer pageSize){ 23 | PageHelper.startPage(pageNum, pageSize); 24 | List list = personMapper.findPerson(); 25 | return PageInfo.of(list); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/java/com/plf/learn/elastic/mapper/FileCustomMapper.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elastic.mapper; 2 | 3 | import com.plf.learn.elastic.bean.FileCustom; 4 | import org.apache.ibatis.annotations.Mapper; 5 | import org.apache.ibatis.annotations.Param; 6 | import org.apache.ibatis.annotations.Select; 7 | import org.apache.ibatis.annotations.Update; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/12/2 14 | */ 15 | @Mapper 16 | public interface FileCustomMapper { 17 | 18 | @Select("select id,name,type,path,backup from filecustom where type=#{type} and backup=0 limit #{limitnum}") 19 | public List findFileCustomByTypeLimit(@Param("type") String type,@Param("limitnum") int limitnum); 20 | 21 | @Update("update filecustom set backup=1 where id=#{id}") 22 | public void updateBackUp(@Param("id") String id); 23 | 24 | } -------------------------------------------------------------------------------- /springboot-learn-neo4j/src/main/java/com/plf/learn/neo4j/controllrt/Neo4jController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.neo4j.controllrt; 2 | 3 | import com.plf.learn.neo4j.dao.MinFamilyRepository; 4 | import com.plf.learn.neo4j.entity.MinFamily; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import javax.annotation.Resource; 10 | 11 | /** 12 | * @author panlf 13 | * @date 2021/12/25 14 | */ 15 | @RestController 16 | public class Neo4jController { 17 | @Resource 18 | private MinFamilyRepository minFamilyRepository; 19 | 20 | @GetMapping("create") 21 | public String testCreate(String name){ 22 | MinFamily minFamily = new MinFamily(name); 23 | minFamilyRepository.save(minFamily); 24 | return "success"; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-learn-shiro/src/main/java/com/plf/learn/shiro/utils/EncryptionPassword.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.shiro.utils; 2 | 3 | import org.apache.shiro.crypto.hash.SimpleHash; 4 | 5 | /** 6 | * @author Panlf 7 | * @date 2019/6/5 8 | */ 9 | public class EncryptionPassword { 10 | 11 | public static void main(String[] args) { 12 | /** 13 | * 加密密码 14 | */ 15 | String password = "qwer"; 16 | 17 | /** 18 | * 加密算法 19 | */ 20 | String algorithmName = "MD5"; 21 | 22 | /** 23 | * 盐值 24 | */ 25 | Object salt = "1a2b3c"; 26 | /** 27 | * 加密次数 28 | */ 29 | int hashIterations = 1024; 30 | 31 | SimpleHash simpleHash = new SimpleHash(algorithmName,password,salt,hashIterations); 32 | /** 33 | * 加密后密码 34 | */ 35 | System.out.println(simpleHash); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/java/com/plf/learn/elasticsearch/bean/Book.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elasticsearch.bean; 2 | 3 | import lombok.Data; 4 | import org.springframework.data.annotation.Id; 5 | import org.springframework.data.elasticsearch.annotations.Document; 6 | import org.springframework.data.elasticsearch.annotations.Field; 7 | import org.springframework.data.elasticsearch.annotations.FieldType; 8 | 9 | /** 10 | * 单机测试,所以设置es的分片数量为1(默认5),设置副本数量为1(默认1) 11 | * @author Panlf 12 | * @date 2019/12/27 13 | */ 14 | @Data 15 | @Document(indexName = "culture",type = "book",shards = 1,replicas = 0) 16 | public class Book { 17 | @Id 18 | private Long id; 19 | 20 | @Field(type = FieldType.Text, analyzer = "standard") 21 | private String name; 22 | 23 | @Field(type = FieldType.Keyword) 24 | private String description; 25 | 26 | @Field(type = FieldType.Double) 27 | private Double price; 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/controller/BlogController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl.controller; 2 | 3 | import com.plf.learn.staticftl.bean.Blog; 4 | import com.plf.learn.staticftl.service.BlogService; 5 | import org.springframework.beans.factory.annotation.Autowired; 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 | /** 11 | * @author Panlf 12 | * @date 2019/11/15 13 | */ 14 | @RequestMapping("/blog") 15 | @RestController 16 | public class BlogController { 17 | 18 | @Autowired 19 | private BlogService blogService; 20 | 21 | 22 | @GetMapping("save") 23 | public String saveBlog(Blog blog){ 24 | blog.setId(System.currentTimeMillis()+""); 25 | blogService.save(blog); 26 | return "success"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/java/com/plf/learn/elasticsearch/service/IndexService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elasticsearch.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; 5 | import org.springframework.stereotype.Service; 6 | 7 | /** 8 | * @author Panlf 9 | * @date 2019/12/27 10 | */ 11 | @Service 12 | public class IndexService { 13 | 14 | @Autowired 15 | private ElasticsearchTemplate elasticsearchTemplate; 16 | 17 | 18 | public void createIndex(Class indexClass){ 19 | // 创建索引,会根据对应类的@Document注解信息来创建 20 | elasticsearchTemplate.createIndex(indexClass); 21 | // 配置映射,会根据对应类中的id、Field等字段来自动完成映射 22 | elasticsearchTemplate.putMapping(indexClass); 23 | } 24 | 25 | public void deleteIndex(Class indexClass){ 26 | elasticsearchTemplate.deleteIndex(indexClass); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/java/com/plf/learn/sharding/SpringBootShardingApplication.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.sharding; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.boot.autoconfigure.SpringBootApplication; 6 | import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 7 | import org.springframework.transaction.annotation.EnableTransactionManagement; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/6/12 12 | */ 13 | @SpringBootApplication 14 | @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) //排除DataSourceConfiguratrion 15 | @EnableTransactionManagement(proxyTargetClass = true) //开启事物管理功能 16 | public class SpringBootShardingApplication { 17 | public static void main(String[] args) { 18 | SpringApplication.run(SpringBootShardingApplication.class,args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/src/main/java/com/plf/learn/aop/multidata/service/CountTablesService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.aop.multidata.service; 2 | 3 | import com.plf.learn.aop.multidata.annotation.TargetDataSource; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.jdbc.core.JdbcTemplate; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | * 测试库 10 | * @author Panlf 11 | * @date 2019/8/7 12 | */ 13 | @Service 14 | public class CountTablesService { 15 | 16 | @Autowired 17 | private JdbcTemplate jdbcTemplate; 18 | 19 | @TargetDataSource("house_user") 20 | public Integer countUser(){ 21 | return jdbcTemplate.queryForObject("select count(*) from user",Integer.class); 22 | } 23 | 24 | @TargetDataSource("house_comment") 25 | public Integer countComment(){ 26 | return jdbcTemplate.queryForObject("select count(*) from comment",Integer.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/config/MyMetaObjectHandler.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.config; 2 | 3 | import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.apache.ibatis.reflection.MetaObject; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.sql.Timestamp; 9 | 10 | @Slf4j 11 | @Component 12 | public class MyMetaObjectHandler implements MetaObjectHandler { 13 | @Override 14 | public void insertFill(MetaObject metaObject) { 15 | log.info("start insert fill ...."); 16 | setFieldValByName("createtime", new Timestamp(System.currentTimeMillis()), metaObject); 17 | } 18 | 19 | @Override 20 | public void updateFill(MetaObject metaObject) { 21 | log.info("start update fill ...."); 22 | setFieldValByName("updatetime", new Timestamp(System.currentTimeMillis()), metaObject); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/resources/readme.txt: -------------------------------------------------------------------------------- 1 | Elastic-job 2 | 3 | 任务调度是指系统为了自动完成特定任务,在约定的特定时刻去执行任务的过程。 4 | 5 | 1)、Elastic-job 当当网基于quartz二次开发的弹性分布式任务调度系统,采用Zookeeper实现分布式协调,实现任务高可用以及分片 6 | 2)、Saturn 唯品会开源的一个分布式调度平台,可以全域统一配置,统一监控,实现任务高可用以及分片并发处理。 7 | 3)、xxl-job大众点评的分布式任务调度平台,是一个轻量级分布式任务调度平台。 8 | 4)、TBSchedule 淘宝非常优秀高性能分布式调度框架 9 | 10 | 分布式系统具体特点 11 | 1、分布性 每个部分都可以独立部署,服务之间交互通过网络进行通信 12 | 2、伸缩性 每个部分都可以集群方式部署 13 | 3、高可用 每个部分都可以集群部分,保证高可用 14 | 15 | 分布式调度实现的目标 16 | 1、并行任务调度 17 | 并行任务调度实现靠多线程。 18 | 将任务调度程序分布式部署,每个节点还可以部署为集群。 19 | 将任务分割成若干个分片,由不同的实例并行执行 20 | 21 | 2、高可用 22 | 若某一个实例宕机,不影响其他实例来执行任务。 23 | 24 | 3、弹性扩容 25 | 当集群中增加实例就可以提高并执行任务的处理效率。 26 | 27 | 4、任务管理与检测 28 | 对系统中存在的所有定时任务统一的管理及监测。 29 | 30 | 5、避免任务重复执行 31 | 分布式锁 32 | 33 | 34 | Zookeeper的两个作用 35 | Elastic-job依赖Zookeeper完成对执行任务信息的存储(如任务名称、任务参与实例、任务执行策略等) 36 | Elastic-job依赖Zookeeper实现选举机制,在任务执行实例数量变化时(如在快速上手中的启动新实例或停止实例) 37 | 会触发选举机制来决定让哪个实例去执行该任务。 38 | 39 | 40 | 分片概念 41 | 作业分片是指任务的分布式执行,需要将一个任务拆分为多个独立的任务项,然后由分布式的应用实例分别执行某一个或几个分片项。 42 | 43 | -------------------------------------------------------------------------------- /springboot-learn-dataway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8066 3 | servlet: 4 | context-path: /dataway 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/springboot?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | druid: 13 | initial-size: 3 14 | min-idle: 3 15 | max-active: 10 16 | max-wait: 60000 17 | filter: 18 | stat: 19 | log-slow-sql: true 20 | slow-sql-millis: 1 21 | 22 | # 是否启用 Dataway 功能(必选:默认false) 23 | HASOR_DATAQL_DATAWAY: true 24 | 25 | # 是否开启 Dataway 后台管理界面(必选:默认false) 26 | HASOR_DATAQL_DATAWAY_ADMIN: true 27 | 28 | # dataway API工作路径(可选,默认:/api/) 29 | HASOR_DATAQL_DATAWAY_API_URL: /api/ 30 | 31 | # dataway-ui 的工作路径(可选,默认:/interface-ui/) 32 | HASOR_DATAQL_DATAWAY_UI_URL: /interface-ui/ 33 | 34 | # SQL执行器方言设置(可选,建议设置) 35 | HASOR_DATAQL_FX_PAGE_DIALECT: mysql 36 | 37 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8003 3 | servlet: 4 | context-path: /jwt 5 | 6 | spring: 7 | datasource: 8 | url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 9 | username: root 10 | password: root 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | jpa: 13 | database: MYSQL 14 | show-sql: true 15 | hibernate: 16 | ddl-auto: update 17 | naming: 18 | physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy 19 | database-platform: org.hibernate.dialect.MySQL5InnoDBDialect 20 | redis: 21 | #数据库索引 22 | database: 0 23 | host: 127.0.0.1 24 | port: 6379 25 | jedis: 26 | pool: 27 | #最大连接数 28 | max-active: 8 29 | #最大阻塞等待时间(负数表示没限制) 30 | max-wait: -1 31 | #最大空闲 32 | max-idle: 8 33 | #最小空闲 34 | min-idle: 0 35 | #连接超时时间 36 | timeout: 10000 -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/controller/MailEventController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event.controller; 2 | 3 | import com.plf.learn.custom.event.emailevents.EmailEventPublish; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 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 | /** 11 | * @author Panlf 12 | * @date 2019/4/19 13 | */ 14 | @RestController 15 | @Slf4j 16 | public class MailEventController { 17 | 18 | @Autowired 19 | private EmailEventPublish emailEventPublish; 20 | 21 | @RequestMapping("/event") 22 | public void publishEvent(@RequestParam String emailAddress) { 23 | // 发布事件 -- 采用异步处理 24 | emailEventPublish.publishEvent(emailAddress); 25 | 26 | // 正常该语句先执行 27 | log.info("Controller业务处理"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-learn-aop-multidata/src/main/java/com/plf/learn/aop/multidata/controller/CountTablesController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.aop.multidata.controller; 2 | 3 | import com.plf.learn.aop.multidata.service.CountTablesService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/8/7 12 | */ 13 | @RestController 14 | @Slf4j 15 | public class CountTablesController { 16 | 17 | @Autowired 18 | private CountTablesService countTablesService; 19 | 20 | @GetMapping("count") 21 | public String getCount(){ 22 | Integer userCount = countTablesService.countUser(); 23 | Integer commentCount = countTablesService.countComment(); 24 | log.info("house_user中的用户表总量为{}",userCount); 25 | log.info("house_comment中的评价表总量为{}",commentCount); 26 | return "success"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/service/AnalysisFileService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document.service; 2 | 3 | import java.util.concurrent.TimeUnit; 4 | 5 | import com.plf.learn.document.container.DocumentContext; 6 | import com.plf.learn.document.utils.interfaces.OperateDocument; 7 | import lombok.extern.slf4j.Slf4j; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.scheduling.annotation.Async; 11 | import org.springframework.stereotype.Service; 12 | 13 | import javax.annotation.Resource; 14 | 15 | /** 16 | * 解析文档,将文档数据保存到数据库 17 | * @author Panlf 18 | * @date 2020/2/13 19 | */ 20 | @Slf4j 21 | @Service 22 | public class AnalysisFileService { 23 | 24 | @Async 25 | public void insertdb() { 26 | try { 27 | TimeUnit.SECONDS.sleep(5); 28 | } catch (InterruptedException e) { 29 | e.printStackTrace(); 30 | } 31 | for(int i=0;i<10;i++) { 32 | log.info("正在处理+++{}",i); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/repository/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa.repository; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.plf.learn.jpa.bean.Student; 7 | import com.plf.learn.jpa.dto.StudentDto; 8 | import org.springframework.data.jpa.repository.JpaRepository; 9 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 10 | import org.springframework.data.jpa.repository.Query; 11 | 12 | 13 | public interface StudentRepository extends JpaRepository,JpaSpecificationExecutor{ 14 | @Query(value="select new com.plf.learn.jpa.dto.StudentDto(st.id,st.name,st.age,st.schoolId,sc.schoolName) from Student st left join School sc on sc.id=st.schoolId") 15 | public List findStudentDto(); 16 | 17 | 18 | @Query(value="select st.id,st.name,st.age,st.school_id,sc.school_name from student st left join school sc on sc.id=st.school_id",nativeQuery=true) 19 | public List> findStudentDtoMap(); 20 | 21 | } 22 | -------------------------------------------------------------------------------- /springboot-learn-staticftl/src/main/java/com/plf/learn/staticftl/listener/BlogStaticFtlListener.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.staticftl.listener; 2 | 3 | import com.plf.learn.staticftl.bean.Blog; 4 | import com.plf.learn.staticftl.service.BlogService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.jms.annotation.JmsListener; 7 | import org.springframework.stereotype.Component; 8 | 9 | import java.util.HashMap; 10 | import java.util.Map; 11 | 12 | /** 13 | * @author Panlf 14 | * @date 2019/11/18 15 | */ 16 | @Component 17 | public class BlogStaticFtlListener { 18 | 19 | @Autowired 20 | private BlogService blogService; 21 | 22 | @JmsListener(destination="staticftl.blog") 23 | public void ListenBlogQueue(String message){ 24 | 25 | String blog_id = message; 26 | 27 | //获取到信息 28 | Blog blog = blogService.getById(blog_id); 29 | Map map = new HashMap<>(); 30 | map.put("blog",blog); 31 | blogService.productStaticPage(map,blog_id); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/emailevents/EmailEventListener.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event.emailevents; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.context.ApplicationListener; 5 | import org.springframework.scheduling.annotation.Async; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/4/19 13 | */ 14 | @Component 15 | @Slf4j 16 | public class EmailEventListener implements ApplicationListener{ 17 | 18 | /** 19 | * 异步处理监听到邮件 20 | * @param event 21 | */ 22 | @Async 23 | @Override 24 | public void onApplicationEvent(EmailEvent event) { 25 | log.info("监听到事件--邮箱地址:" + event.getEmailAddress()); 26 | 27 | //模拟逻辑处理 28 | try { 29 | TimeUnit.SECONDS.sleep(3); 30 | } catch (InterruptedException e) { 31 | log.error("异常:{}",e.getMessage()); 32 | } 33 | 34 | log.info("事件处理完成"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-learn-neo4j/src/main/java/com/plf/learn/neo4j/dao/MinFamilyRepository.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.neo4j.dao; 2 | 3 | import com.plf.learn.neo4j.entity.MinFamily; 4 | import org.springframework.data.neo4j.repository.Neo4jRepository; 5 | import org.springframework.data.neo4j.repository.query.Query; 6 | import org.springframework.data.repository.query.Param; 7 | import org.springframework.stereotype.Repository; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * @author panlf 13 | * @date 2021/12/25 14 | */ 15 | @Repository 16 | public interface MinFamilyRepository extends Neo4jRepository { 17 | @Query("match (n:minFamily {name:$in}),(m:minFamily {name:$out}) " + 18 | "create (n)-[:小敏家人物关系{relation:$relation}]->(m)") 19 | void createRelation(@Param("in") String in, @Param("relation") String relation, @Param("out") String out); 20 | 21 | @Query(" MATCH p = (n:minFamily {name:$name}), (n)-[:小敏家人物关系{relation:$relation}]->(t) return t") 22 | List findByName(@Param("name") String name, @Param("relation") String relation); 23 | } 24 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/java/com/plf/learn/monitor/controller/PersonController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.monitor.controller; 2 | 3 | import com.github.pagehelper.PageInfo; 4 | import com.plf.learn.monitor.bean.Person; 5 | import com.plf.learn.monitor.service.PersonService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RequestMapping; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | /** 13 | * @author Panlf 14 | * @date 2019/7/11 15 | */ 16 | @RestController 17 | @RequestMapping("person") 18 | public class PersonController { 19 | @Autowired 20 | private PersonService personService; 21 | 22 | @GetMapping("getPerson/{pagenum}/{pagesize}") 23 | public PageInfo getPerson(@PathVariable("pagenum") Integer pagenum, @PathVariable("pagesize") Integer pagesize){ 24 | return personService.findPerson(pagenum, pagesize); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/utils/RedisUtils.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.utils; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.StringRedisTemplate; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.annotation.Resource; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/5/16 13 | */ 14 | @Component 15 | public class RedisUtils { 16 | @Resource 17 | public StringRedisTemplate stringRedisTemplate; 18 | 19 | /** 20 | * 往Redis中存储字符串数据 21 | * @param key 键 22 | * @param value 值 23 | * @param time 过期时间,单位秒 24 | */ 25 | public void insertStr(String key,String value,Integer time){ 26 | stringRedisTemplate.opsForValue().set(key,value,time, TimeUnit.SECONDS); 27 | } 28 | 29 | /** 30 | * 根据key从Redis获取值 31 | * @param key 键 32 | * @return 33 | */ 34 | public String getStr(String key){ 35 | return stringRedisTemplate.opsForValue().get(key); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/controller/RedisController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.controller; 2 | 3 | import com.plf.learn.redis.annotations.ApiIdempotent; 4 | import com.plf.learn.redis.service.TokenService; 5 | import lombok.extern.slf4j.Slf4j; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/12/26 14 | */ 15 | @RestController 16 | @Slf4j 17 | public class RedisController { 18 | 19 | @Autowired 20 | private TokenService tokenService; 21 | 22 | @GetMapping("/create/{username}") 23 | public String createToken(@PathVariable String username){ 24 | return tokenService.createToken(username); 25 | } 26 | 27 | @GetMapping("/order") 28 | @ApiIdempotent 29 | public String getOrder(){ 30 | log.info("幂等性检验通过之后的业务操作"); 31 | return "success"; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /springboot-learn-share-session/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8030 3 | servlet: 4 | context-path: /sharesession 5 | 6 | spring: 7 | redis: 8 | #数据库索引 9 | database: 0 10 | host: 127.0.0.1 11 | port: 6379 12 | lettuce: 13 | pool: 14 | #最大连接数 15 | max-active: 8 16 | #最大阻塞等待时间(负数表示没限制) 17 | max-wait: 8 18 | #最大空闲 19 | max-idle: 8 20 | #最小空闲 21 | min-idle: -1 22 | #连接超时时间 23 | timeout: 10000 24 | session: 25 | store-type: redis 26 | redis: 27 | # session更新策略,有ON_SAVE、IMMEDIATE, 28 | # ON_SAVE是在调用#SessionRepository#save(org.springframework.session.Session)时,在response commit前刷新缓存 29 | # IMMEDIATE是只要有任何更新就会刷新缓存 30 | flush-mode: on_save 31 | 32 | # ON_SAVE: 只有当SessionRepository.save(Session)方法被调用时, 才会将session中的数据同步到redis中. 在web 应用中, 当请求完成响应后, 才开始同步. 也就是说在执行response 之前session数据都是缓存在本地的. 33 | # IMMEDIATE: 实时同步session 数据到redis. 当执行SessionRepository.createSession()时, 会将session数据同步到redis中; 当对session的attribute进行set/remove 等操作时, 也会同步session中的数据到redis中. 34 | 35 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/entity/User.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.entity; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.List; 6 | 7 | import lombok.Data; 8 | import org.springframework.security.core.GrantedAuthority; 9 | import org.springframework.security.core.userdetails.UserDetails; 10 | 11 | @Data 12 | public class User implements UserDetails{ 13 | 14 | private Integer id; 15 | private String username; 16 | private String realname; 17 | private String password; 18 | /** 19 | * 创建日期 20 | */ 21 | private Date createDate; 22 | 23 | /** 24 | * 最后登录时间 25 | */ 26 | private Date lastLogintime; 27 | 28 | /** 29 | * 是否可用 30 | */ 31 | private boolean enabled; 32 | /** 33 | * 是否过期 34 | */ 35 | private boolean accountNonExpired; 36 | /** 37 | * 是否锁定 38 | */ 39 | private boolean accountNonLocked; 40 | 41 | /** 42 | * 证书是否过期 43 | */ 44 | private boolean credentialsNonExpired; 45 | 46 | /** 47 | * 用户拥有的所有权限 48 | */ 49 | public List authorities = new ArrayList<>(); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/config/ErrorPageConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.config; 2 | 3 | import org.springframework.boot.web.server.ConfigurableWebServerFactory; 4 | import org.springframework.boot.web.server.ErrorPage; 5 | import org.springframework.boot.web.server.WebServerFactoryCustomizer; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.http.HttpStatus; 9 | 10 | /** 11 | * 定义错误页面 12 | * @author Panlf 13 | * 14 | */ 15 | @Configuration 16 | public class ErrorPageConfig { 17 | 18 | @Bean 19 | public WebServerFactoryCustomizer webServerFactoryCustomizer() { 20 | /*return new WebServerFactoryCustomizer () { 21 | 22 | @Override 23 | public void customize(ConfigurableWebServerFactory factory) { 24 | factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/403")); 25 | } 26 | };*/ 27 | return factory -> factory.addErrorPages(new ErrorPage(HttpStatus.FORBIDDEN, "/403")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/resources/readme.txt: -------------------------------------------------------------------------------- 1 | Cluster 集群,包含多个节点,每个节点属于哪个集群是 2 | 通过配置(集群名称,默认elasticsearch)来决定, 3 | 4 | Node 节点,集群中的一个节点,节点也有一个名称(默认是随机分配的),节点名称很重要 5 | (在执行运维管理的时候),默认节点会去加入一个名称为elasticsearch的集群, 6 | 如果直接启动一堆节点,那么他们会自动组成一个elasticsearch集群, 7 | 当然一个节点也可以组成一个elasticsearch集群 8 | 9 | Document 文档,es中的最小数据单元,一个document可以是一条客户数据、商品分类数据等, 10 | 通常使用JSON数据结构表示,每个index下的type中,都可以去存储多个document。 11 | 一个document里面有多个field,每个field就是一个数据字段 12 | 13 | Index 索引,包含一堆相似结构的文档数据,比如一个客户的索引、商品分类索引等,索引也有名称 14 | 15 | Type 类型,每个索引都可以有一个或者多个type,type是index中的一个逻辑分类, 16 | 一个type下的document,都有相同的Field,比如博客系统,有一个索引,可以定义用户数据type, 17 | 博客数据type等 18 | 19 | shard 单台机器无法存储大量数据,es可以将一个索引中的数据切分为多个shard,分布在多台服务器上存储。 20 | 有了shard就可以横向扩展,存储更多的数据,让搜索和分析等操作分布到多台服务器上执行 21 | 提高吞吐量和性能。每个shard都是一个lucene index 22 | 23 | replica 任何一个服务器随时可能故障或宕机,此时shard可能就会丢失,因此可以为每个shard创建 24 | 多个replica副本。replica可以在shard故障时提供备用服务,保证数据不丢失,多个replica 25 | 还可以提升搜索操作的吞吐量和性能。primary shard(建立索引时一次设置,不能修改,默认5个), 26 | replica shard(随时修改数量,默认1个),默认每个索引10个shard,5个primary shard,5个replica shard 27 | 最小的高可用配置,是2台服务器。 28 | 29 | Index 数据库 30 | type 表 31 | document 行 -------------------------------------------------------------------------------- /springboot-learn-mongodb/src/main/java/com/plf/learn/mongodb/bean/Comment.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mongodb.bean; 2 | 3 | import lombok.Data; 4 | //import org.springframework.data.mongodb.core.index.CompoundIndex; 5 | //import org.springframework.data.annotation.Id; 6 | import org.springframework.data.mongodb.core.index.Indexed; 7 | import org.springframework.data.mongodb.core.mapping.Document; 8 | 9 | import java.time.LocalDateTime; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2020/3/2 14 | */ 15 | @Document("comment") 16 | @Data 17 | //复合索引 18 | //@CompoundIndex(def="{'userid':1,'nickname':-1}") 19 | public class Comment { 20 | 21 | //主键标识,该属性的值会自动对应mongodb的主键字段"_id",如果该属性名就叫id,则该注解可以省略,否则必须写 22 | //@Id 23 | private String id; 24 | private String comment; 25 | 26 | /** 27 | * 添加一个单字段索引 28 | */ 29 | @Indexed 30 | private String userid; 31 | private String nickname; 32 | private LocalDateTime createdatetime; 33 | private Integer likenum; 34 | private Integer replynum; 35 | private String state; 36 | private String parentid; 37 | private String articleid; 38 | } 39 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.mapper; 2 | 3 | import com.plf.learn.security.entity.Permission; 4 | import com.plf.learn.security.entity.User; 5 | import org.apache.ibatis.annotations.Mapper; 6 | import org.apache.ibatis.annotations.Select; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2020/3/13 13 | */ 14 | @Mapper 15 | public interface UserMapper { 16 | @Select("select * from sys_user where username = #{username}") 17 | public User findByUsername(String username); 18 | 19 | @Select("select permission.* " + 20 | " from " + 21 | " sys_user user" + 22 | " inner join sys_user_role user_role on user.id=user_role.user_id" + 23 | " inner join sys_role_permission role_permission on user_role.role_id=role_permission.role_id" + 24 | " inner join sys_permission permission on role_permission.perm_id = permission.id" + 25 | " where user.username=#{username}") 26 | public List findPermissionByUsername(String username); 27 | } 28 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/java/com/plf/learn/caffeine/dao/UserInfoDao.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.caffeine.dao; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.stereotype.Repository; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * @author panlf 11 | * @date 2021/8/16 12 | */ 13 | @Repository 14 | @Slf4j 15 | public class UserInfoDao { 16 | public Map map = new HashMap<>(); 17 | 18 | 19 | public String addUserInfo(Integer id,String userInfo){ 20 | log.info("数据库操作 - add"); 21 | 22 | map.put(id,userInfo); 23 | 24 | return userInfo; 25 | } 26 | 27 | public String getUserInfo(Integer id){ 28 | log.info("数据库操作 - get"); 29 | 30 | return map.get(id); 31 | } 32 | 33 | public String updateUserInfo(Integer id,String userInfo){ 34 | log.info("数据库操作 - update"); 35 | 36 | map.put(id,userInfo); 37 | 38 | return userInfo; 39 | } 40 | 41 | public void deleteUserInfo(Integer id){ 42 | log.info("数据库操作 - delete"); 43 | 44 | map.remove(id); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /springboot-learn-solr/src/main/java/com/plf/learn/solr/controller/SolrController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.solr.controller; 2 | 3 | import com.plf.learn.solr.entity.Worker; 4 | import com.plf.learn.solr.service.SolrService; 5 | import org.apache.solr.common.SolrDocument; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.List; 11 | 12 | /** 13 | * @author Panlf 14 | * @date 2020/3/18 15 | */ 16 | @RestController 17 | public class SolrController { 18 | 19 | @Autowired 20 | private SolrService solrService; 21 | 22 | @RequestMapping("save") 23 | public String saveWorker(Worker worker){ 24 | solrService.saveWorker(worker); 25 | return "success"; 26 | } 27 | 28 | @RequestMapping("get") 29 | public SolrDocument getWorker(String id){ 30 | return solrService.findById(id); 31 | } 32 | 33 | @RequestMapping("getAll") 34 | public List getAllWorker(){ 35 | return solrService.findAll(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /springboot-learn-kafka/src/main/java/com/plf/learn/kafka/producer/KafkaProducer.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.kafka.producer; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.plf.learn.kafka.message.Message; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.kafka.core.KafkaTemplate; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/12/26 12 | */ 13 | @Component 14 | public class KafkaProducer { 15 | 16 | @Autowired 17 | private KafkaTemplate kafkaTemplate; 18 | 19 | /** 20 | * kafka发送消息,这里只能使用String 21 | * @param key 22 | * @param message 23 | */ 24 | public void sendMessage(String key,Message message){ 25 | ObjectMapper mapper = new ObjectMapper(); 26 | String jsonMessage=""; 27 | try{ 28 | jsonMessage = mapper.writeValueAsString(message); 29 | }catch (Exception e){ 30 | e.printStackTrace(); 31 | } 32 | kafkaTemplate.send(message.getTopic(),message.getPartition(),key,jsonMessage); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/java/com/plf/learn/websocket/service/WebSocketService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.websocket.service; 2 | 3 | import com.plf.learn.websocket.entity.ResponseMessage; 4 | import org.springframework.beans.factory.annotation.Autowired; 5 | import org.springframework.messaging.simp.SimpMessagingTemplate; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2020/3/20 13 | */ 14 | @Service 15 | public class WebSocketService { 16 | @Autowired 17 | private SimpMessagingTemplate simpMessagingTemplate; 18 | 19 | /** 20 | * 广播 21 | * 发给所有在线用户 22 | * 23 | * @param msg 24 | */ 25 | public void sendMsg(ResponseMessage msg) { 26 | simpMessagingTemplate.convertAndSend("/topic", msg); 27 | } 28 | 29 | /** 30 | * 发送给指定用户 31 | * @param users 32 | * @param msg 33 | */ 34 | public void send2Users(List users, ResponseMessage msg) { 35 | users.forEach(userName -> { 36 | simpMessagingTemplate.convertAndSendToUser(userName, "/msg", msg); 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'springboot-learn' 2 | include 'springboot-learn-jpa' 3 | include 'springboot-learn-mybatis-plus' 4 | include 'springboot-learn-custom-event' 5 | include 'springboot-learn-mail' 6 | include 'springboot-learn-jwt' 7 | include 'springboot-learn-distributed-lock' 8 | include 'springboot-learn-jetcache' 9 | include 'springboot-learn-shiro' 10 | include 'springboot-learn-sharding-jdbc' 11 | include 'springboot-learn-druid-monitor' 12 | include 'springboot-learn-aop-multidata' 13 | include 'springboot-learn-staticftl' 14 | include 'springboot-learn-elastic-job' 15 | include 'springboot-learn-share-session' 16 | include 'springboot-learn-kafka' 17 | include 'springboot-learn-redis' 18 | include 'springboot-learn-elasticsearch' 19 | include 'springboot-learn-document' 20 | include 'springboot-learn-mongodb' 21 | include 'springboot-learn-security' 22 | include 'springboot-learn-log' 23 | include 'springboot-learn-solr' 24 | include 'springboot-learn-threadlocal' 25 | include 'springboot-learn-websocket' 26 | include 'springboot-learn-dataway' 27 | include 'springboot-learn-caffeine' 28 | include 'springboot-learn-api-limiter' 29 | include 'springboot-learn-neo4j' 30 | 31 | -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/controller/UploadFileController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document.controller; 2 | 3 | import com.plf.learn.document.container.DocumentContext; 4 | import com.plf.learn.document.service.AnalysisFileService; 5 | import com.plf.learn.document.utils.interfaces.OperateDocument; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | 12 | @RestController 13 | @RequestMapping("upload") 14 | public class UploadFileController { 15 | 16 | @Autowired 17 | private DocumentContext documentContext; 18 | 19 | @Autowired 20 | private AnalysisFileService analysisFileService; 21 | 22 | @GetMapping("save") 23 | public String upload() { 24 | analysisFileService.insertdb(); 25 | return "正在解析...."; 26 | } 27 | 28 | @GetMapping("edit") 29 | public String editDocument(String dealKey){ 30 | OperateDocument operateDocument = documentContext.getResource(dealKey); 31 | return operateDocument.readDocument(null); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/resources/sql/ds0.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Source Server : localhost 3 | Source Server Version : 50720 4 | Source Host : localhost:3306 5 | Source Database : ds0 6 | 7 | Target Server Type : MYSQL 8 | Target Server Version : 50720 9 | File Encoding : 65001 10 | 11 | Date: 2019-06-12 14:39:32 12 | */ 13 | 14 | SET FOREIGN_KEY_CHECKS=0; 15 | 16 | -- ---------------------------- 17 | -- Table structure for t_order_0 18 | -- ---------------------------- 19 | DROP TABLE IF EXISTS `t_order_0`; 20 | CREATE TABLE `t_order_0` ( 21 | `id` bigint(30) NOT NULL, 22 | `order_id` bigint(30) DEFAULT NULL, 23 | `user_id` bigint(30) DEFAULT NULL, 24 | `username` varchar(20) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; 27 | 28 | -- ---------------------------- 29 | -- Table structure for t_order_1 30 | -- ---------------------------- 31 | DROP TABLE IF EXISTS `t_order_1`; 32 | CREATE TABLE `t_order_1` ( 33 | `id` bigint(30) NOT NULL, 34 | `order_id` bigint(30) DEFAULT NULL, 35 | `user_id` bigint(30) DEFAULT NULL, 36 | `username` varchar(20) DEFAULT NULL, 37 | PRIMARY KEY (`id`) 38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; 39 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/resources/sql/ds1.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Source Server : localhost 3 | Source Server Version : 50720 4 | Source Host : localhost:3306 5 | Source Database : ds1 6 | 7 | Target Server Type : MYSQL 8 | Target Server Version : 50720 9 | File Encoding : 65001 10 | 11 | Date: 2019-06-12 14:39:47 12 | */ 13 | 14 | SET FOREIGN_KEY_CHECKS=0; 15 | 16 | -- ---------------------------- 17 | -- Table structure for t_order_0 18 | -- ---------------------------- 19 | DROP TABLE IF EXISTS `t_order_0`; 20 | CREATE TABLE `t_order_0` ( 21 | `id` bigint(30) NOT NULL, 22 | `order_id` bigint(30) DEFAULT NULL, 23 | `user_id` bigint(30) DEFAULT NULL, 24 | `username` varchar(20) DEFAULT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; 27 | 28 | -- ---------------------------- 29 | -- Table structure for t_order_1 30 | -- ---------------------------- 31 | DROP TABLE IF EXISTS `t_order_1`; 32 | CREATE TABLE `t_order_1` ( 33 | `id` bigint(30) NOT NULL, 34 | `order_id` bigint(30) DEFAULT NULL, 35 | `user_id` bigint(30) DEFAULT NULL, 36 | `username` varchar(20) DEFAULT NULL, 37 | PRIMARY KEY (`id`) 38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC; 39 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/controller/StudentController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa.controller; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import com.plf.learn.jpa.bean.Student; 7 | import com.plf.learn.jpa.dto.StudentDto; 8 | import com.plf.learn.jpa.service.StudentService; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestParam; 12 | import org.springframework.web.bind.annotation.RestController; 13 | 14 | 15 | @RestController 16 | @RequestMapping("/student") 17 | public class StudentController { 18 | 19 | @Autowired 20 | private StudentService studentService; 21 | 22 | @RequestMapping("/findByName") 23 | public List findByName(@RequestParam(required=false) String name){ 24 | return studentService.findStudentByName(name); 25 | } 26 | 27 | @RequestMapping("/findStudentDto") 28 | public List findStudentDto(){ 29 | return studentService.findStudentDto(); 30 | } 31 | 32 | @RequestMapping("/findStudentDtoMap") 33 | public List> findStudentDtoMap(){ 34 | return studentService.findStudentDtoMap(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /springboot-learn-jetcache/src/main/java/com/plf/learn/jetcache/controller/PersonController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jetcache.controller; 2 | 3 | import com.plf.learn.jetcache.bean.Person; 4 | import com.plf.learn.jetcache.service.PersonService; 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.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/5/24 14 | */ 15 | @RestController 16 | @RequestMapping("person") 17 | public class PersonController { 18 | 19 | @Autowired 20 | private PersonService personService; 21 | 22 | @GetMapping("get") 23 | public Person getById(Integer id){ 24 | return personService.getPersonById(id); 25 | } 26 | 27 | @PostMapping("update") 28 | public String updatePerson(Person person){ 29 | personService.updatePerson(person); 30 | return "success"; 31 | } 32 | 33 | @GetMapping("delete") 34 | public String deleteById(Integer id){ 35 | personService.deletePerson(id); 36 | return "success"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-learn-kafka/src/main/java/com/plf/learn/kafka/controller/KafkaController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.kafka.controller; 2 | 3 | import com.plf.learn.kafka.message.Message; 4 | import com.plf.learn.kafka.producer.KafkaProducer; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.PathVariable; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.util.Date; 11 | import java.util.Random; 12 | 13 | /** 14 | * @author Panlf 15 | * @date 2019/12/26 16 | */ 17 | @RestController 18 | public class KafkaController { 19 | 20 | @Autowired 21 | private KafkaProducer kafkaProducer; 22 | 23 | @GetMapping("/send/{id}/{partition}/{content}") 24 | public String sendMessage(@PathVariable Integer id,@PathVariable Integer partition,@PathVariable String content){ 25 | Message message = new Message(); 26 | message.setId(id); 27 | message.setTopic("kafka-test"); 28 | message.setContent(content); 29 | message.setPartition(partition); 30 | message.setCreateTime(new Date()); 31 | kafkaProducer.sendMessage(String.valueOf(id),message); 32 | return "success"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/java/com/plf/learn/caffeine/controller/CaffeineController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.caffeine.controller; 2 | 3 | import com.plf.learn.caffeine.service.UserInfoService; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RestController; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * @author panlf 11 | * @date 2021/8/16 12 | */ 13 | @RestController 14 | public class CaffeineController { 15 | 16 | @Resource 17 | private UserInfoService userInfoService; 18 | 19 | @GetMapping("add") 20 | public String add(Integer id,String userInfo){ 21 | userInfoService.addUserInfo(id,userInfo); 22 | return "success"; 23 | } 24 | 25 | @GetMapping("get") 26 | public String get(Integer id){ 27 | String userInfo = userInfoService.getUserById(id); 28 | return userInfo; 29 | } 30 | 31 | @GetMapping("update") 32 | public String update(Integer id,String userInfo){ 33 | userInfoService.updateUserInfo(id,userInfo); 34 | return "success"; 35 | } 36 | 37 | @GetMapping("delete") 38 | public String delete(Integer id){ 39 | userInfoService.deleteUserById(id); 40 | return "success"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /springboot-learn-jetcache/src/main/java/com/plf/learn/jetcache/service/impl/PersonServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jetcache.service.impl; 2 | 3 | import com.alicp.jetcache.Cache; 4 | import com.alicp.jetcache.anno.CacheType; 5 | import com.alicp.jetcache.anno.CreateCache; 6 | import com.plf.learn.jetcache.bean.Person; 7 | import com.plf.learn.jetcache.service.PersonService; 8 | import org.springframework.stereotype.Service; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/5/24 13 | */ 14 | @Service 15 | public class PersonServiceImpl implements PersonService { 16 | 17 | @CreateCache(name = "PersonService.personCache", expire = 3600, cacheType = CacheType.BOTH, localLimit = 50) 18 | private Cache personCache; 19 | 20 | @Override 21 | public Person getPersonById(Integer id) { 22 | Person person = personCache.get(id); 23 | if(person!=null){ 24 | return person; 25 | } 26 | person = new Person(id,"Rush",23); 27 | personCache.put(id,person); 28 | return person; 29 | } 30 | 31 | @Override 32 | public void updatePerson(Person person) { 33 | personCache.put(person.getId(),person); 34 | } 35 | 36 | @Override 37 | public void deletePerson(Integer id) { 38 | personCache.remove(id); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /springboot-learn-share-session/src/main/java/com/plf/learn/share/session/controller/ShareSessionController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.share.session.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.PathVariable; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpSession; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/12/4 14 | */ 15 | @RestController 16 | public class ShareSessionController { 17 | 18 | 19 | @Value("${server.port}") 20 | public int port; 21 | 22 | @GetMapping("/create/{name}") 23 | public String createSession(HttpServletRequest request, @PathVariable String name){ 24 | HttpSession session=request.getSession(); 25 | session.setAttribute("name",name); 26 | return "当前端口"+port+"项目的session.id:"+session.getId()+",name为"+name+"已成功存入session"; 27 | 28 | } 29 | 30 | @GetMapping("/get") 31 | public String getSession(HttpServletRequest request){ 32 | HttpSession session=request.getSession(); 33 | return "当前端口"+port+"项目的session.id:"+session.getId()+",name为"+session.getAttribute("name"); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/controller/ProductController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.controller; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.springframework.security.core.context.SecurityContextHolder; 5 | import org.springframework.security.core.userdetails.UserDetails; 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | @Controller 10 | @RequestMapping("/product") 11 | @Slf4j 12 | public class ProductController { 13 | 14 | @RequestMapping("/add") 15 | public String add() { 16 | return "product/add"; 17 | } 18 | 19 | 20 | @RequestMapping("/update") 21 | public String update() { 22 | return "product/update"; 23 | } 24 | 25 | @RequestMapping("/list") 26 | public String list() { 27 | 28 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 29 | 30 | if(principal!=null) { 31 | if(principal instanceof UserDetails) { 32 | UserDetails userDetails = (UserDetails) principal; 33 | String username = userDetails.getUsername(); 34 | log.info("当前登录用户:{}",username); 35 | } 36 | } 37 | 38 | return "product/list"; 39 | } 40 | 41 | @RequestMapping("/delete") 42 | public String delete() { 43 | return "product/delete"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/java/com/plf/learn/sharding/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.sharding.controller; 2 | 3 | import com.plf.learn.sharding.bean.Order; 4 | import com.plf.learn.sharding.service.OrderService; 5 | import org.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/6/12 14 | */ 15 | @RestController 16 | @RequestMapping("order") 17 | public class OrderController { 18 | 19 | final SnowflakeShardingKeyGenerator keyGenerator = new SnowflakeShardingKeyGenerator(); 20 | 21 | @Autowired 22 | private OrderService orderService; 23 | 24 | @GetMapping("save") 25 | public String save(Order order){ 26 | String keyId = keyGenerator.generateKey().toString(); 27 | long id = Long.valueOf(keyId); 28 | order.setId(id); 29 | orderService.save(order); 30 | return "success"; 31 | } 32 | 33 | @GetMapping("findById") 34 | public Order findById(Long id){ 35 | return orderService.findById(id); 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /springboot-learn-mongodb/src/main/java/com/plf/learn/mongodb/controller/CommentController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mongodb.controller; 2 | 3 | import com.plf.learn.mongodb.bean.Comment; 4 | import com.plf.learn.mongodb.service.CommentService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import java.time.LocalDateTime; 11 | 12 | /** 13 | * @author Panlf 14 | * @date 2020/3/2 15 | */ 16 | @RestController 17 | public class CommentController { 18 | 19 | @Autowired 20 | private CommentService commentService; 21 | 22 | @GetMapping("/save") 23 | public String saveComment(Comment comment){ 24 | comment.setCreatedatetime(LocalDateTime.now()); 25 | commentService.saveComment(comment); 26 | return "success"; 27 | } 28 | 29 | @GetMapping("/page") 30 | public Page findCommentListByParentid(String parentid, int pageNumber, int pageSize){ 31 | return commentService.findCommentListByParentid(parentid,pageNumber-1,pageSize); 32 | } 33 | 34 | @GetMapping("/incrlikenum") 35 | public Comment incrLikenum(String id){ 36 | return commentService.updateCommentLikenum(id); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/config/CuratorConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock.config; 2 | 3 | import org.apache.curator.framework.CuratorFramework; 4 | import org.apache.curator.framework.CuratorFrameworkFactory; 5 | import org.apache.curator.retry.RetryNTimes; 6 | import org.springframework.beans.factory.annotation.Value; 7 | import org.springframework.context.annotation.Bean; 8 | import org.springframework.context.annotation.Configuration; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/5/21 13 | */ 14 | @Configuration 15 | public class CuratorConfig { 16 | @Value("${curator.retryCount}") 17 | private int retryCount; 18 | 19 | @Value("${curator.elapsedTimeMs}") 20 | private int elapsedTimeMs; 21 | 22 | @Value("${curator.connectString}") 23 | private String connectString; 24 | 25 | @Value("${curator.sessionTimeoutMs}") 26 | private int sessionTimeoutMs; 27 | 28 | @Value("${curator.connectionTimeoutMs}") 29 | private int connectionTimeoutMs; 30 | 31 | @Bean(initMethod = "start") 32 | public CuratorFramework curatorFramework() { 33 | return CuratorFrameworkFactory.newClient( 34 | connectString, 35 | sessionTimeoutMs, 36 | connectionTimeoutMs, 37 | new RetryNTimes(retryCount, elapsedTimeMs)); 38 | } 39 | } -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/java/com/plf/learn/elastic/config/ElasticJobRegistryCenterConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elastic.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | 6 | import com.dangdang.ddframe.job.reg.base.CoordinatorRegistryCenter; 7 | import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperConfiguration; 8 | import com.dangdang.ddframe.job.reg.zookeeper.ZookeeperRegistryCenter; 9 | 10 | @Configuration 11 | public class ElasticJobRegistryCenterConfig { 12 | 13 | //zookeeper端口 14 | private static final int ZOOKEEPER_PORT = 2181; 15 | //zookeeper链接 16 | private static final String ZOOKEEPER_CONNECTION_STRING="localhost:"+ZOOKEEPER_PORT; 17 | //定时任务命名空间 18 | private static final String JOB_NAMESPACE="elastic-job-example-java"; 19 | 20 | 21 | //zk配置及创建注册中心 22 | @Bean(initMethod="init") 23 | private static CoordinatorRegistryCenter setUpRegitryCenter() { 24 | //zk配置 25 | ZookeeperConfiguration zookeeperConfiguration=new ZookeeperConfiguration(ZOOKEEPER_CONNECTION_STRING,JOB_NAMESPACE); 26 | //减少zk超时时间 27 | zookeeperConfiguration.setBaseSleepTimeMilliseconds(100); 28 | 29 | //创建注册中心 30 | CoordinatorRegistryCenter zookeeperRegistryCenter = new ZookeeperRegistryCenter(zookeeperConfiguration); 31 | 32 | return zookeeperRegistryCenter; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/interceptor/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread.interceptor; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 6 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 8 | 9 | @Configuration 10 | public class WebMvcConfig extends WebMvcConfigurationSupport { 11 | 12 | @Autowired 13 | private AuthActionInterceptor authActionInterceptor; 14 | 15 | @Autowired 16 | private AuthUserInterceptor authUserInterceptor; 17 | 18 | @Override 19 | public void addInterceptors(InterceptorRegistry registry) { 20 | registry.addInterceptor(authUserInterceptor).excludePathPatterns("/static/**").addPathPatterns("/**"); 21 | registry.addInterceptor(authActionInterceptor).addPathPatterns("/user/index"); 22 | super.addInterceptors(registry); 23 | } 24 | 25 | /** 26 | * 放行静态资源 27 | * @param registry 28 | */ 29 | @Override 30 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 31 | registry.addResourceHandler("/**").addResourceLocations("classpath:/static/"); 32 | super.addResourceHandlers(registry); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/controller/LogController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.controller; 2 | 3 | import java.util.Date; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 10 | import com.plf.learn.mybatisplus.dto.LogDto; 11 | import com.plf.learn.mybatisplus.entity.Log; 12 | import com.plf.learn.mybatisplus.service.LogService; 13 | 14 | @RestController 15 | @RequestMapping("/log") 16 | public class LogController { 17 | 18 | @Autowired 19 | private LogService logService; 20 | 21 | @RequestMapping("/add") 22 | public String addLog(Log log){ 23 | logService.insertLog(log); 24 | return "success"; 25 | } 26 | 27 | @RequestMapping("/delete") 28 | public String deleteLog(Integer id){ 29 | logService.deleteLog(id); 30 | return "success"; 31 | } 32 | 33 | @RequestMapping("/listPage") 34 | public Page listPageLog(String starttime){ 35 | return logService.getPageLog(new Page(1,2),starttime); 36 | } 37 | 38 | @RequestMapping("/listLogName") 39 | public Page listLogAndName(String username){ 40 | return logService.getLogAndName(new Page(1,2),username); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/test/BuyTest.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock.test; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.junit.Test; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | 8 | /** 9 | * 测试并发 10 | * @author Panlf 11 | * @date 2019/5/20 12 | */ 13 | @Slf4j 14 | public class BuyTest { 15 | 16 | private RestTemplate restTemplate = new RestTemplate(); 17 | 18 | private String url = "http://localhost:8004/lock/buyZookeeper"; 19 | 20 | @Test 21 | public void ticketTest() { 22 | Buy tr = new Buy(); 23 | Thread t1 = new Thread(tr, "A"); 24 | Thread t2 = new Thread(tr, "B"); 25 | Thread t3 = new Thread(tr, "C"); 26 | Thread t4 = new Thread(tr, "D"); 27 | t1.start(); 28 | t2.start(); 29 | t3.start(); 30 | t4.start(); 31 | try { 32 | Thread.currentThread().join(); 33 | } catch (InterruptedException e) { 34 | e.printStackTrace(); 35 | } 36 | } 37 | 38 | public class Buy implements Runnable{ 39 | @Override 40 | public void run() { 41 | while(true){ 42 | Integer num = restTemplate.getForObject(url,Integer.class); 43 | if(num<=0){ 44 | break; 45 | } 46 | } 47 | } 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/java/com/plf/learn/websocket/config/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.websocket.config; 2 | 3 | import org.springframework.context.annotation.Configuration; 4 | import org.springframework.messaging.simp.config.MessageBrokerRegistry; 5 | import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; 6 | import org.springframework.web.socket.config.annotation.StompEndpointRegistry; 7 | import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; 8 | 9 | /** 10 | * @EnableWebSocketMessageBroker 11 | * 用于开启使用STOMP协议来传输基于代理(MessageBroker)的消息 12 | * @author Panlf 13 | * @date 2020/3/20 14 | */ 15 | @Configuration 16 | @EnableWebSocketMessageBroker 17 | public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { 18 | 19 | @Override 20 | public void configureMessageBroker(MessageBrokerRegistry registry) { 21 | //设置广播节点 22 | registry.enableStompBrokerRelay("/topic", "/user"); 23 | //定义一对一推送的前缀 24 | registry.setUserDestinationPrefix("/user/"); 25 | //定义websocket前缀 26 | registry.setApplicationDestinationPrefixes("/app"); 27 | } 28 | 29 | @Override 30 | public void registerStompEndpoints(StompEndpointRegistry registry) { 31 | //注册一个Stomp的节点(endpoint),并指定使用SockJS协议 32 | registry.addEndpoint("/ws").setAllowedOrigins("*").withSockJS(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /springboot-learn-mybatis-plus/src/main/java/com/plf/learn/mybatisplus/service/impl/LogServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mybatisplus.service.impl; 2 | 3 | import java.util.List; 4 | 5 | import com.plf.learn.mybatisplus.dto.LogDto; 6 | import com.plf.learn.mybatisplus.entity.Log; 7 | import com.plf.learn.mybatisplus.mapper.LogMapper; 8 | import com.plf.learn.mybatisplus.service.LogService; 9 | import org.springframework.stereotype.Service; 10 | 11 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 12 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 13 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 14 | 15 | @Service 16 | public class LogServiceImpl extends ServiceImpl implements LogService { 17 | 18 | @Override 19 | public void insertLog(Log log) { 20 | baseMapper.insert(log); 21 | } 22 | 23 | @Override 24 | public void deleteLog(Integer id) { 25 | baseMapper.deleteById(id); 26 | } 27 | 28 | @Override 29 | public Page getPageLog(Page page, String starttime) { 30 | return (Page) baseMapper.selectPage(page, new QueryWrapper().select("content,createtime,user_id").gt("createtime",starttime)); 31 | } 32 | 33 | @Override 34 | public Page getLogAndName(Page page, String username) { 35 | List records = baseMapper.getLogAndName(page,username); 36 | page.setRecords(records); 37 | return page; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /springboot-learn-sharding-jdbc/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | mybatis: 2 | type-aliases-package: com.plf.learn.sharding.bean 3 | configuration: 4 | map-underscore-to-camel-case: true 5 | 6 | spring: 7 | shardingsphere: 8 | datasource: 9 | names: ds0,ds1 10 | ds0: 11 | driver-class-name: com.mysql.cj.jdbc.Driver 12 | jdbc-url: jdbc:mysql://localhost:3306/ds0?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 13 | username: root 14 | password: root 15 | ds1: 16 | driver-class-name: com.mysql.cj.jdbc.Driver 17 | jdbc-url: jdbc:mysql://localhost:3306/ds1?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=GMT%2B8 18 | username: root 19 | password: root 20 | sharding: 21 | default-database-strategy: 22 | inline: 23 | sharding-column: user_id 24 | algorithm-expression: ds$->{user_id % 2} 25 | tables: 26 | t_order: 27 | actual-data-nodes: ds$->{0..1}.t_order_$->{0..1} 28 | table-strategy: 29 | inline: 30 | sharding-column: order_id 31 | algorithm-expression: t_order_$->{order_id % 2} 32 | key-generator: 33 | column: order_id 34 | type: SNOWFLAKE 35 | props: 36 | worker: 37 | id: 123 38 | sql: 39 | show: true -------------------------------------------------------------------------------- /springboot-learn-document/src/main/java/com/plf/learn/document/container/DocumentContext.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.document.container; 2 | 3 | import java.util.Map; 4 | import java.util.concurrent.ConcurrentHashMap; 5 | 6 | import com.plf.learn.document.utils.interfaces.OperateDocument; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.stereotype.Component; 11 | 12 | 13 | @Component 14 | public class DocumentContext { 15 | 16 | private static final Logger logger = LoggerFactory.getLogger(DocumentContext.class); 17 | 18 | @Autowired 19 | private final Map documentMap = new ConcurrentHashMap<>(); 20 | 21 | /** 22 | * 根据key名为beanName,value为实例类装入到documentMap 23 | * @param documentMap 24 | */ 25 | public DocumentContext(Map documentMap) { 26 | this.documentMap.clear(); 27 | documentMap.forEach((k, v)-> this.documentMap.put(k, v)); 28 | logger.info("策略模式装入documentMap:{}",documentMap); 29 | } 30 | 31 | public String readDocument(String beanName,String path){ 32 | return this.getResource(beanName).readDocument(path); 33 | } 34 | 35 | public boolean writeDocument(String beanName,String path,String content){ 36 | return this.getResource(beanName).writeDocument(path, content); 37 | } 38 | 39 | public OperateDocument getResource(String beanName) { 40 | return documentMap.get(beanName); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/handler/MyAuthenticationFailtureHandler.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.handler; 2 | 3 | import java.io.IOException; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import javax.servlet.ServletException; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import org.springframework.security.core.AuthenticationException; 12 | import org.springframework.security.web.authentication.AuthenticationFailureHandler; 13 | 14 | import com.fasterxml.jackson.databind.ObjectMapper; 15 | import org.springframework.stereotype.Component; 16 | 17 | /** 18 | * 自定义登录失败的逻辑 19 | * @author Panlf 20 | * @date 2020/3/13 21 | */ 22 | @Component 23 | public class MyAuthenticationFailtureHandler implements AuthenticationFailureHandler { 24 | 25 | private ObjectMapper objectMapper = new ObjectMapper(); 26 | 27 | 28 | /** 29 | * 返回JSON数据,配合ajax使用,直接弹框用户体验更好 30 | */ 31 | @Override 32 | public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, 33 | AuthenticationException exception) throws IOException, ServletException { 34 | //返回字符串给前端 35 | Map map = new HashMap<>(); 36 | map.put("success",false); 37 | map.put("errorMsg",exception.getMessage()); 38 | String json = objectMapper.writeValueAsString(map); 39 | 40 | response.setContentType("text/json;charset=utf-8"); 41 | response.getWriter().write(json); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/java/com/plf/learn/elasticsearch/controller/BookController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elasticsearch.controller; 2 | 3 | import com.plf.learn.elasticsearch.bean.Book; 4 | import com.plf.learn.elasticsearch.service.BookService; 5 | import com.plf.learn.elasticsearch.service.IndexService; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import java.util.List; 12 | 13 | /** 14 | * @author Panlf 15 | * @date 2019/12/27 16 | */ 17 | @RestController 18 | public class BookController { 19 | 20 | @Autowired 21 | private BookService bookService; 22 | 23 | @Autowired 24 | private IndexService indexService; 25 | 26 | 27 | @GetMapping("/save") 28 | public String save(Book book){ 29 | bookService.saveBook(book); 30 | return "success"; 31 | } 32 | 33 | @GetMapping("/delete/{id}") 34 | public String delete(@PathVariable Long id){ 35 | bookService.deleteBook(id); 36 | return "success"; 37 | } 38 | 39 | @GetMapping("/get/{name}") 40 | public List findByName(@PathVariable String name){ 41 | return bookService.findBookByName(name); 42 | } 43 | 44 | @GetMapping("/create") 45 | public String createIndex(){ 46 | indexService.createIndex(Book.class); 47 | return "success"; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /springboot-learn-neo4j/src/test/java/com/plf/learn/neo4j/Neo4jTest.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.neo4j; 2 | 3 | import com.plf.learn.neo4j.dao.MinFamilyRepository; 4 | import com.plf.learn.neo4j.entity.MinFamily; 5 | import org.junit.jupiter.api.Test; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | 8 | import javax.annotation.Resource; 9 | 10 | /** 11 | * @author panlf 12 | * @date 2021/12/25 13 | */ 14 | @SpringBootTest(classes = Neo4jApplication.class) 15 | public class Neo4jTest { 16 | 17 | @Resource 18 | private MinFamilyRepository minFamilyRepository; 19 | 20 | @Test 21 | public void testCreate(){ 22 | MinFamily minFamily = new MinFamily(); 23 | minFamily.setName("赵素敏"); 24 | minFamilyRepository.save(minFamily); 25 | } 26 | 27 | @Test 28 | public void testDelete(){ 29 | minFamilyRepository.deleteById(10L); 30 | } 31 | 32 | @Test 33 | public void testUpdate(){ 34 | MinFamily minFamily = new MinFamily(); 35 | minFamily.setId(5L); 36 | minFamily.setName("金家骏"); 37 | minFamilyRepository.save(minFamily); 38 | } 39 | 40 | @Test 41 | public void testCreateRelation(){ 42 | minFamilyRepository.createRelation("陈天福","喜欢","赵素敏"); 43 | } 44 | @Test 45 | public void findAll(){ 46 | System.out.println( minFamilyRepository.findAll()); 47 | } 48 | 49 | @Test 50 | public void getByName(){ 51 | System.out.println( minFamilyRepository.findByName("陈天福","喜欢")); 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/utils/RedisUtils.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.utils; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.data.redis.core.StringRedisTemplate; 5 | import org.springframework.stereotype.Component; 6 | 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/12/26 12 | */ 13 | @Component 14 | public class RedisUtils { 15 | @Autowired 16 | private StringRedisTemplate stringRedisTemplate; 17 | 18 | /** 19 | * 往Redis中存储字符串数据 20 | * @param key 键 21 | * @param value 值 22 | * @param time 过期时间,单位秒 23 | */ 24 | public void set(String key,String value,Integer time){ 25 | stringRedisTemplate.opsForValue().set(key,value,time, TimeUnit.SECONDS); 26 | } 27 | 28 | /** 29 | * 根据key从Redis获取值 30 | * @param key 键 31 | * @return 32 | */ 33 | public String get(String key){ 34 | return stringRedisTemplate.opsForValue().get(key); 35 | } 36 | 37 | /** 38 | * 判断key是否存在 39 | * @param key 40 | * @return 41 | */ 42 | public boolean exits(String key){ 43 | return stringRedisTemplate.hasKey(key); 44 | } 45 | 46 | /** 47 | * 删除key 48 | * @param key 49 | * @return 删除失败返回false,其他返回true 50 | */ 51 | public boolean remove(String key){ 52 | if(exits(key)){ 53 | return stringRedisTemplate.delete(key); 54 | } 55 | return true; 56 | } 57 | } 58 | 59 | -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/interceptor/AuthActionInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread.interceptor; 2 | 3 | import com.plf.learn.thread.entity.User; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.lang.Nullable; 6 | import org.springframework.stereotype.Component; 7 | import org.springframework.web.servlet.HandlerInterceptor; 8 | import org.springframework.web.servlet.ModelAndView; 9 | 10 | import javax.servlet.http.HttpServletRequest; 11 | import javax.servlet.http.HttpServletResponse; 12 | 13 | /** 14 | * 方法级验证 15 | * @author Panlf 16 | * @date 2020/3/20 17 | */ 18 | @Component 19 | @Slf4j 20 | public class AuthActionInterceptor implements HandlerInterceptor{ 21 | 22 | @Override 23 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 24 | log.info("start AuthActionInterceptor"); 25 | User user = UserContextHolder.getUser(); 26 | //相当于未登录 27 | if (user == null) { 28 | //返回登录 29 | response.sendRedirect("/thread/user/sign"); 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | @Override 36 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { 37 | 38 | } 39 | 40 | @Override 41 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /springboot-learn-api-limiter/src/test/java/com/plf/learn/httpclient/HttpTest.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.httpclient; 2 | 3 | import org.junit.Test; 4 | 5 | import java.io.IOException; 6 | import java.net.URI; 7 | import java.net.http.HttpClient; 8 | import java.net.http.HttpRequest; 9 | import java.net.http.HttpResponse; 10 | import java.util.concurrent.ExecutorService; 11 | import java.util.concurrent.Executors; 12 | 13 | /** 14 | * @author panlf 15 | * @date 2021/9/1 16 | */ 17 | public class HttpTest { 18 | 19 | HttpClient client = HttpClient.newHttpClient(); 20 | HttpRequest request = HttpRequest.newBuilder(URI.create("http://localhost:8080/api/limiter/hello")) 21 | .build(); 22 | HttpResponse.BodyHandler responseBodyHandler = HttpResponse.BodyHandlers.ofString(); 23 | 24 | 25 | @Test 26 | public void test(){ 27 | ExecutorService executorService = Executors.newFixedThreadPool(5); 28 | 29 | for(int i=0;i<5;i++) { 30 | executorService.submit(()->{ 31 | sendHttp(); 32 | }); 33 | } 34 | 35 | 36 | try { 37 | Thread.sleep(20000); 38 | } catch (InterruptedException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | public void sendHttp(){ 44 | try { 45 | HttpResponse response = client.send(request,responseBodyHandler); 46 | 47 | String body = response.body(); 48 | System.out.println(body); 49 | } catch (InterruptedException | IOException e) { 50 | e.printStackTrace(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /springboot-learn-kafka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8011 3 | servlet: 4 | context-path: /kafka 5 | 6 | spring: 7 | kafka: 8 | # kafka服务器地址 9 | bootstrap-servers: http://localhost:9020,http://localhost:9021,http://localhost:9022 10 | producer: 11 | # 发生错误后,消息重发的次数。 12 | retries: 0 13 | #当有多个消息需要被发送到同一个分区时,生产者会把它们放在同一个批次里。该参数指定了一个批次可以使用的内存大小,按照字节数计算。 14 | batch-size: 16384 15 | # 设置生产者内存缓冲区的大小。 16 | buffer-memory: 33554432 17 | # key/value的序列化 18 | key-serializer: org.apache.kafka.common.serialization.StringSerializer 19 | value-serializer: org.apache.kafka.common.serialization.StringSerializer 20 | # acks=0:生产者在成功写入消息之前不会等待任何来自服务器的响应。 21 | # acks=1:只要集群的首领节点收到消息,生产者就会收到一个来自服务器成功响应。 22 | # acks=all:只有当所有参与复制的节点全部收到消息时,生产者才会收到一个来自服务器的成功响应。 23 | acks: 1 24 | consumer: 25 | # 指定默认组名 26 | group-id: consumer-group 27 | # earliest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,从头开始消费 28 | # latest:当各分区下有已提交的offset时,从提交的offset开始消费;无提交的offset时,消费新产生的该分区下的数据 29 | # none:topic各分区都存在已提交的offset时,从offset后开始消费;只要有一个分区不存在已提交的offset,则抛出异常 30 | auto-offset-reset: earliest 31 | # 是否自动提交偏移量,默认值是true,为了避免出现重复数据和数据丢失,可以把它设置为false,然后手动提交偏移量 32 | enable-auto-commit: true 33 | # 自动提交的时间间隔 34 | auto-commit-interval: 20000 35 | # key/value的反序列化 36 | key-deserializer: org.apache.kafka.common.serialization.StringDeserializer 37 | value-deserializer: org.apache.kafka.common.serialization.StringDeserializer 38 | listener: 39 | # 设置消费线程数 40 | concurrency: 3 41 | 42 | 43 | -------------------------------------------------------------------------------- /springboot-learn-websocket/src/main/java/com/plf/learn/websocket/controller/WebSocketController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.websocket.controller; 2 | 3 | import com.plf.learn.websocket.entity.RequestMessage; 4 | import com.plf.learn.websocket.entity.ResponseMessage; 5 | import com.plf.learn.websocket.service.WebSocketService; 6 | import lombok.extern.slf4j.Slf4j; 7 | import org.assertj.core.util.Lists; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.messaging.handler.annotation.MessageMapping; 10 | import org.springframework.messaging.handler.annotation.SendTo; 11 | import org.springframework.stereotype.Controller; 12 | import org.springframework.web.bind.annotation.GetMapping; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * @author Panlf 18 | * @date 2020/3/20 19 | */ 20 | @Controller 21 | @Slf4j 22 | public class WebSocketController { 23 | @Autowired 24 | private WebSocketService webSocketService; 25 | 26 | @MessageMapping("/welcome")//@MessageMapping和@RequestMapping功能类似,用于设置URL映射地址,浏览器向服务器发起请求,需要通过该地址。 27 | @SendTo("/topic/welcome")//如果服务器接受到了消息,就会对订阅了@SendTo括号中的地址传送消息。 28 | public ResponseMessage say(RequestMessage message) throws Exception { 29 | log.info("获取到信息 : {}",message.getName()); 30 | List users = Lists.newArrayList(); 31 | users.add("d892bf12bf7d11e793b69c5c8e6f60fb");//此处写死只是为了方便测试,此值需要对应页面中订阅个人消息的userId 32 | webSocketService.send2Users(users, new ResponseMessage("admin hello")); 33 | 34 | return new ResponseMessage("Welcome, " + message.getName() + "!"); 35 | } 36 | 37 | @GetMapping("index") 38 | public String toHtml(){ 39 | return "ws"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/configuration/WebConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.configuration; 2 | 3 | import com.plf.learn.redis.annotations.ApiIdempotent; 4 | import com.plf.learn.redis.interceptor.ApiIdempotentInterceptor; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | import org.springframework.web.servlet.config.annotation.CorsRegistry; 9 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 10 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; 11 | 12 | /** 13 | * @author Panlf 14 | * @date 2019/12/26 15 | */ 16 | @Configuration 17 | public class WebConfiguration implements WebMvcConfigurer { 18 | 19 | @Autowired 20 | private ApiIdempotentInterceptor apiIdempotentInterceptor; 21 | 22 | @Bean 23 | public WebMvcConfigurer corsConfigurer() { 24 | return new WebMvcConfigurer() { 25 | @Override 26 | public void addCorsMappings(CorsRegistry registry) { 27 | registry.addMapping("/**") 28 | .allowedOrigins("*", "null") 29 | .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") 30 | .maxAge(3600) 31 | .allowCredentials(true); 32 | } 33 | }; 34 | } 35 | 36 | @Override 37 | public void addInterceptors(InterceptorRegistry registry) { 38 | // 接口幂等性拦截器 39 | registry.addInterceptor(apiIdempotentInterceptor); 40 | WebMvcConfigurer.super.addInterceptors(registry); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /springboot-learn-threadlocal/src/main/java/com/plf/learn/thread/controller/ThreadController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.thread.controller; 2 | 3 | import com.plf.learn.thread.base.Message; 4 | import com.plf.learn.thread.entity.User; 5 | import org.springframework.util.DigestUtils; 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.servlet.http.HttpSession; 11 | import java.util.UUID; 12 | 13 | /** 14 | * @author Panlf 15 | * @date 2020/3/20 16 | */ 17 | @RestController 18 | @RequestMapping("user") 19 | public class ThreadController { 20 | 21 | 22 | @GetMapping("sign") 23 | public Message sign(){ 24 | return Message.fail("讲道理你需要登录啊!访问/thread/user/login",null); 25 | } 26 | 27 | @GetMapping("login") 28 | public Message login(String username, String password, HttpSession httpSession){ 29 | User user = new User(UUID.randomUUID().toString(), 30 | username, 31 | DigestUtils.md5DigestAsHex(password.getBytes())); 32 | httpSession.setAttribute("user",user); 33 | return Message.success("登录成功!可访问/thread/user/index",null); 34 | } 35 | 36 | @GetMapping("/index") 37 | public Message index(){ 38 | return Message.success("主页内容来了!",null); 39 | } 40 | 41 | @GetMapping("/error") 42 | public Message error(){ 43 | return Message.fail("尴尬!出错了!",null); 44 | } 45 | 46 | @GetMapping("loginout") 47 | public Message loginout(HttpSession httpSession){ 48 | httpSession.invalidate(); 49 | return Message.success("登出",null); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /springboot-learn-mongodb/src/main/java/com/plf/learn/mongodb/service/CommentService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mongodb.service; 2 | 3 | import com.plf.learn.mongodb.bean.Comment; 4 | import com.plf.learn.mongodb.repository.CommentRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.data.domain.Page; 7 | import org.springframework.data.domain.PageRequest; 8 | import org.springframework.data.mongodb.core.MongoTemplate; 9 | import org.springframework.data.mongodb.core.query.Criteria; 10 | import org.springframework.data.mongodb.core.query.Query; 11 | import org.springframework.data.mongodb.core.query.Update; 12 | import org.springframework.stereotype.Service; 13 | 14 | /** 15 | * @author Panlf 16 | * @date 2020/3/2 17 | */ 18 | @Service 19 | public class CommentService { 20 | 21 | @Autowired 22 | private CommentRepository commentRepository; 23 | 24 | @Autowired 25 | private MongoTemplate mongoTemplate; 26 | 27 | public void saveComment(Comment comment){ 28 | commentRepository.save(comment); 29 | } 30 | 31 | public Page findCommentListByParentid(String parentid,int pageNumber,int pageSize){ 32 | return commentRepository.findByParentid(parentid, PageRequest.of(pageNumber,pageSize)); 33 | } 34 | 35 | /** 36 | * 点赞数加1 37 | * @param id 38 | */ 39 | public Comment updateCommentLikenum(String id){ 40 | //查询条件 41 | Query query = Query.query(Criteria.where("_id").is(id)); 42 | //更新条件 43 | Update update = new Update(); 44 | update.inc("likenum"); 45 | mongoTemplate.updateFirst(query,update,Comment.class); 46 | 47 | return commentRepository.findById(id).get(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/java/com/plf/learn/caffeine/service/UserInfoService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.caffeine.service; 2 | 3 | import com.plf.learn.caffeine.dao.UserInfoDao; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.cache.annotation.CacheConfig; 6 | import org.springframework.cache.annotation.CacheEvict; 7 | import org.springframework.cache.annotation.CachePut; 8 | import org.springframework.cache.annotation.Cacheable; 9 | import org.springframework.stereotype.Service; 10 | 11 | import javax.annotation.Resource; 12 | 13 | /** 14 | * @author panlf 15 | * @date 2021/8/16 16 | */ 17 | @Service 18 | @CacheConfig(cacheNames = "userInfo") 19 | @Slf4j 20 | public class UserInfoService { 21 | 22 | @Resource 23 | UserInfoDao userInfoDao; 24 | 25 | @CachePut(key = "#id",value = "userInfo") 26 | public String addUserInfo(Integer id,String userInfo){ 27 | log.info("UserInfoService.addUserInfo"); 28 | userInfoDao.addUserInfo(id,userInfo); 29 | return userInfo; 30 | } 31 | 32 | @Cacheable(key = "#id",value = "userInfo") 33 | public String getUserById(Integer id){ 34 | log.info("UserInfoService.getUserById"); 35 | String userInfo = userInfoDao.getUserInfo(id); 36 | return userInfo; 37 | } 38 | 39 | @CachePut(key = "#id",value = "userInfo") 40 | public String updateUserInfo(Integer id,String userInfo){ 41 | log.info("UserInfoService.updateUserInfo"); 42 | userInfoDao.updateUserInfo(id,userInfo); 43 | return userInfo; 44 | } 45 | 46 | @CacheEvict(key = "#id") 47 | public void deleteUserById(Integer id) { 48 | log.info("UserInfoService.deleteById"); 49 | userInfoDao.deleteUserInfo(id); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /springboot-learn-security/src/main/java/com/plf/learn/security/service/MyUserDetailService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.security.service; 2 | 3 | import com.plf.learn.security.entity.Permission; 4 | import com.plf.learn.security.entity.User; 5 | import com.plf.learn.security.mapper.UserMapper; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.security.core.GrantedAuthority; 8 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 9 | import org.springframework.security.core.userdetails.UserDetails; 10 | import org.springframework.security.core.userdetails.UserDetailsService; 11 | import org.springframework.security.core.userdetails.UsernameNotFoundException; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | /** 17 | * @author Panlf 18 | * @date 2020/3/13 19 | */ 20 | public class MyUserDetailService implements UserDetailsService { 21 | 22 | @Autowired 23 | private UserMapper userMapper; 24 | 25 | @Override 26 | public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 27 | User user = userMapper.findByUsername(username); 28 | 29 | //配置权限或者角色 30 | if (user != null) { 31 | List permList = userMapper.findPermissionByUsername(username); 32 | List authorities = new ArrayList<>(); 33 | 34 | for (Permission perm : permList) { 35 | GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(perm.getPermTag()); 36 | authorities.add(grantedAuthority); 37 | } 38 | 39 | user.setAuthorities(authorities); 40 | } 41 | //List authoritys = new ArrayList<>(); 42 | //authoritys.add(new SimpleGrantedAuthority("PRODUCT_ADD")); 43 | return user; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /springboot-learn-custom-event/src/main/java/com/plf/learn/custom/event/configuration/ThreadPool.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.custom.event.configuration; 2 | 3 | import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | import org.springframework.lang.Nullable; 7 | import org.springframework.scheduling.annotation.AsyncConfigurer; 8 | import org.springframework.scheduling.annotation.EnableAsync; 9 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 10 | 11 | import java.util.concurrent.Executor; 12 | import java.util.concurrent.ThreadPoolExecutor; 13 | 14 | /** 15 | * @author Panlf 16 | * @date 2019/4/19 17 | */ 18 | @EnableAsync 19 | @Configuration 20 | public class ThreadPool implements AsyncConfigurer { 21 | @Nullable 22 | @Override 23 | @Bean("taskExecutor") 24 | public Executor getAsyncExecutor() { 25 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 26 | // 线程池创建时候初始化的线程数 27 | executor.setCorePoolSize(10); 28 | // 线程池最大的线程数,只有在缓冲队列满了之后才会申请超过核心线程数的线程 29 | executor.setMaxPoolSize(20); 30 | // 用来缓冲执行任务的队列 31 | executor.setQueueCapacity(200); 32 | // 允许线程的空闲时间60秒 33 | executor.setKeepAliveSeconds(60); 34 | // 线程池名的前缀 35 | executor.setThreadNamePrefix("taskExecutor-"); 36 | // 线程池对拒绝任务的处理策略 37 | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); 38 | executor.initialize(); 39 | return executor; 40 | } 41 | 42 | @Nullable 43 | @Override 44 | public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { 45 | return null; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /springboot-learn-elasticsearch/src/main/java/com/plf/learn/elasticsearch/service/BookService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elasticsearch.service; 2 | 3 | import com.plf.learn.elasticsearch.bean.Book; 4 | import com.plf.learn.elasticsearch.repository.BookRepository; 5 | import org.elasticsearch.index.query.QueryBuilders; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.data.domain.Page; 8 | import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; 9 | import org.springframework.stereotype.Service; 10 | 11 | import java.util.List; 12 | import java.util.Optional; 13 | 14 | /** 15 | * @author Panlf 16 | * @date 2019/12/27 17 | */ 18 | @Service 19 | public class BookService { 20 | 21 | @Autowired 22 | private BookRepository bookRepository; 23 | 24 | public void saveBook(Book book){ 25 | bookRepository.save(book); 26 | } 27 | 28 | public void deleteBook(Long id){ 29 | bookRepository.deleteById(id); 30 | } 31 | 32 | public Book findById(Long id){ 33 | Optional book=bookRepository.findById(id); 34 | return book.get(); 35 | } 36 | 37 | public List findBookByName(String name){ 38 | /* 39 | matchQuery:词条匹配,先分词然后在调用termQuery进行匹配 40 | TermQuery:词条匹配,不分词 41 | wildcardQuery:通配符匹配 42 | fuzzyQuery:模糊匹配 43 | rangeQuery:范围匹配 44 | booleanQuery:布尔查询 45 | */ 46 | // 构建查询条件 47 | NativeSearchQueryBuilder queryBuilder = new NativeSearchQueryBuilder(); 48 | // 添加基本分词查询 49 | queryBuilder.withQuery(QueryBuilders.matchQuery("name",name)); 50 | // 搜索,获取结果 51 | Page bookPage = bookRepository.search(queryBuilder.build()); 52 | 53 | return bookPage.toList(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/redis/RedissonDistributionLock.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock.redis; 2 | 3 | import org.redisson.api.RLock; 4 | import org.redisson.api.RedissonClient; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.annotation.Resource; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * @author Panlf 12 | * @date 2019/5/20 13 | */ 14 | @Component 15 | public class RedissonDistributionLock { 16 | 17 | @Resource 18 | private RedissonClient redissonClient; 19 | 20 | public RLock lock(String lockKey) { 21 | RLock lock = redissonClient.getLock(lockKey); 22 | lock.lock(); 23 | return lock; 24 | } 25 | 26 | public RLock lock(String lockKey, int leaseTime) { 27 | RLock lock = redissonClient.getLock(lockKey); 28 | lock.lock(leaseTime, TimeUnit.SECONDS); 29 | return lock; 30 | } 31 | 32 | public RLock lock(String lockKey, TimeUnit unit , int timeout) { 33 | RLock lock = redissonClient.getLock(lockKey); 34 | lock.lock(timeout, unit); 35 | return lock; 36 | } 37 | 38 | public boolean tryLock(String lockKey, TimeUnit unit, int waitTime, int leaseTime) { 39 | RLock lock = redissonClient.getLock(lockKey); 40 | try { 41 | return lock.tryLock(waitTime, leaseTime, unit); 42 | } catch (InterruptedException e) { 43 | return false; 44 | } 45 | } 46 | 47 | public void unlock(String lockKey) { 48 | RLock lock = redissonClient.getLock(lockKey); 49 | lock.unlock(); 50 | } 51 | 52 | public void unlock(RLock lock) { 53 | lock.unlock(); 54 | } 55 | public void setRedissonClient(RedissonClient redissonClient) { 56 | this.redissonClient = redissonClient; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/java/com/plf/learn/jwt/filter/JwtFilter.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jwt.filter; 2 | 3 | import com.plf.learn.jwt.utils.JwtUtils; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.stereotype.Component; 6 | 7 | import javax.servlet.*; 8 | import javax.servlet.annotation.WebFilter; 9 | import javax.servlet.http.HttpServletRequest; 10 | import javax.servlet.http.HttpServletResponse; 11 | import java.io.IOException; 12 | import java.util.Arrays; 13 | import java.util.Collections; 14 | import java.util.List; 15 | 16 | /** 17 | * 需要授权的访问地址都可以移到这里来统一处理 18 | * @author Panlf 19 | * @date 2019/5/14 20 | */ 21 | @WebFilter("/*") 22 | @Component 23 | @Slf4j 24 | public class JwtFilter implements Filter{ 25 | 26 | /** 27 | * 28 | * 需要验证的名单 29 | */ 30 | private static final List NEED_AUTH_LIST = Arrays.asList("/hello"); 31 | 32 | private static final String JWT_HEADER_NAME = "Authorization"; 33 | 34 | @Override 35 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 36 | final HttpServletRequest httpServletRequest = (HttpServletRequest) request; 37 | final HttpServletResponse httpServletResponse = (HttpServletResponse) response; 38 | 39 | String token = httpServletRequest.getHeader(JWT_HEADER_NAME); 40 | String url = httpServletRequest.getRequestURI(); 41 | log.info("当前访问地址:{}",url); 42 | if(NEED_AUTH_LIST.contains(httpServletRequest.getRequestURI())){ 43 | log.info("进入验证名单"); 44 | } 45 | chain.doFilter(request, response); 46 | } 47 | 48 | @Override 49 | public void init(FilterConfig filterConfig) throws ServletException { 50 | 51 | } 52 | 53 | @Override 54 | public void destroy() { 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /springboot-learn-distributed-lock/src/main/java/com/plf/learn/lock/redis/RedisUtils.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.lock.redis; 2 | 3 | import org.springframework.data.redis.core.StringRedisTemplate; 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.annotation.Resource; 7 | import java.util.concurrent.TimeUnit; 8 | 9 | /** 10 | * @author Panlf 11 | * @date 2019/5/20 12 | */ 13 | @Component 14 | public class RedisUtils { 15 | @Resource 16 | public StringRedisTemplate stringRedisTemplate; 17 | 18 | /** 19 | * 往Redis中存储字符串数据 20 | * @param key 键 21 | * @param value 值 22 | * @param time 过期时间,单位秒 23 | */ 24 | public void insertStr(String key,String value,long time){ 25 | stringRedisTemplate.opsForValue().set(key,value,time, TimeUnit.SECONDS); 26 | } 27 | 28 | /** 29 | * 往Redis中存储字符串数据 无过期时间 30 | * @param key 31 | * @param value 32 | */ 33 | public void insertStr(String key,String value){ 34 | stringRedisTemplate.opsForValue().set(key,value); 35 | } 36 | 37 | /** 38 | * 往Redis中存储字符串数据,存在则不插入 39 | * @param key 键 40 | * @param value 值 41 | */ 42 | public void insertIfAbsent(String key,String value){ 43 | stringRedisTemplate.opsForValue().setIfAbsent(key,value); 44 | } 45 | 46 | /** 47 | * 往Redis中存储字符串数据,存在则不插入,设置过期时间 48 | * @param key 49 | * @param value 50 | * @param time 单位秒 51 | */ 52 | public void insertIfAbsent(String key,String value,long time){ 53 | stringRedisTemplate.opsForValue().setIfAbsent(key,value,time,TimeUnit.SECONDS); 54 | } 55 | 56 | 57 | /** 58 | * 根据key从Redis获取值 59 | * @param key 键 60 | * @return 61 | */ 62 | public String getStr(String key){ 63 | return stringRedisTemplate.opsForValue().get(key); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/java/com/plf/learn/caffeine/config/CaffeineConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.caffeine.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 | /** 13 | * @author panlf 14 | * @date 2021/8/16 15 | */ 16 | @Configuration 17 | @EnableCaching //开启缓存 18 | public class CaffeineConfig { 19 | 20 | //配置Caffeine缓存行为(例如到期,缓存大小限制等) 21 | public Caffeine caffeineConfig() { 22 | 23 | /* 24 | initialCapacity=[integer]: 初始的缓存空间大小 25 | maximumSize=[long]: 缓存的最大条数 26 | maximumWeight=[long]: 缓存的最大权重 27 | expireAfterAccess=[duration]: 最后一次写入或访问后经过固定时间过期 28 | expireAfterWrite=[duration]: 最后一次写入后经过固定时间过期 29 | refreshAfterWrite=[duration]: 创建缓存或者最近一次更新缓存后经过固定的时间间隔,刷新缓存 30 | recordStats:开发统计功能 31 | 32 | expireAfterWrite和expireAfterAccess同时存在时,以expireAfterWrite为准。 33 | maximumSize和maximumWeight不可以同时使用 34 | */ 35 | Caffeine caffeine = Caffeine.newBuilder() 36 | //最后一次写入后经过固定时间过期 37 | .expireAfterWrite(60, TimeUnit.MINUTES) 38 | //初始的缓存空间大小 39 | .initialCapacity(100) 40 | //缓存的最大条数 41 | .maximumSize(1000); 42 | return caffeine; 43 | } 44 | 45 | @Bean 46 | public CaffeineCacheManager caffeineCacheManager() { 47 | CaffeineCacheManager caffeineCacheManager = new CaffeineCacheManager(); 48 | caffeineCacheManager.setCaffeine(caffeineConfig()); 49 | return caffeineCacheManager; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8008 3 | servlet: 4 | context-path: /monitor 5 | 6 | # 数据库的配置 7 | spring: 8 | datasource: 9 | type: com.alibaba.druid.pool.DruidDataSource 10 | url: jdbc:postgresql://127.0.0.1:5432/springboot?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&characterEncoding=UTF-8 11 | driver-class-name: org.postgresql.Driver 12 | username: postgres 13 | password: 123456 14 | # Druid配置 15 | # 初始化大小,最小,最大 16 | druid: 17 | initialSize: 5 18 | minIdle: 5 19 | maxActive: 20 20 | # 配置获取连接等待超时的时间 21 | maxWait: 60000 22 | # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 23 | timeBetweenEvictionRunsMillis: 60000 24 | # 配置一个连接在池中最小生存的时间,单位是毫秒 25 | minEvictableIdleTimeMillis: 300000 26 | validationQuery: SELECT 1 27 | testWhileIdle: true 28 | testOnBorrow: false 29 | testOnReturn: false 30 | # 打开PSCache,并且指定每个连接上PSCache的大小 31 | poolPreparedStatements: true 32 | maxPoolPreparedStatementPerConnectionSize: 20 33 | # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 34 | filters: stat,wall,log4j 35 | # 通过connectProperties属性来打开mergeSql功能;慢SQL记录 36 | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 37 | # 合并多个DruidDataSource的监控数据 38 | #spring.datasource.useGlobalDataSourceStat=true 39 | 40 | 41 | # pageHelper的配置 42 | pagehelper: 43 | offsetAsPageNum: true 44 | rowBoundsWithCount: true 45 | pageSizeZero: true 46 | reasonable: false 47 | params: pageNum=pageHelperStart;pageSize=pageHelperRows; 48 | supportMethodsArguments: false 49 | helper-dialect: postgresql 50 | 51 | # mybatis配置 52 | # 实体类扫描 53 | mybatis: 54 | type-aliases-package: com.plf.learn.springbootmybatisdruid.bean 55 | # 配置映射文件位置 56 | mapper-locations: classpath:/mapper/*.xml 57 | # 开启驼峰匹配 58 | configuration.map-underscore-to-camel-case: true -------------------------------------------------------------------------------- /springboot-learn-druid-monitor/src/main/java/com/plf/learn/monitor/config/DruidConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.monitor.config; 2 | 3 | import org.springframework.boot.web.servlet.FilterRegistrationBean; 4 | import org.springframework.boot.web.servlet.ServletRegistrationBean; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | 8 | import com.alibaba.druid.support.http.StatViewServlet; 9 | import com.alibaba.druid.support.http.WebStatFilter; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/7/11 14 | */ 15 | @Configuration 16 | public class DruidConfiguration { 17 | @Bean 18 | public ServletRegistrationBean druidStatViewServlet() { 19 | ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(new StatViewServlet(), 20 | "/druid/*"); 21 | // IP白名单 (没有配置或者为空,则允许所有访问) 22 | registrationBean.addInitParameter("allow", "127.0.0.1"); 23 | // IP黑名单 (存在共同时,deny优先于allow) 24 | registrationBean.addInitParameter("deny", ""); 25 | registrationBean.addInitParameter("loginUsername", "druid"); 26 | registrationBean.addInitParameter("loginPassword", "123456"); 27 | registrationBean.addInitParameter("resetEnable", "false"); 28 | return registrationBean; 29 | } 30 | 31 | 32 | @Bean 33 | public FilterRegistrationBean druidStatFilter() { 34 | FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>( 35 | new WebStatFilter()); 36 | // 添加过滤规则 37 | filterRegistrationBean.addUrlPatterns("/*"); 38 | // 添加不需要忽略的格式信息 39 | filterRegistrationBean.addInitParameter("exclusions", 40 | "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); 41 | return filterRegistrationBean; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /springboot-learn-mail/src/main/java/com/plf/learn/mail/controller/MailController.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mail.controller; 2 | 3 | import com.plf.learn.mail.service.MailService; 4 | import lombok.extern.slf4j.Slf4j; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RestController; 8 | 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/4/20 14 | */ 15 | @RestController 16 | @Slf4j 17 | public class MailController { 18 | @Autowired 19 | private MailService mailService; 20 | 21 | @RequestMapping("/sendSimpleMail") 22 | public String sendSimpleMail(){ 23 | mailService.sendSimpleMail("", "简单的信息", "测试数据"); 24 | return "success"; 25 | } 26 | 27 | @RequestMapping("/sendHtmlMail") 28 | public String sendHtmlMail(){ 29 | mailService.sendHtmlMail("", "SpringBootHTML邮件测试", 30 | "

邮件标题

Hello"); 31 | return "success"; 32 | } 33 | 34 | @RequestMapping("/sendMailWithFile") 35 | public String sendMailWithFile(){ 36 | mailService.sendMailWithFile("", "SpringBoot附件邮件测试", 37 | "文件邮件","E:\\temp\\2.txt"); 38 | return "success"; 39 | } 40 | 41 | @RequestMapping("/sendMailWithImg") 42 | public String sendMailWithImg(){ 43 | String imgId="2"; 44 | String content="这是有图片的邮件:"; 45 | mailService.sendMailWithImg("", "SpringBoot图片邮件测试", 46 | content,"E:\\temp\\10.jpg",imgId); 47 | return "success"; 48 | } 49 | 50 | @RequestMapping("/test") 51 | public String testAsync(){ 52 | mailService.testAsync(); 53 | log.info("MailController无需等待就出现"); 54 | return "success"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/service/impl/TokenServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.service.impl; 2 | 3 | import com.plf.learn.redis.service.TokenService; 4 | import com.plf.learn.redis.utils.RedisUtils; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import javax.servlet.http.HttpServletRequest; 9 | import java.util.UUID; 10 | 11 | /** 12 | * @author Panlf 13 | * @date 2019/12/26 14 | */ 15 | @Service 16 | public class TokenServiceImpl implements TokenService { 17 | 18 | @Autowired 19 | private RedisUtils redisUtils; 20 | 21 | @Override 22 | public String createToken(String username) { 23 | //生成Token 24 | String token = UUID.randomUUID().toString(); 25 | 26 | /** 27 | * key为用户名,UUID生成token,过期时间600s 28 | */ 29 | redisUtils.set(username,token,600); 30 | 31 | return token; 32 | } 33 | 34 | @Override 35 | public boolean checkToken(HttpServletRequest request) throws Exception { 36 | String token = request.getHeader("token"); 37 | String username = request.getParameter("username"); 38 | 39 | if(username==null || username.trim().length()<=0){ 40 | throw new Exception("未获取到用户,请重新登录"); 41 | } 42 | 43 | if(token==null || token.trim().length()<=0){ 44 | token = request.getParameter("token"); 45 | if(token==null || token.trim().length()<=0){ 46 | throw new Exception("无token,无法继续操作"); 47 | } 48 | } 49 | 50 | if(!redisUtils.exits(username)){ 51 | throw new Exception("token过期,请重新申请"); 52 | } 53 | 54 | if(!redisUtils.get(username).equals(token)){ 55 | throw new Exception("token不匹配,请重新访问"); 56 | } 57 | 58 | //继续操作,删除无用token 59 | redisUtils.remove(token); 60 | 61 | return true; 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /springboot-learn-mail/src/main/java/com/plf/learn/mail/config/ThreadPoolTaskConfig.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.mail.config; 2 | 3 | /** 4 | * @author Panlf 5 | * @date 2020/3/18 6 | */ 7 | 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.context.annotation.Configuration; 10 | import org.springframework.scheduling.annotation.EnableAsync; 11 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; 12 | 13 | import java.util.concurrent.ThreadPoolExecutor; 14 | 15 | /** 16 | * 线程池配置 17 | * @author zhh 18 | * 19 | */ 20 | @Configuration 21 | @EnableAsync 22 | public class ThreadPoolTaskConfig { 23 | 24 | /** 25 | * 默认情况下,在创建了线程池后,线程池中的线程数为0,当有任务来之后,就会创建一个线程去执行任务, 26 | * 当线程池中的线程数目达到corePoolSize后,就会把到达的任务放到缓存队列当中; 27 | * 当队列满了,就继续创建线程,当线程数量大于等于maxPoolSize后,开始使用拒绝策略拒绝 28 | */ 29 | 30 | /** 核心线程数(默认线程数) */ 31 | private static final int corePoolSize = 20; 32 | /** 最大线程数 */ 33 | private static final int maxPoolSize = 100; 34 | /** 允许线程空闲时间(单位:默认为秒) */ 35 | private static final int keepAliveTime = 10; 36 | /** 缓冲队列大小 */ 37 | private static final int queueCapacity = 200; 38 | /** 线程池名前缀 */ 39 | private static final String threadNamePrefix = "Async-Service-"; 40 | 41 | @Bean("taskExecutor") // bean的名称,默认为首字母小写的方法名 42 | public ThreadPoolTaskExecutor taskExecutor(){ 43 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 44 | executor.setCorePoolSize(corePoolSize); 45 | executor.setMaxPoolSize(maxPoolSize); 46 | executor.setQueueCapacity(queueCapacity); 47 | executor.setKeepAliveSeconds(keepAliveTime); 48 | executor.setThreadNamePrefix(threadNamePrefix); 49 | 50 | // 线程池对拒绝任务的处理策略 51 | // CallerRunsPolicy:由调用线程(提交任务的线程)处理该任务 52 | executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); 53 | // 初始化 54 | executor.initialize(); 55 | return executor; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /springboot-learn-elastic-job/src/main/java/com/plf/learn/elastic/job/FileBackupJob.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.elastic.job; 2 | 3 | import java.time.LocalDateTime; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import com.plf.learn.elastic.bean.FileCustom; 8 | import com.plf.learn.elastic.service.FileCustomService; 9 | import lombok.extern.slf4j.Slf4j; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.stereotype.Component; 12 | 13 | import com.dangdang.ddframe.job.api.ShardingContext; 14 | import com.dangdang.ddframe.job.api.simple.SimpleJob; 15 | 16 | 17 | 18 | @Component 19 | @Slf4j 20 | public class FileBackupJob implements SimpleJob{ 21 | 22 | //每次任务执行要备份文件的数量 23 | private final int FETCH_SIZE=2; 24 | 25 | @Autowired 26 | private FileCustomService fileCustomService; 27 | 28 | @Override 29 | public void execute(ShardingContext shardingContext) { 30 | System.out.println("作业分片:"+shardingContext.getShardingItem()); 31 | //分片参数 (0=text,1=image,2=radio,3=video) 参数就是text、image... 32 | String jobParameter=shardingContext.getShardingParameter(); 33 | 34 | //获取未备份文件 35 | List fileCustoms = fetchUnBackupFiles(jobParameter,FETCH_SIZE); 36 | //进行文件备份 37 | backupFiles(fileCustoms); 38 | } 39 | 40 | /** 41 | * 获取未备份文件 42 | * @param count 43 | * @return 44 | */ 45 | public List fetchUnBackupFiles(String jobParamter,int count){ 46 | //要取的文件列表 47 | List fetchList = new ArrayList<>(); 48 | //从数据库查询根据type和count查询 49 | fetchList=fileCustomService.findFileCustomList(jobParamter,count); 50 | return fetchList; 51 | } 52 | 53 | /** 54 | * 文件备份 55 | * @param files 56 | */ 57 | public void backupFiles(List files) { 58 | for (FileCustom fileCustom : files) { 59 | fileCustomService.updateFileCustom(fileCustom.getId()); 60 | log.info("time:{},备份文件,名称:{},类型:{}", LocalDateTime.now(),fileCustom.getName(),fileCustom.getType()); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /springboot-learn-jpa/src/main/java/com/plf/learn/jpa/service/StudentService.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.jpa.service; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.Map; 6 | 7 | import javax.persistence.criteria.CriteriaBuilder; 8 | import javax.persistence.criteria.CriteriaQuery; 9 | import javax.persistence.criteria.Predicate; 10 | import javax.persistence.criteria.Root; 11 | 12 | import com.plf.learn.jpa.bean.Student; 13 | import com.plf.learn.jpa.dto.StudentDto; 14 | import com.plf.learn.jpa.repository.StudentRepository; 15 | import org.springframework.beans.factory.annotation.Autowired; 16 | import org.springframework.data.jpa.domain.Specification; 17 | import org.springframework.stereotype.Service; 18 | 19 | 20 | @Service 21 | public class StudentService { 22 | 23 | @Autowired 24 | private StudentRepository studentRepository; 25 | 26 | /** 27 | * 动态参数查询 28 | * @param name 29 | * @return 30 | */ 31 | public List findStudentByName(String name){ 32 | Specification specification = new Specification() { 33 | 34 | private static final long serialVersionUID = 6520751345774664104L; 35 | 36 | @Override 37 | public Predicate toPredicate(Root root, CriteriaQuery criteriaQuery, CriteriaBuilder criteriaBuilder) { 38 | List list = new ArrayList<>(); 39 | if(name!=null && name.trim().length()>0){ 40 | list.add(criteriaBuilder.like(root.get("name").as(String.class),"%"+name+"%")); 41 | } 42 | Predicate[] p = new Predicate[list.size()]; 43 | return criteriaBuilder.and(list.toArray(p)); 44 | } 45 | }; 46 | 47 | return studentRepository.findAll(specification); 48 | } 49 | 50 | /** 51 | * 使用原生SQL语句 52 | * @return 53 | */ 54 | public List findStudentDto(){ 55 | return studentRepository.findStudentDto(); 56 | } 57 | 58 | /** 59 | * 使用原生SQL语句 60 | * @return 61 | */ 62 | public List> findStudentDtoMap(){ 63 | return studentRepository.findStudentDtoMap(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /springboot-learn-redis/src/main/java/com/plf/learn/redis/interceptor/ApiIdempotentInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.redis.interceptor; 2 | 3 | import com.plf.learn.redis.annotations.ApiIdempotent; 4 | import com.plf.learn.redis.service.TokenService; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.lang.Nullable; 8 | import org.springframework.web.method.HandlerMethod; 9 | import org.springframework.web.servlet.HandlerInterceptor; 10 | import org.springframework.web.servlet.ModelAndView; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | import java.lang.reflect.Method; 15 | 16 | /** 17 | * 接口幂等性拦截器 18 | * @author Panlf 19 | * @date 2019/12/26 20 | */ 21 | @Configuration 22 | public class ApiIdempotentInterceptor implements HandlerInterceptor { 23 | 24 | @Autowired 25 | private TokenService tokenService; 26 | 27 | @Override 28 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { 29 | if (!(handler instanceof HandlerMethod)) { 30 | return true; 31 | } 32 | HandlerMethod handlerMethod = (HandlerMethod) handler; 33 | Method method = handlerMethod.getMethod(); 34 | 35 | ApiIdempotent methodAnnotation = method.getAnnotation(ApiIdempotent.class); 36 | if (methodAnnotation != null) { 37 | // 幂等性校验, 校验通过则放行, 校验失败则抛出异常, 并通过统一异常处理返回友好提示 38 | tokenService.checkToken(request); 39 | } 40 | 41 | return true; 42 | } 43 | 44 | @Override 45 | public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable ModelAndView modelAndView) throws Exception { 46 | 47 | } 48 | 49 | @Override 50 | public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, @Nullable Exception ex) throws Exception { 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /springboot-learn-jwt/src/main/resources/readme.txt: -------------------------------------------------------------------------------- 1 | JWT简介 2 | JSON Web Token由三部分组成 - Header、Payload、Signature,他们之间用原点(.)连接, 3 | 即是Header.Payload.Signature。 4 | 5 | Header 6 | Header 部分是一个 JSON 对象,描述 JWT 的元数据。 7 | 由两部分组成: 8 | alg属性表示签名的算法(algorithm),默认是 HMAC SHA256(写成 HS256) 9 | typ属性表示这个令牌(token)的类型(type),JWT 令牌统一写为JWT 10 | 11 | Payload 12 | Payload 部分也是一个 JSON 对象,用来存放实际需要传递的数据。 13 | iss(issuer):签发人 14 | exp(expiration time):过期时间 15 | sub(subject):主题 16 | aud(audience):受众 17 | nbf(Not Before):生效时间 18 | iat(Issued At):签发时间 19 | jti(JWT ID):编号 20 | 21 | 注意,JWT 默认是不加密的,任何人都可以读到,所以不要把秘密信息放在这个部分。 22 | 这个 JSON 对象也要使用 Base64URL 算法转成字符串。 23 | 24 | Signature 25 | Signature 部分是对前两部分的签名,防止数据篡改。 26 | 首先,需要指定一个密钥(secret)。这个密钥只有服务器才知道,不能泄露给用户。 27 | 然后,使用 Header 里面指定的签名算法(默认是 HMAC SHA256),按照下面的公式产生签名。 28 | HMACSHA256( 29 | base64UrlEncode(header) + "." + 30 | base64UrlEncode(payload), 31 | secret) 32 | 33 | 客户端收到服务器返回的 JWT,可以储存在 Cookie 里面,也可以储存在 localStorage。 34 | 35 | 此后,客户端每次与服务器通信,都要带上这个 JWT。 36 | 你可以把它放在 Cookie 里面自动发送,但是这样不能跨域, 37 | 所以更好的做法是放在 HTTP 请求的头信息Authorization字段里面。 38 | 39 | 特点 40 | (1)JWT 默认是不加密,但也是可以加密的。生成原始 Token 以后,可以用密钥再加密一次。 41 | (2)JWT 不加密的情况下,不能将秘密数据写入 JWT。 42 | (3)JWT 不仅可以用于认证,也可以用于交换信息。有效使用 JWT,可以降低服务器查询数据库的次数。 43 | (4)JWT 的最大缺点是,由于服务器不保存 session 状态,因此无法在使用过程中废止某个 token,或者更改 token 的权限。也就是说,一旦 JWT 签发了,在到期之前就会始终有效,除非服务器部署额外的逻辑。 44 | (5)JWT 本身包含了认证信息,一旦泄露,任何人都可以获得该令牌的所有权限。为了减少盗用,JWT 的有效期应该设置得比较短。对于一些比较重要的权限,使用时应该再次对用户进行认证。 45 | (6)为了减少盗用,JWT 不应该使用 HTTP 协议明码传输,要使用 HTTPS 协议传输。 46 | 47 | 48 | 49 | Token机制 50 | 身份认证 51 | 使用token的身份验证方法,在服务端不需要存储用户的登录记录 52 | 1、客户端使用用户名、密码登录 53 | 2、服务端收到请求,去验证用户名、密码 54 | 3、验证成功后,服务端会签发一个Token,再把这个Token发送给客户端 55 | 4、客户端收到Token以后把它存储起来,比如放到Cookie或者LocalStorage里 56 | 5、客户端每次向服务端请求资源的时候需要带着服务端签发的Token 57 | 6、服务端收到请求,然后去验证客户端请求里面带着的Token,如果验证成功,就向客户端返回请求的数据 58 | 59 | -------------------------------------------------------------------------------- /springboot-learn-caffeine/src/main/java/com/plf/learn/caffeine/config/CaffeineMonitorAspect.java: -------------------------------------------------------------------------------- 1 | package com.plf.learn.caffeine.config; 2 | 3 | import lombok.extern.slf4j.Slf4j; 4 | import org.aspectj.lang.JoinPoint; 5 | import org.aspectj.lang.annotation.AfterReturning; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.aspectj.lang.annotation.Pointcut; 8 | import org.springframework.cache.Cache; 9 | import org.springframework.cache.caffeine.CaffeineCacheManager; 10 | import org.springframework.core.annotation.Order; 11 | import org.springframework.stereotype.Component; 12 | 13 | import javax.annotation.Resource; 14 | import java.util.Collection; 15 | 16 | /** 17 | * @author panlf 18 | * @date 2021/8/16 19 | */ 20 | @Aspect 21 | @Component 22 | // add 缓存的时候。我需要这个aop在执行缓存操作之后再执行。所以需要执行order大一点 23 | @Order(9) 24 | @Slf4j 25 | public class CaffeineMonitorAspect { 26 | @Pointcut("execution(* com.plf.learn.caffeine.service.*.*(..))") 27 | public void aspect() { } 28 | 29 | @Resource 30 | CaffeineCacheManager caffeineCacheManager; 31 | 32 | 33 | //主要是为了监控是否数据真的放入到Cache里 34 | @AfterReturning("aspect()") 35 | public void after(JoinPoint point) { 36 | String method = point.getSignature().getName(); 37 | Object[] args = point.getArgs(); 38 | log.info("method : {}",method); 39 | log.info("args length: {}",args.length); 40 | 41 | Integer userId = 0; 42 | if(method.startsWith("add")){ 43 | userId = Integer.valueOf(args[0].toString()); 44 | } 45 | 46 | 47 | Collection collection = caffeineCacheManager.getCacheNames(); 48 | Integer finalUserId = userId; 49 | 50 | log.info("finalUserId : {}",finalUserId); 51 | collection.stream().forEach(x->{ 52 | if(x.equalsIgnoreCase("userInfo")){ 53 | Cache cache = caffeineCacheManager.getCache(x); 54 | Cache.ValueWrapper valueWrapper = cache.get(finalUserId); 55 | if(valueWrapper!=null){ 56 | log.info("cache : {} ",valueWrapper.get()); 57 | } 58 | } 59 | }); 60 | } 61 | 62 | } 63 | --------------------------------------------------------------------------------