├── .gitignore ├── .idea ├── compiler.xml ├── dataSources.local.xml ├── dataSources.xml ├── dataSources │ └── 9d7ddf88-be8d-4e3a-95a9-ba86c0086a42.xml ├── inspectionProfiles │ └── Project_Default.xml ├── libraries │ ├── Maven__ch_qos_logback_logback_classic_1_2_3.xml │ ├── Maven__ch_qos_logback_logback_core_1_2_3.xml │ ├── Maven__com_alibaba_fastjson_1_2_62.xml │ ├── Maven__com_baomidou_mybatis_plus_3_1_2.xml │ ├── Maven__com_baomidou_mybatis_plus_annotation_3_1_2.xml │ ├── Maven__com_baomidou_mybatis_plus_boot_starter_3_1_2.xml │ ├── Maven__com_baomidou_mybatis_plus_core_3_1_2.xml │ ├── Maven__com_baomidou_mybatis_plus_extension_3_1_2.xml │ ├── Maven__com_baomidou_mybatis_plus_generator_3_1_2.xml │ ├── Maven__com_fasterxml_classmate_1_3_4.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_core_2_9_8.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_9_8.xml │ ├── Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_6.xml │ ├── Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_6.xml │ ├── Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_6.xml │ ├── Maven__com_github_jsqlparser_jsqlparser_1_2.xml │ ├── Maven__com_mchange_mchange_commons_java_0_2_11.xml │ ├── Maven__com_zaxxer_HikariCP_3_2_0.xml │ ├── Maven__io_lettuce_lettuce_core_5_1_8_RELEASE.xml │ ├── Maven__io_netty_netty_buffer_4_1_38_Final.xml │ ├── Maven__io_netty_netty_codec_4_1_38_Final.xml │ ├── Maven__io_netty_netty_common_4_1_38_Final.xml │ ├── Maven__io_netty_netty_handler_4_1_38_Final.xml │ ├── Maven__io_netty_netty_resolver_4_1_38_Final.xml │ ├── Maven__io_netty_netty_transport_4_1_38_Final.xml │ ├── Maven__io_projectreactor_reactor_core_3_2_11_RELEASE.xml │ ├── Maven__javax_annotation_javax_annotation_api_1_3_2.xml │ ├── Maven__javax_validation_validation_api_2_0_1_Final.xml │ ├── Maven__mysql_mysql_connector_java_6_0_6.xml │ ├── Maven__org_apache_commons_commons_lang3_3_5.xml │ ├── Maven__org_apache_logging_log4j_log4j_api_2_10_0.xml │ ├── Maven__org_apache_logging_log4j_log4j_to_slf4j_2_10_0.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_32.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_32.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_32.xml │ ├── Maven__org_apache_velocity_velocity_engine_core_2_0.xml │ ├── Maven__org_aspectj_aspectjweaver_1_8_13.xml │ ├── Maven__org_freemarker_freemarker_2_3_23.xml │ ├── Maven__org_hibernate_validator_hibernate_validator_6_0_11_Final.xml │ ├── Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml │ ├── Maven__org_mybatis_mybatis_3_5_1.xml │ ├── Maven__org_mybatis_mybatis_spring_2_0_1.xml │ ├── Maven__org_quartz_scheduler_quartz_2_3_0.xml │ ├── Maven__org_reactivestreams_reactive_streams_1_0_2.xml │ ├── Maven__org_slf4j_jul_to_slf4j_1_7_25.xml │ ├── Maven__org_slf4j_slf4j_api_1_7_25.xml │ ├── Maven__org_springframework_boot_spring_boot_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_2_1_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_2_1_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_aop_2_0_5_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_data_redis_2_1_8_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_jdbc_2_1_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_json_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_logging_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_quartz_2_1_1_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_web_2_0_4_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_commons_2_1_10_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_keyvalue_2_1_10_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_redis_2_1_10_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_5_0_9_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_5_1_9_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_5_0_8_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_5_1_3_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_context_5_0_8_RELEASE.xml │ ├── Maven__org_springframework_spring_context_5_1_3_RELEASE.xml │ ├── Maven__org_springframework_spring_context_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_context_support_5_1_3_RELEASE.xml │ ├── Maven__org_springframework_spring_core_5_0_8_RELEASE.xml │ ├── Maven__org_springframework_spring_core_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_5_0_8_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_5_1_3_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_jcl_5_0_8_RELEASE.xml │ ├── Maven__org_springframework_spring_jcl_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_jdbc_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_oxm_5_1_9_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_5_1_3_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_5_1_6_RELEASE.xml │ ├── Maven__org_springframework_spring_web_5_0_8_RELEASE.xml │ ├── Maven__org_springframework_spring_webmvc_5_0_8_RELEASE.xml │ └── Maven__org_yaml_snakeyaml_1_19.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── README.md ├── pom.xml ├── redis-like-common ├── pom.xml ├── redis-like-common.iml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── h2t │ │ └── study │ │ ├── README.md │ │ └── util │ │ └── FastjsonUtil.java └── target │ └── classes │ └── com │ └── h2t │ └── study │ └── util │ ├── FastjsonUtil$1.class │ └── FastjsonUtil.class ├── redis-like-dao ├── pom.xml ├── redis-like-dao.iml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── h2t │ │ └── study │ │ └── mapper │ │ ├── ArticleMapper.java │ │ ├── README.md │ │ ├── UserLikeArticleMapper.java │ │ └── UserMapper.java └── target │ └── classes │ └── com │ └── h2t │ └── study │ └── mapper │ ├── ArticleMapper.class │ ├── UserLikeArticleMapper.class │ └── UserMapper.class ├── redis-like-model ├── pom.xml ├── redis-like-model.iml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── h2t │ │ └── study │ │ ├── converter │ │ └── LocalDateTimeConverter.java │ │ ├── dto │ │ └── BaseDTO.java │ │ ├── po │ │ ├── Article.java │ │ ├── BasePO.java │ │ ├── User.java │ │ └── UserLikeArticle.java │ │ └── vo │ │ └── BaseVO.java └── target │ └── classes │ └── com │ └── h2t │ └── study │ ├── converter │ └── LocalDateTimeConverter.class │ ├── dto │ └── BaseDTO.class │ ├── po │ ├── Article.class │ ├── BasePO.class │ ├── User.class │ └── UserLikeArticle.class │ └── vo │ └── BaseVO.class ├── redis-like-service ├── pom.xml ├── redis-like-service.iml ├── src │ └── main │ │ └── java │ │ └── com │ │ └── h2t │ │ └── study │ │ ├── config │ │ └── MyBatisPlusConfig.java │ │ ├── enums │ │ └── ErrorCodeEnum.java │ │ ├── exception │ │ └── CustomException.java │ │ ├── generator │ │ ├── MpGenerator.java │ │ └── README.md │ │ ├── service │ │ ├── ArticleService.java │ │ ├── BaseService.java │ │ ├── RedisService.java │ │ ├── UserLikeArticleService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── ArticleServiceImpl.java │ │ │ ├── BaseServiceImpl.java │ │ │ ├── RedisServiceImpl.java │ │ │ ├── UserLikeArticleServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── task │ │ └── ScheduleTask.java └── target │ └── classes │ └── com │ └── h2t │ └── study │ ├── config │ └── MyBatisPlusConfig.class │ ├── enums │ └── ErrorCodeEnum.class │ ├── exception │ └── CustomException.class │ ├── generator │ ├── MpGenerator$1.class │ ├── MpGenerator$2.class │ └── MpGenerator.class │ ├── service │ ├── ArticleService.class │ ├── BaseService.class │ ├── RedisService.class │ ├── UserLikeArticleService.class │ ├── UserService.class │ └── impl │ │ ├── ArticleServiceImpl.class │ │ ├── BaseServiceImpl.class │ │ ├── RedisServiceImpl.class │ │ ├── UserLikeArticleServiceImpl.class │ │ └── UserServiceImpl.class │ └── task │ └── ScheduleTask.class ├── redis-like-web ├── pom.xml ├── redis-like-web.iml ├── src │ └── main │ │ ├── java │ │ └── com │ │ │ └── h2t │ │ │ └── study │ │ │ ├── Runner.java │ │ │ ├── aspect │ │ │ └── ResponseAspect.java │ │ │ ├── controller │ │ │ ├── ArticleLikeController.java │ │ │ └── TestController.java │ │ │ ├── handler │ │ │ └── ResponseHandler.java │ │ │ └── response │ │ │ └── BaseResponse.java │ │ └── resources │ │ ├── application.properties │ │ ├── log4j2-spring.xml │ │ └── log4j2.component.properties └── target │ └── classes │ ├── application.properties │ ├── com │ └── h2t │ │ └── study │ │ ├── Runner.class │ │ ├── aspect │ │ └── ResponseAspect.class │ │ ├── controller │ │ ├── ArticleLikeController.class │ │ └── TestController.class │ │ ├── handler │ │ └── ResponseHandler.class │ │ └── response │ │ └── BaseResponse.class │ ├── log4j2-spring.xml │ └── log4j2.component.properties ├── redis-like.iml └── sql └── article-like.sql /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/dataSources.local.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | *:@ 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql 6 | true 7 | com.mysql.jdbc.Driver 8 | jdbc:mysql://localhost:3306/test 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_classic_1_2_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__ch_qos_logback_logback_core_1_2_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_fastjson_1_2_62.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_baomidou_mybatis_plus_3_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_baomidou_mybatis_plus_annotation_3_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_baomidou_mybatis_plus_boot_starter_3_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_baomidou_mybatis_plus_core_3_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_baomidou_mybatis_plus_extension_3_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_baomidou_mybatis_plus_generator_3_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_classmate_1_3_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_9_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_9_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_github_jsqlparser_jsqlparser_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_mchange_mchange_commons_java_0_2_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_zaxxer_HikariCP_3_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_lettuce_lettuce_core_5_1_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_buffer_4_1_38_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_codec_4_1_38_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_common_4_1_38_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_handler_4_1_38_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_resolver_4_1_38_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_netty_netty_transport_4_1_38_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_projectreactor_reactor_core_3_2_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_annotation_javax_annotation_api_1_3_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__javax_validation_validation_api_2_0_1_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__mysql_mysql_connector_java_6_0_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_lang3_3_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_logging_log4j_log4j_api_2_10_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_logging_log4j_log4j_to_slf4j_2_10_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_32.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_32.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_32.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_velocity_velocity_engine_core_2_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_aspectj_aspectjweaver_1_8_13.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_freemarker_freemarker_2_3_23.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_11_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mybatis_mybatis_3_5_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mybatis_mybatis_spring_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_quartz_scheduler_quartz_2_3_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_reactivestreams_reactive_streams_1_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jul_to_slf4j_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_slf4j_api_1_7_25.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_2_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_autoconfigure_2_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_aop_2_0_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_data_redis_2_1_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_jdbc_2_1_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_json_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_logging_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_quartz_2_1_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_tomcat_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_web_2_0_4_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_commons_2_1_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_keyvalue_2_1_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_data_spring_data_redis_2_1_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_5_0_9_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_5_1_9_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_5_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_5_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_support_5_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_5_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jcl_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jcl_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jdbc_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_oxm_5_1_9_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_5_1_3_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_5_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_5_0_8_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_yaml_snakeyaml_1_19.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # redis-like 2 | 3 | ### redis-like项目介绍 4 | 基于`Redis`的点赞功能实现`demo` 5 | 6 | ### 开发环境 7 | - windows10 os 8 | - Maven 3.6.1 9 | - JDK 1.8 10 | 11 | ### 技术栈 12 | - MySQL 13 | - Redis 14 | - MyBatisPlus 15 | - SpringBoot 16 | 17 | ### 程序运行 18 | - 创建数据库&导入表 19 | 1.创建`article-like`数据库 20 | 2.数据库表结构在`sql`文件夹下 21 | - 启动本地`Redis`,进入`Redis`安装目录执行命令: 22 | 23 | ``` 24 | redis-server.exe redis.windows.conf 25 | ``` 26 | - 运行`Run.java` 27 | 28 | ### API说明 29 | ###### 点赞文章 30 | - `API` => `/{articleId}/{likedUserId}/{likedPoseId}` 31 | - 请求方式 => `POST` 32 | - 参数说明 33 | 34 | | 参数名称 | 参数类型 | 是否必填 | 参数说明 | 35 | | :-----: | :---: | :---: | :---: | 36 | | articleId | Long | 是 | 文章ID | 37 | | likedUserId | Long | 是 | 被点赞用户ID | 38 | | likedPoseId | Long | 是 | 点赞用户ID | 39 | 40 | ###### 取消点赞 41 | - `API` => `/{articleId}/{likedUserId}/{likedPoseId}` 42 | - 请求方式 => `DELETE` 43 | - 参数说明 44 | 45 | | 参数名称 | 参数类型 | 是否必填 | 参数说明 | 46 | | :-----: | :---: | :---: | :---: | 47 | | articleId | Long | 是 | 文章ID | 48 | | likedUserId | Long | 是 | 被点赞用户ID | 49 | | likedPoseId | Long | 是 | 点赞用户ID | 50 | 51 | ###### 获取用户点赞的文章 52 | - `API` => `/user/{likedPoseId}/like` 53 | - 请求方式 => `GET` 54 | - 参数说明 55 | 56 | | 参数名称 | 参数类型 | 是否必填 | 参数说明 | 57 | | :-----: | :---: | :---: | :---: | 58 | | likedPoseId | Long | 是 | 点赞用户ID | 59 | 60 | ###### 统计用户总的文章点赞数 61 | - `API` => `/total/user/{userId}` 62 | - 请求方式 => `GET` 63 | - 参数说明 64 | 65 | | 参数名称 | 参数类型 | 是否必填 | 参数说明 | 66 | | :-----: | :---: | :---: | :---: | 67 | | likedUserId | Long | 是 | 被点赞用户ID | 68 | 69 | ###### 统计某篇文章总点赞数 70 | - `API` => `/total/article/{articleId}` 71 | - 请求方式 => `GET` 72 | - 参数说明 73 | 74 | | 参数名称 | 参数类型 | 是否必填 | 参数说明 | 75 | | :-----: | :---: | :---: | :---: | 76 | | articleId | Long | 是 | 文章ID | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 4.0.0 6 | 7 | com.h2t.study 8 | redis-like 9 | 1.0.0-SNAPSHOT 10 | pom 11 | redis-like 12 | 13 | 14 | 1.0.0-SNAPSHOT 15 | 1.8 16 | 17 | 18 | 19 | 20 | redis-like-common 21 | redis-like-dao 22 | redis-like-service 23 | redis-like-web 24 | redis-like-model 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter 32 | 2.0.4.RELEASE 33 | 34 | 35 | 36 | org.springframework.boot 37 | spring-boot-starter-test 38 | 2.0.4.RELEASE 39 | test 40 | 41 | 42 | 43 | org.springframework.boot 44 | spring-boot-starter-web 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-starter-logging 50 | 51 | 52 | 2.0.4.RELEASE 53 | 54 | 55 | 56 | 57 | mysql 58 | mysql-connector-java 59 | 6.0.6 60 | 61 | 62 | 63 | 64 | com.baomidou 65 | mybatis-plus-boot-starter 66 | 3.1.2 67 | 68 | 69 | 70 | com.baomidou 71 | mybatis-plus-generator 72 | 3.1.2 73 | 74 | 75 | 76 | org.apache.velocity 77 | velocity-engine-core 78 | 2.0 79 | 80 | 81 | 82 | org.freemarker 83 | freemarker 84 | 2.3.23 85 | 86 | 87 | 88 | 89 | org.springframework.boot 90 | spring-boot-starter-log4j2 91 | 2.1.1.RELEASE 92 | 93 | 94 | 95 | com.lmax 96 | disruptor 97 | 3.4.2 98 | 99 | 100 | 101 | org.springframework.boot 102 | spring-boot-starter-aop 103 | 2.0.5.RELEASE 104 | 105 | 106 | 107 | com.fasterxml.jackson.core 108 | jackson-databind 109 | 2.9.8 110 | 111 | 112 | 113 | 114 | com.h2t.study 115 | redis-like-common 116 | 1.0.0-SNAPSHOT 117 | 118 | 119 | 120 | com.h2t.study 121 | redis-like-dao 122 | 1.0.0-SNAPSHOT 123 | 124 | 125 | 126 | com.h2t.study 127 | redis-like-service 128 | 1.0.0-SNAPSHOT 129 | 130 | 131 | 132 | com.h2t.study 133 | redis-like-model 134 | 1.0.0-SNAPSHOT 135 | 136 | 137 | 138 | org.springframework.boot 139 | spring-boot-starter-data-redis 140 | 2.1.8.RELEASE 141 | 142 | 143 | 144 | com.alibaba 145 | fastjson 146 | 1.2.62 147 | 148 | 149 | 150 | org.springframework.boot 151 | spring-boot-starter-quartz 152 | 2.1.1.RELEASE 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | dev 162 | 163 | dev 164 | 165 | 166 | true 167 | 168 | 169 | 170 | 171 | test 172 | 173 | test 174 | 175 | 176 | 177 | 178 | pre 179 | 180 | pre 181 | 182 | 183 | 184 | 185 | prod 186 | 187 | prod 188 | 189 | 190 | 191 | 192 | 193 | ${project.artifactId} 194 | 195 | 196 | org.springframework.boot 197 | spring-boot-maven-plugin 198 | 2.1.5.RELEASE 199 | 200 | 201 | 202 | org.apache.maven.plugins 203 | maven-compiler-plugin 204 | 205 | 8 206 | 8 207 | 208 | 209 | 210 | 211 | 212 | src/main/java 213 | 214 | **/*.xml 215 | **/*.properties 216 | 217 | true 218 | 219 | 220 | 221 | 222 | -------------------------------------------------------------------------------- /redis-like-common/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | com.h2t.study 9 | redis-like 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | redis-like-common 14 | 15 | 16 | 17 | com.alibaba 18 | fastjson 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /redis-like-common/redis-like-common.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /redis-like-common/src/main/java/com/h2t/study/README.md: -------------------------------------------------------------------------------- 1 | 该模块主用放一些工具类以及中间件封装类 2 | 工具类的整合及中间件的封装 -------------------------------------------------------------------------------- /redis-like-common/src/main/java/com/h2t/study/util/FastjsonUtil.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.util; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.TypeReference; 5 | 6 | import java.util.Set; 7 | 8 | /** 9 | * 序列化与反序列化工具类 10 | * 11 | * @author hetiantian 12 | * @version 1.0 13 | * @Date 2019/10/11 11:12 14 | */ 15 | public class FastjsonUtil { 16 | /** 17 | * 序列化 18 | * 19 | * @param object 序列化对象 20 | * @return 21 | */ 22 | public static String serialize(Object object) { 23 | return JSON.toJSONString(object); 24 | } 25 | 26 | /** 27 | * Set反序列化 28 | * 29 | * @param jsonStr 序列化结果 30 | * @param clazz 泛型class类 31 | * @return 32 | */ 33 | public static Set deserializeToSet(String jsonStr, Class clazz) { 34 | return JSON.parseObject(jsonStr, new TypeReference>(clazz) { 35 | }); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /redis-like-common/target/classes/com/h2t/study/util/FastjsonUtil$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-common/target/classes/com/h2t/study/util/FastjsonUtil$1.class -------------------------------------------------------------------------------- /redis-like-common/target/classes/com/h2t/study/util/FastjsonUtil.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-common/target/classes/com/h2t/study/util/FastjsonUtil.class -------------------------------------------------------------------------------- /redis-like-dao/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | com.h2t.study 9 | redis-like 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | redis-like-dao 14 | 15 | 16 | 17 | com.baomidou 18 | mybatis-plus-boot-starter 19 | 20 | 21 | 22 | com.h2t.study 23 | redis-like-model 24 | 25 | 26 | -------------------------------------------------------------------------------- /redis-like-dao/redis-like-dao.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /redis-like-dao/src/main/java/com/h2t/study/mapper/ArticleMapper.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.h2t.study.po.Article; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author hetiantian 13 | * @since 2019-10-08 14 | */ 15 | @Mapper 16 | public interface ArticleMapper extends BaseMapper
{ 17 | 18 | } 19 | -------------------------------------------------------------------------------- /redis-like-dao/src/main/java/com/h2t/study/mapper/README.md: -------------------------------------------------------------------------------- 1 | 该包下主要为dao层接口 -------------------------------------------------------------------------------- /redis-like-dao/src/main/java/com/h2t/study/mapper/UserLikeArticleMapper.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.h2t.study.po.UserLikeArticle; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author hetiantian 13 | * @since 2019-10-08 14 | */ 15 | @Mapper 16 | public interface UserLikeArticleMapper extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /redis-like-dao/src/main/java/com/h2t/study/mapper/UserMapper.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.mapper; 2 | 3 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 4 | import com.h2t.study.po.User; 5 | import org.apache.ibatis.annotations.Mapper; 6 | 7 | /** 8 | *

9 | * Mapper 接口 10 | *

11 | * 12 | * @author hetiantian 13 | * @since 2019-10-08 14 | */ 15 | @Mapper 16 | public interface UserMapper extends BaseMapper { 17 | 18 | } 19 | -------------------------------------------------------------------------------- /redis-like-dao/target/classes/com/h2t/study/mapper/ArticleMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-dao/target/classes/com/h2t/study/mapper/ArticleMapper.class -------------------------------------------------------------------------------- /redis-like-dao/target/classes/com/h2t/study/mapper/UserLikeArticleMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-dao/target/classes/com/h2t/study/mapper/UserLikeArticleMapper.class -------------------------------------------------------------------------------- /redis-like-dao/target/classes/com/h2t/study/mapper/UserMapper.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-dao/target/classes/com/h2t/study/mapper/UserMapper.class -------------------------------------------------------------------------------- /redis-like-model/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | com.h2t.study 9 | redis-like 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | redis-like-model 14 | 15 | 16 | 17 | com.baomidou 18 | mybatis-plus-boot-starter 19 | 20 | 21 | 22 | com.fasterxml.jackson.core 23 | jackson-databind 24 | 25 | 26 | -------------------------------------------------------------------------------- /redis-like-model/redis-like-model.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/converter/LocalDateTimeConverter.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.converter; 2 | 3 | import com.fasterxml.jackson.core.JsonGenerator; 4 | import com.fasterxml.jackson.databind.JsonSerializer; 5 | import com.fasterxml.jackson.databind.SerializerProvider; 6 | 7 | import java.io.IOException; 8 | import java.time.LocalDateTime; 9 | import java.time.ZoneOffset; 10 | 11 | /** 12 | * LocalDateTime转化器 13 | * 14 | * @author hetiantian 15 | * @version 1.0 16 | * @Date 2019/10/08 14:23 17 | */ 18 | public class LocalDateTimeConverter extends JsonSerializer { 19 | 20 | @Override 21 | public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException { 22 | gen.writeNumber(value.toInstant(ZoneOffset.of("+8")).toEpochMilli()); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/dto/BaseDTO.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.dto; 2 | 3 | /** 4 | * 基本DTO字段 5 | * 6 | * @author hetiantian 7 | * @version 1.0 8 | * @Date 2019/08/12 19:01 9 | */ 10 | public class BaseDTO { 11 | } 12 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/po/Article.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | 5 | import java.sql.Blob; 6 | 7 | /** 8 | * 文章实体 9 | * 10 | * @author hetiantian 11 | * @since 2019-10-08 12 | */ 13 | public class Article extends BasePO { 14 | /** 15 | * 用户ID 16 | */ 17 | @TableField(value = "user_id", exist = true) 18 | private Long userId; 19 | 20 | /** 21 | * 文章内容 22 | */ 23 | @TableField(value = "content", exist = true) 24 | private Blob content; 25 | 26 | /** 27 | * 文章总点赞数 28 | */ 29 | @TableField(value = "total_like_count", exist = true) 30 | private Long totalLikeCount; 31 | 32 | /** 33 | * 文章名字 34 | */ 35 | @TableField(value = "article_name", exist = true) 36 | private String articleName; 37 | 38 | public Long getUserId() { 39 | return userId; 40 | } 41 | 42 | public void setUserId(Long userId) { 43 | this.userId = userId; 44 | } 45 | 46 | public Blob getContent() { 47 | return content; 48 | } 49 | 50 | public void setContent(Blob content) { 51 | this.content = content; 52 | } 53 | 54 | public Long getTotalLikeCount() { 55 | return totalLikeCount; 56 | } 57 | 58 | public void setTotalLikeCount(Long totalLikeCount) { 59 | this.totalLikeCount = totalLikeCount; 60 | } 61 | 62 | public String getArticleName() { 63 | return articleName; 64 | } 65 | 66 | public void setArticleName(String articleName) { 67 | this.articleName = articleName; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/po/BasePO.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.*; 4 | import com.fasterxml.jackson.databind.annotation.JsonSerialize; 5 | import com.h2t.study.converter.LocalDateTimeConverter; 6 | import org.springframework.format.annotation.DateTimeFormat; 7 | 8 | import java.time.LocalDateTime; 9 | 10 | /** 11 | * 基本PO字段 12 | * 13 | * @author hetiantian 14 | * @version 1.0 15 | * @Date 2019/08/02 16:39 16 | */ 17 | @TableName(value = "base") 18 | public class BasePO { 19 | @TableId(value = "id", type = IdType.AUTO) 20 | private Long id; 21 | 22 | //使用@TableLogic注解实现逻辑删除 23 | @TableLogic 24 | @TableField(value = "deleted", exist = true) 25 | protected Integer deleted = 0; 26 | 27 | @TableField(value = "gmt_create", exist = true) 28 | @JsonSerialize(using = LocalDateTimeConverter.class) 29 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 30 | protected LocalDateTime gmtCreate; 31 | 32 | @TableField(value = "gmt_modified", exist = true) 33 | @JsonSerialize(using = LocalDateTimeConverter.class) 34 | @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") 35 | protected LocalDateTime gmtModified; 36 | 37 | public BasePO() { 38 | } 39 | 40 | public BasePO(Long id, Integer deleted, LocalDateTime gmtCreate, LocalDateTime gmtModify) { 41 | this.id = id; 42 | this.deleted = deleted; 43 | this.gmtCreate = gmtCreate; 44 | this.gmtModified = gmtModify; 45 | } 46 | 47 | //getter and setter 48 | public Long getId() { 49 | return id; 50 | } 51 | 52 | public void setId(Long id) { 53 | this.id = id; 54 | } 55 | 56 | public LocalDateTime getGmtCreate() { 57 | return gmtCreate; 58 | } 59 | 60 | public void setGmtCreate(LocalDateTime gmtCreate) { 61 | this.gmtCreate = gmtCreate; 62 | } 63 | 64 | public LocalDateTime getGmtModified() { 65 | return gmtModified; 66 | } 67 | 68 | public void setGmtModified(LocalDateTime gmtModified) { 69 | this.gmtModified = gmtModified; 70 | } 71 | 72 | public Integer getDeleted() { 73 | return deleted; 74 | } 75 | 76 | public void setDeleted(Integer deleted) { 77 | this.deleted = deleted; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return "BasePO{" + 83 | "id=" + id + 84 | ", deleted=" + deleted + 85 | ", gmtCreate=" + gmtCreate + 86 | ", gmtModified=" + gmtModified + 87 | '}'; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/po/User.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | 5 | /** 6 | * 用户实体 7 | * 8 | * @author hetiantian 9 | * @since 2019-10-08 10 | */ 11 | public class User extends BasePO { 12 | /** 13 | * 用户名 14 | */ 15 | @TableField(value = "username", exist = true) 16 | private String username; 17 | 18 | /** 19 | * 密码 20 | */ 21 | @TableField(value = "password", exist = true) 22 | private String password; 23 | 24 | public String getUsername() { 25 | return username; 26 | } 27 | 28 | public void setUsername(String username) { 29 | this.username = username; 30 | } 31 | 32 | public String getPassword() { 33 | return password; 34 | } 35 | 36 | public void setPassword(String password) { 37 | this.password = password; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/po/UserLikeArticle.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.po; 2 | 3 | import com.baomidou.mybatisplus.annotation.TableField; 4 | 5 | /** 6 | * 点赞中间表实体类 7 | * 8 | * @author hetiantian 9 | * @since 2019-10-08 10 | */ 11 | public class UserLikeArticle extends BasePO { 12 | /** 13 | * 用户ID 14 | */ 15 | @TableField(value = "user_id", exist = true) 16 | private Long userId; 17 | 18 | /** 19 | * 文章ID 20 | */ 21 | @TableField(value = "article_id", exist = true) 22 | private Long articleId; 23 | 24 | public Long getUserId() { 25 | return userId; 26 | } 27 | 28 | public void setUserId(Long userId) { 29 | this.userId = userId; 30 | } 31 | 32 | public Long getArticleId() { 33 | return articleId; 34 | } 35 | 36 | public void setArticleId(Long articleId) { 37 | this.articleId = articleId; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /redis-like-model/src/main/java/com/h2t/study/vo/BaseVO.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.vo; 2 | 3 | /** 4 | * 基本VO字段 5 | * 6 | * @author hetiantian 7 | * @version 1.0 8 | * @Date 2019/08/12 19:01 9 | */ 10 | public class BaseVO { 11 | } 12 | -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/converter/LocalDateTimeConverter.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/converter/LocalDateTimeConverter.class -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/dto/BaseDTO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/dto/BaseDTO.class -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/po/Article.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/po/Article.class -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/po/BasePO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/po/BasePO.class -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/po/User.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/po/User.class -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/po/UserLikeArticle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/po/UserLikeArticle.class -------------------------------------------------------------------------------- /redis-like-model/target/classes/com/h2t/study/vo/BaseVO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-model/target/classes/com/h2t/study/vo/BaseVO.class -------------------------------------------------------------------------------- /redis-like-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | 9 | com.h2t.study 10 | redis-like 11 | 1.0.0-SNAPSHOT 12 | 13 | 14 | redis-like-service 15 | 16 | 17 | 18 | com.baomidou 19 | mybatis-plus-boot-starter 20 | 21 | 22 | 23 | com.h2t.study 24 | redis-like-model 25 | 26 | 27 | 28 | 29 | com.baomidou 30 | mybatis-plus-boot-starter 31 | 32 | 33 | 34 | com.baomidou 35 | mybatis-plus-generator 36 | 37 | 38 | 39 | org.apache.velocity 40 | velocity-engine-core 41 | 42 | 43 | 44 | org.freemarker 45 | freemarker 46 | 47 | 48 | 49 | mysql 50 | mysql-connector-java 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-starter-data-redis 56 | 57 | 58 | 59 | com.h2t.study 60 | redis-like-model 61 | 62 | 63 | 64 | com.h2t.study 65 | redis-like-dao 66 | 67 | 68 | 69 | com.h2t.study 70 | redis-like-common 71 | 72 | 73 | 74 | org.springframework.boot 75 | spring-boot-starter-quartz 76 | 77 | 78 | -------------------------------------------------------------------------------- /redis-like-service/redis-like-service.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/config/MyBatisPlusConfig.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.config; 2 | 3 | import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.context.annotation.Configuration; 6 | 7 | /** 8 | * mybatis plus配置类 9 | * 10 | * @author hetiantian 11 | * @version 1.0 12 | * @Date 2019/08/02 16:11 13 | */ 14 | @Configuration 15 | public class MyBatisPlusConfig { 16 | // mybatis-plus分页插件 17 | @Bean 18 | public PaginationInterceptor paginationInterceptor() { 19 | return new PaginationInterceptor(); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/enums/ErrorCodeEnum.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.enums; 2 | 3 | /** 4 | * 错误代码枚举类 5 | * 6 | * @author hetiantian 7 | * @version 1.0 8 | * @Date 2019/08/01 16:51 9 | */ 10 | public enum ErrorCodeEnum { 11 | /** 12 | * 错误码 13 | */ 14 | Param_does_not_exist("0001", "查找参数不存在"), 15 | Param_does_not_correct("0002", "所传参数格式不正确"), 16 | Param_can_not_null("0003", "传参不为null"), 17 | Object_can_not_found("0004", "查找对象不存在"), 18 | Unlike_article_not_exist("0005", "该文章未被当前用户点赞"), 19 | Like_article_is_exist("0006", "该文章已被当前用户点赞,重复点赞"); 20 | 21 | ErrorCodeEnum(String errorCode, String errorMsg) { 22 | this.errorCode = errorCode; 23 | this.errorMsg = errorMsg; 24 | } 25 | 26 | /** 27 | * 错误码 28 | */ 29 | private String errorCode; 30 | 31 | /** 32 | * 错误信息 33 | */ 34 | private String errorMsg; 35 | 36 | public String getErrorCode() { 37 | return errorCode; 38 | } 39 | 40 | public void setErrorCode(String errorCode) { 41 | this.errorCode = errorCode; 42 | } 43 | 44 | public String getErrorMsg() { 45 | return errorMsg; 46 | } 47 | 48 | public void setErrorMsg(String errorMsg) { 49 | this.errorMsg = errorMsg; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/exception/CustomException.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.exception; 2 | 3 | import com.h2t.study.enums.ErrorCodeEnum; 4 | 5 | /** 6 | * 自定义异常类 7 | * 8 | * @author hetiantian 9 | * @version 1.0 10 | * @Date 2019/08/01 16:24 11 | */ 12 | public class CustomException extends RuntimeException { 13 | /** 14 | * 错误码 15 | */ 16 | private ErrorCodeEnum errorCodeEnum; 17 | 18 | public CustomException(ErrorCodeEnum errorCodeEnum) { 19 | this.errorCodeEnum = errorCodeEnum; 20 | } 21 | 22 | public ErrorCodeEnum getErrorCodeEnum() { 23 | return errorCodeEnum; 24 | } 25 | 26 | public void setErrorCodeEnum(ErrorCodeEnum errorCodeEnum) { 27 | this.errorCodeEnum = errorCodeEnum; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return "CustomException{" + 33 | "errorCodeEnum=" + errorCodeEnum + 34 | '}'; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/generator/MpGenerator.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.generator; 2 | 3 | import com.baomidou.mybatisplus.generator.AutoGenerator; 4 | import com.baomidou.mybatisplus.generator.InjectionConfig; 5 | import com.baomidou.mybatisplus.generator.config.*; 6 | import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert; 7 | import com.baomidou.mybatisplus.generator.config.rules.DbColumnType; 8 | import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy; 9 | import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine; 10 | 11 | /** 12 | * 代码生成器 13 | * 14 | * @author hetiantian 15 | * @version 1.0 16 | * @Date 2019/08/05 11:52 17 | */ 18 | public class MpGenerator { 19 | /** 20 | * 包名 21 | */ 22 | private static final String PACKAGE_NAME = "com.h2t.study"; 23 | 24 | /** 25 | * 代码生成路径 26 | */ 27 | private static final String OUTPUT_DIR = "mp-generator-output"; 28 | 29 | /** 30 | * 代码注释作者 31 | */ 32 | private static final String AUTHOR = "hetiantian"; 33 | 34 | private static final String DRIVER_NAME = "com.mysql.cj.jdbc.Driver"; 35 | private static final String HOST = "localhost"; 36 | private static final String PORT = "3306"; 37 | /** 38 | * 数据库信息 39 | */ 40 | private static final String DATABASE = "article-like"; 41 | private static final String USERNAME = "root"; 42 | private static final String PASSWORD = "123456"; 43 | private static final String URL = "jdbc:mysql://" + HOST + ":" + PORT + "/" + DATABASE 44 | + "?characterEncoding=UTF8&serverTimezone=UTC"; 45 | 46 | public static void main(String[] args) { 47 | // 代码生成器 48 | AutoGenerator mpg = new AutoGenerator(); 49 | mpg.setGlobalConfig(buildGlobalConfig()); 50 | // 数据源配置 51 | mpg.setDataSource(buildDataSourceConfig()); 52 | // 包配置 53 | mpg.setPackageInfo(buildPackageConfig()); 54 | // 自定义配置 55 | InjectionConfig cfg = new InjectionConfig() { 56 | @Override 57 | public void initMap() { 58 | // to do nothing 59 | } 60 | }; 61 | mpg.setCfg(cfg); 62 | // 配置模板 63 | TemplateConfig templateConfig = new TemplateConfig(); 64 | //不生成mapper xml文件 65 | //templateConfig.setXml(null); 66 | mpg.setTemplate(templateConfig); 67 | // 策略配置 68 | mpg.setStrategy(buildStrategyConfig()); 69 | mpg.setTemplateEngine(new FreemarkerTemplateEngine()); 70 | mpg.execute(); 71 | } 72 | 73 | /** 74 | * 全局构造配置类 75 | * 76 | * @return 77 | */ 78 | private static GlobalConfig buildGlobalConfig() { 79 | // 全局配置 80 | GlobalConfig gc = new GlobalConfig(); 81 | //项目所在地址 82 | gc.setOutputDir(OUTPUT_DIR); 83 | //注释作者 84 | gc.setAuthor(AUTHOR); 85 | //生成文件不打开 86 | gc.setOpen(false); 87 | gc.setFileOverride(true); 88 | gc.setActiveRecord(true); 89 | // XML 二级缓存 90 | gc.setEnableCache(false); 91 | //生成result map 92 | // XML ResultMap 93 | gc.setBaseResultMap(true); 94 | //生成java mysql字段映射 95 | // XML columList 96 | gc.setBaseColumnList(true); 97 | // gc.setSwagger2(true); 实体属性 Swagger2 注解 98 | // 自定义文件命名,注意 %s 会自动填充表实体属性! 99 | gc.setMapperName("%sMapper"); 100 | gc.setXmlName("%sMapper"); 101 | gc.setServiceName("%sService"); 102 | gc.setServiceImplName("%sServiceImpl"); 103 | gc.setControllerName("%sController"); 104 | return gc; 105 | } 106 | 107 | /** 108 | * 数据库配置信息 109 | * 110 | * @return 111 | */ 112 | private static DataSourceConfig buildDataSourceConfig() { 113 | DataSourceConfig dsc = new DataSourceConfig(); 114 | dsc.setUrl(URL); 115 | // dsc.setSchemaName("public"); 116 | dsc.setDriverName(DRIVER_NAME); 117 | dsc.setUsername(USERNAME); 118 | dsc.setPassword(PASSWORD); 119 | dsc.setTypeConvert(new MySqlTypeConvert() { 120 | @Override 121 | public DbColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) { 122 | //将数据库中timestamp转换成date 123 | if (fieldType.toLowerCase().contains("timestamp")) { 124 | return DbColumnType.DATE; 125 | } 126 | return (DbColumnType) super.processTypeConvert(globalConfig, fieldType); 127 | } 128 | }); 129 | return dsc; 130 | } 131 | 132 | private static PackageConfig buildPackageConfig() { 133 | PackageConfig pc = new PackageConfig(); 134 | //pc.setModuleName(scanner("模块名")); 135 | pc.setParent(PACKAGE_NAME); 136 | pc.setEntity("po"); 137 | pc.setXml("mapper"); 138 | pc.setController("controller"); 139 | pc.setService("service"); 140 | return pc; 141 | } 142 | 143 | private static StrategyConfig buildStrategyConfig() { 144 | StrategyConfig strategy = new StrategyConfig(); 145 | // 命名规则 146 | strategy.setNaming(NamingStrategy.underline_to_camel); 147 | strategy.setColumnNaming(NamingStrategy.underline_to_camel); 148 | 149 | // 默认生成的po类不继承,手动修改继承 150 | //strategy.setSuperEntityClass((String) null); 151 | // 实体是否使用Lombok插件 152 | strategy.setEntityLombokModel(false); 153 | // 自定义 service 父类 154 | strategy.setSuperServiceClass(String.format("%s.service.BaseService", PACKAGE_NAME)); 155 | // 自定义 service 实现类父类 156 | strategy.setSuperServiceImplClass(String.format("%s.service.impl.BaseServiceImpl", PACKAGE_NAME)); 157 | // 控制层是否使用Rest风格 158 | strategy.setRestControllerStyle(true); 159 | return strategy; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/generator/README.md: -------------------------------------------------------------------------------- 1 | 生成`controller`、`service`、`po`、`dao`层代码,生成的代码只需极小的改动就可以使用了, 2 | 提高了开发效率 3 | 只需要初始化几个字段值就可以了 4 | - PACKAGE_NAME 5 | 生成代码的包名,和项目的包名一致,负责复制过去代码会有一些小问题 6 | - OUTPUT_DIR 7 | 生成代码保存文件地址,默认保存在项目下的mp-generator-output文件夹下,可以修改为自定义保存地址 8 | - AUTHOR 9 | 注释中作者的名字 10 | - DRIVER_NAME 11 | 数据库驱动 12 | - HOST 13 | 数据库主机号 14 | - PORT 15 | 数据库端口 16 | - DATABASE 17 | 数据库名字 18 | - USERNAME 19 | 数据库用户名 20 | - PASSWORD 21 | 数据库密码 22 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/ArticleService.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service; 2 | 3 | import com.h2t.study.po.Article; 4 | 5 | /** 6 | *

7 | * 服务类 8 | *

9 | * 10 | * @author hetiantian 11 | * @since 2019-10-08 12 | */ 13 | public interface ArticleService extends BaseService
{ 14 | 15 | } 16 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/BaseService.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service; 2 | 3 | import com.baomidou.mybatisplus.core.metadata.IPage; 4 | import com.baomidou.mybatisplus.extension.service.IService; 5 | 6 | import java.util.Collection; 7 | import java.util.List; 8 | 9 | /** 10 | * @Description: 基本业务类接口 11 | * @Author: hetiantian 12 | * @Date:2019/8/3 11:46 13 | * @Version: 1.0 14 | */ 15 | public interface BaseService extends IService { 16 | /** 17 | * 添加 18 | * 19 | * @param obj 20 | * @return 21 | */ 22 | boolean insert(T obj); 23 | 24 | /** 25 | * 批量添加 26 | * 27 | * @param objList 28 | * @return 29 | */ 30 | boolean insertBatch(List objList); 31 | 32 | /** 33 | * 根据id删除 34 | */ 35 | boolean modifyById(T obj); 36 | 37 | /** 38 | * 根据传入参数条件进行删除 39 | * 40 | * @param obj 41 | * @return 42 | */ 43 | boolean delete(T obj); 44 | 45 | /** 46 | * 批量删除 47 | * 48 | * @param idList 49 | * @return 50 | */ 51 | boolean deleteByIds(List idList); 52 | 53 | /** 54 | * 批量id删除 55 | * 56 | * @param id 57 | * @return 58 | */ 59 | boolean deleteById(Long id); 60 | 61 | /** 62 | * 根据id查找 63 | */ 64 | T selectById(Long id); 65 | 66 | /** 67 | * 根据条件进行查询 68 | * 69 | * @param obj 70 | * @return 71 | */ 72 | List selectList(T obj); 73 | 74 | /** 75 | * 根据id批量查询 76 | * 77 | * @param idList 78 | * @return 79 | */ 80 | Collection selectByIds(List idList); 81 | 82 | /** 83 | * 分页查询 84 | * 85 | * @param pageNo 页码 86 | * @param pageSize 页数 87 | * @param obj 88 | * @return 89 | */ 90 | IPage selectPage(T obj, Integer pageNo, Integer pageSize); 91 | 92 | /** 93 | * 根据条件查询指定结果,结果只有一个 94 | * 95 | * @param obj 96 | * @return 97 | */ 98 | T selectOne(T obj); 99 | } 100 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/RedisService.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * redis服务接口 7 | * 8 | * @author hetiantian 9 | * @version 1.0 10 | * @Date 2019/09/29 16:10 11 | */ 12 | public interface RedisService { 13 | /** 14 | * 用户点赞某篇文章 15 | * 16 | * @param likedUserId 被点赞用户ID 17 | * @param likedPostId 点赞用户 18 | * @param articleId 文章ID 19 | */ 20 | void likeArticle(Long articleId, Long likedUserId, Long likedPostId); 21 | 22 | /** 23 | * 取消点赞 24 | * 25 | * @param likedUserId 被点赞用户ID 26 | * @param likedPostId 点赞用户 27 | * @param articleId 文章ID 28 | */ 29 | void unlikeArticle(Long articleId, Long likedUserId, Long likedPostId); 30 | 31 | /** 32 | * 统计某篇文章总点赞数 33 | * 34 | * @param articleId 35 | * @return 36 | */ 37 | Long countArticleLike(Long articleId); 38 | 39 | /** 40 | * 统计用户总的文章点赞数 41 | * 42 | * @param likedUserId 43 | * @return 44 | */ 45 | Long countUserLike(Long likedUserId); 46 | 47 | /** 48 | * 获取用户点赞的文章 49 | * 50 | * @param likedPostId 点赞用户ID 51 | * @return 52 | */ 53 | List getUserLikeArticleIds(Long likedPostId); 54 | } 55 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/UserLikeArticleService.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service; 2 | 3 | import com.h2t.study.po.UserLikeArticle; 4 | 5 | /** 6 | *

7 | * 服务类 8 | *

9 | * 10 | * @author hetiantian 11 | * @since 2019-10-08 12 | */ 13 | public interface UserLikeArticleService extends BaseService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service; 2 | 3 | import com.h2t.study.po.User; 4 | 5 | /** 6 | *

7 | * 服务类 8 | *

9 | * 10 | * @author hetiantian 11 | * @since 2019-10-08 12 | */ 13 | public interface UserService extends BaseService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/impl/ArticleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service.impl; 2 | 3 | import com.h2t.study.mapper.ArticleMapper; 4 | import com.h2t.study.po.Article; 5 | import com.h2t.study.service.ArticleService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | *

10 | * 服务实现类 11 | *

12 | * 13 | * @author hetiantian 14 | * @since 2019-10-08 15 | */ 16 | @Service 17 | public class ArticleServiceImpl extends BaseServiceImpl implements ArticleService { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/impl/BaseServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service.impl; 2 | 3 | import com.baomidou.mybatisplus.core.conditions.Wrapper; 4 | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; 5 | import com.baomidou.mybatisplus.core.mapper.BaseMapper; 6 | import com.baomidou.mybatisplus.core.metadata.IPage; 7 | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 8 | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 9 | import com.h2t.study.service.BaseService; 10 | 11 | import java.util.Collection; 12 | import java.util.List; 13 | 14 | /** 15 | * @Description: 基本业务实现类 16 | * @Author: hetiantian 17 | * @Date:2019/8/3 11:54 18 | * @Version: 1.0 19 | */ 20 | public class BaseServiceImpl, T> extends ServiceImpl implements BaseService { 21 | 22 | /** 23 | * 添加 24 | * 25 | * @param obj 26 | * @return 27 | */ 28 | public boolean insert(T obj) { 29 | return this.save(obj); 30 | } 31 | 32 | /** 33 | * 批量添加 34 | * 35 | * @param objList 36 | * @return 37 | */ 38 | public boolean insertBatch(List objList) { 39 | return this.saveBatch(objList); 40 | } 41 | 42 | 43 | /** 44 | * 根据id删除 45 | * 46 | * @param obj 47 | */ 48 | public boolean modifyById(T obj) { 49 | return this.updateById(obj); 50 | } 51 | 52 | /** 53 | * 根据传入参数条件进行删除 54 | * 55 | * @param obj 56 | * @return 57 | */ 58 | public boolean delete(T obj) { 59 | Wrapper wrapper = new QueryWrapper(obj); 60 | return this.remove(wrapper); 61 | } 62 | 63 | /** 64 | * 批量删除 65 | * 66 | * @param idList 67 | * @return 68 | */ 69 | public boolean deleteByIds(List idList) { 70 | return this.removeByIds(idList); 71 | } 72 | 73 | /** 74 | * 批量id删除 75 | * 76 | * @param id 77 | * @return 78 | */ 79 | public boolean deleteById(Long id) { 80 | return this.removeById(id); 81 | } 82 | 83 | /** 84 | * 根据id进行更新 85 | * 86 | * @param obj 87 | * @return 88 | * */ 89 | // @Override 90 | // public boolean modify(T obj) { 91 | // Wrapper wrapper = new QueryWrapper<>(obj); 92 | // return this.update(wrapper); 93 | // } 94 | 95 | /** 96 | * 根据id查找 97 | * 98 | * @param id 99 | */ 100 | public T selectById(Long id) { 101 | return this.getById(id); 102 | } 103 | 104 | /** 105 | * 根据条件进行查询 106 | * 107 | * @param obj 108 | * @return 109 | */ 110 | public List selectList(T obj) { 111 | Wrapper wrapper = new QueryWrapper<>(obj); 112 | return this.list(wrapper); 113 | } 114 | 115 | /** 116 | * 根据id批量查询 117 | * 118 | * @param idList 119 | * @return 120 | */ 121 | public Collection selectByIds(List idList) { 122 | return this.listByIds(idList); 123 | } 124 | 125 | /** 126 | * 分页查询 127 | * 128 | * @param pageNo 页码 129 | * @param pageSize 页数 130 | * @param obj 131 | * @return 132 | */ 133 | public IPage selectPage(T obj, Integer pageNo, Integer pageSize) { 134 | Page page = new Page(pageNo, pageSize); 135 | Wrapper wrapper = new QueryWrapper(obj); 136 | return this.page(page, wrapper); 137 | } 138 | 139 | /** 140 | * 根据条件查询指定结果,结果只有一个 141 | * 142 | * @param obj 143 | * @return 144 | */ 145 | public T selectOne(T obj) { 146 | Wrapper wrapper = new QueryWrapper<>(obj); 147 | return this.getOne(wrapper); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/impl/RedisServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service.impl; 2 | 3 | import com.h2t.study.enums.ErrorCodeEnum; 4 | import com.h2t.study.exception.CustomException; 5 | import com.h2t.study.service.RedisService; 6 | import com.h2t.study.util.FastjsonUtil; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Value; 10 | import org.springframework.data.redis.core.RedisTemplate; 11 | import org.springframework.data.redis.serializer.RedisSerializer; 12 | import org.springframework.data.redis.serializer.StringRedisSerializer; 13 | import org.springframework.stereotype.Service; 14 | 15 | import javax.annotation.PostConstruct; 16 | import javax.annotation.Resource; 17 | import java.util.HashSet; 18 | import java.util.List; 19 | import java.util.Set; 20 | import java.util.stream.Collectors; 21 | 22 | /** 23 | * redis服务实现类 24 | * 25 | * @author hetiantian 26 | * @version 1.0 27 | * @Date 2019/09/29 16:05 28 | */ 29 | @Service 30 | public class RedisServiceImpl implements RedisService { 31 | Logger logger = LoggerFactory.getLogger(RedisServiceImpl.class); 32 | 33 | /** 34 | * 文章点赞总数key 35 | * redis key命名规范推荐使用大写,单词与单词之间使用: 36 | */ 37 | @Value("${total.like.count.key}") 38 | private String TOTAL_LIKE_COUNT_KEY; 39 | 40 | /** 41 | * 用户点赞文章key 42 | */ 43 | @Value("${user.like.article.key}") 44 | private String USER_LIKE_ARTICLE_KEY; 45 | 46 | /** 47 | * 文章被点赞的key 48 | */ 49 | @Value("${article.liked.user.key}") 50 | private String ARTICLE_LIKED_USER_KEY; 51 | 52 | @Resource 53 | private RedisTemplate redisTemplate; 54 | 55 | /** 56 | * 指定序列化方式 57 | */ 58 | @PostConstruct 59 | public void init() { 60 | RedisSerializer redisSerializer = new StringRedisSerializer(); 61 | redisTemplate.setKeySerializer(redisSerializer); 62 | redisTemplate.setValueSerializer(redisSerializer); 63 | redisTemplate.setHashKeySerializer(redisSerializer); 64 | redisTemplate.setHashValueSerializer(redisSerializer); 65 | } 66 | 67 | /** 68 | * 用户点赞某篇文章 69 | * 70 | * @param likedUserId 被点赞用户ID 71 | * @param likedPostId 点赞用户 72 | * @param articleId 文章ID 73 | */ 74 | public void likeArticle(Long articleId, Long likedUserId, Long likedPostId) { 75 | validateParam(articleId, likedUserId, likedPostId); //参数验证 76 | 77 | logger.info("点赞数据存入redis开始,articleId:{},likedUserId:{},likedPostId:{}", articleId, likedUserId, likedPostId); 78 | 79 | //只有未点赞的用户才可以进行点赞 80 | likeArticleLogicValidate(articleId, likedUserId, likedPostId); 81 | //1.用户总点赞数+1 82 | redisTemplate.opsForHash().increment(TOTAL_LIKE_COUNT_KEY, String.valueOf(likedUserId), 1); 83 | synchronized (this) { 84 | //2.用户喜欢的文章+1 85 | String userLikeResult = (String) redisTemplate.opsForHash().get(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId)); 86 | Set articleIdSet = userLikeResult == null ? new HashSet<>() : FastjsonUtil.deserializeToSet(userLikeResult, Long.class); 87 | articleIdSet.add(articleId); 88 | redisTemplate.opsForHash().put(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId), FastjsonUtil.serialize(articleIdSet)); 89 | 90 | //3.文章点赞数+1 91 | String articleLikedResult = (String) redisTemplate.opsForHash().get(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId)); 92 | Set likePostIdSet = articleLikedResult == null ? new HashSet<>() : FastjsonUtil.deserializeToSet(articleLikedResult, Long.class); 93 | likePostIdSet.add(likedPostId); 94 | redisTemplate.opsForHash().put(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId), FastjsonUtil.serialize(likePostIdSet)); 95 | logger.info("取消点赞数据存入redis结束,articleId:{},likedUserId:{},likedPostId:{}", articleId, likedUserId, likedPostId); 96 | } 97 | } 98 | 99 | /** 100 | * 取消点赞 101 | * 102 | * @param likedUserId 被点赞用户ID 103 | * @param likedPostId 点赞用户 104 | * @param articleId 文章ID 105 | */ 106 | public void unlikeArticle(Long articleId, Long likedUserId, Long likedPostId) { 107 | validateParam(articleId, likedUserId, likedPostId); //参数校验 108 | 109 | logger.info("取消点赞数据存入redis开始,articleId:{},likedUserId:{},likedPostId:{}", articleId, likedUserId, likedPostId); 110 | //1.用户总点赞数-1 111 | synchronized (this) { 112 | //只有点赞的用户才可以取消点赞 113 | unlikeArticleLogicValidate(articleId, likedUserId, likedPostId); 114 | Long totalLikeCount = Long.parseLong((String) redisTemplate.opsForHash().get(TOTAL_LIKE_COUNT_KEY, String.valueOf(likedUserId))); 115 | redisTemplate.opsForHash().put(TOTAL_LIKE_COUNT_KEY, String.valueOf(likedUserId), String.valueOf(--totalLikeCount)); 116 | 117 | //2.用户喜欢的文章-1 118 | String userLikeResult = (String) redisTemplate.opsForHash().get(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId)); 119 | Set articleIdSet = FastjsonUtil.deserializeToSet(userLikeResult, Long.class); 120 | articleIdSet.remove(articleId); 121 | redisTemplate.opsForHash().put(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId), FastjsonUtil.serialize(articleIdSet)); 122 | 123 | //3.取消用户某篇文章的点赞数 124 | String articleLikedResult = (String) redisTemplate.opsForHash().get(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId)); 125 | Set likePostIdSet = FastjsonUtil.deserializeToSet(articleLikedResult, Long.class); 126 | likePostIdSet.remove(likedPostId); 127 | redisTemplate.opsForHash().put(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId), FastjsonUtil.serialize(likePostIdSet)); 128 | } 129 | 130 | logger.info("取消点赞数据存入redis结束,articleId:{},likedUserId:{},likedPostId:{}", articleId, likedUserId, likedPostId); 131 | } 132 | 133 | /** 134 | * 统计某篇文章总点赞数 135 | * 136 | * @param articleId 文章ID 137 | * @return 138 | */ 139 | public synchronized Long countArticleLike(Long articleId) { 140 | validateParam(articleId); 141 | String articleLikedResult = (String) redisTemplate.opsForHash().get(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId)); 142 | Set likePostIdSet = FastjsonUtil.deserializeToSet(articleLikedResult, Long.class); 143 | if (likePostIdSet == null) { 144 | return 0L; 145 | } 146 | return new Long(likePostIdSet.size()); 147 | } 148 | 149 | /** 150 | * 统计用户总的文章点赞数 151 | * 152 | * @param likedUserId 153 | * @return 154 | */ 155 | public synchronized Long countUserLike(Long likedUserId) { 156 | validateParam(likedUserId); 157 | return Long.parseLong((String) redisTemplate.opsForHash().get(TOTAL_LIKE_COUNT_KEY, String.valueOf(likedUserId))); 158 | } 159 | 160 | /** 161 | * 获取用户点赞的文章 162 | * 163 | * @param likedPostId 164 | * @return 165 | */ 166 | public List getUserLikeArticleIds(Long likedPostId) { 167 | validateParam(likedPostId); 168 | String userLikeResult = (String) redisTemplate.opsForHash().get(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId)); 169 | Set articleIdSet = FastjsonUtil.deserializeToSet(userLikeResult, Long.class); 170 | 171 | return articleIdSet.stream().collect(Collectors.toList()); 172 | } 173 | 174 | /** 175 | * 入参验证 176 | * 177 | * @param params 178 | * @throws CustomException 179 | */ 180 | private void validateParam(Long... params) { 181 | for (Long param : params) { 182 | if (null == param) { 183 | logger.error("入参存在null值"); 184 | throw new CustomException(ErrorCodeEnum.Param_can_not_null); 185 | } 186 | } 187 | } 188 | 189 | /** 190 | * 点赞文章逻辑校验 191 | * 192 | * @throws 193 | */ 194 | private void likeArticleLogicValidate(Long articleId, Long likedUserId, Long likedPostId) { 195 | Set articleIdSet = FastjsonUtil.deserializeToSet((String) redisTemplate.opsForHash().get(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId)), Long.class); 196 | Set likePostIdSet = FastjsonUtil.deserializeToSet((String) redisTemplate.opsForHash().get(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId)), Long.class); 197 | if (articleIdSet == null) { 198 | return; 199 | } 200 | if (likePostIdSet == null) { 201 | return; 202 | } else { 203 | if (articleIdSet.contains(articleId) || likePostIdSet.contains(likedPostId)) { 204 | logger.error("该文章已被当前用户点赞,重复点赞,articleId:{},likedUserId:{},likedPostId:{}", articleId, likedUserId, likedPostId); 205 | throw new CustomException(ErrorCodeEnum.Like_article_is_exist); 206 | } 207 | } 208 | } 209 | 210 | /** 211 | * 取消点赞逻辑校验 212 | */ 213 | private void unlikeArticleLogicValidate(Long articleId, Long likedUserId, Long likedPostId) { 214 | Set articleIdSet = FastjsonUtil.deserializeToSet((String) redisTemplate.opsForHash().get(USER_LIKE_ARTICLE_KEY, String.valueOf(likedPostId)), Long.class); 215 | Set likePostIdSet = FastjsonUtil.deserializeToSet((String) redisTemplate.opsForHash().get(ARTICLE_LIKED_USER_KEY, String.valueOf(articleId)), Long.class); 216 | if (articleIdSet == null || !articleIdSet.contains(articleId) 217 | || likePostIdSet == null || !likePostIdSet.contains(likedPostId)) { 218 | logger.error("该文章未被当前用户点赞,不可以进行取消点赞操作,articleId:{},likedUserId:{},likedPostId:{}", 219 | articleId, likedUserId, likedPostId); 220 | throw new CustomException(ErrorCodeEnum.Unlike_article_not_exist); 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/impl/UserLikeArticleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service.impl; 2 | 3 | import com.h2t.study.mapper.UserLikeArticleMapper; 4 | import com.h2t.study.po.UserLikeArticle; 5 | import com.h2t.study.service.UserLikeArticleService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | *

10 | * 服务实现类 11 | *

12 | * 13 | * @author hetiantian 14 | * @since 2019-10-08 15 | */ 16 | @Service 17 | public class UserLikeArticleServiceImpl extends BaseServiceImpl implements UserLikeArticleService { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.service.impl; 2 | 3 | import com.h2t.study.mapper.UserMapper; 4 | import com.h2t.study.po.User; 5 | import com.h2t.study.service.UserService; 6 | import org.springframework.stereotype.Service; 7 | 8 | /** 9 | *

10 | * 服务实现类 11 | *

12 | * 13 | * @author hetiantian 14 | * @since 2019-10-08 15 | */ 16 | @Service 17 | public class UserServiceImpl extends BaseServiceImpl implements UserService { 18 | 19 | } 20 | -------------------------------------------------------------------------------- /redis-like-service/src/main/java/com/h2t/study/task/ScheduleTask.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.task; 2 | 3 | import com.h2t.study.enums.ErrorCodeEnum; 4 | import com.h2t.study.exception.CustomException; 5 | import com.h2t.study.po.Article; 6 | import com.h2t.study.po.UserLikeArticle; 7 | import com.h2t.study.service.ArticleService; 8 | import com.h2t.study.service.UserLikeArticleService; 9 | import com.h2t.study.util.FastjsonUtil; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Value; 13 | import org.springframework.data.redis.core.RedisTemplate; 14 | import org.springframework.scheduling.annotation.Scheduled; 15 | import org.springframework.stereotype.Service; 16 | 17 | import javax.annotation.Resource; 18 | import java.time.LocalDateTime; 19 | import java.time.format.DateTimeFormatter; 20 | import java.util.Map; 21 | import java.util.Set; 22 | 23 | /** 24 | * 定时落库任务 25 | * 26 | * @author hetiantian 27 | * @version 1.0 28 | * @Date 2019/10/08 16:17 29 | */ 30 | @Service 31 | public class ScheduleTask { 32 | private Logger logger = LoggerFactory.getLogger(ScheduleTask.class); 33 | 34 | private DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); 35 | 36 | /** 37 | * 用户点赞文章key 38 | */ 39 | @Value("${user.like.article.key}") 40 | private String USER_LIKE_ARTICLE_KEY; 41 | 42 | /** 43 | * 文章被点赞的key 44 | */ 45 | @Value("${article.liked.user.key}") 46 | private String ARTICLE_LIKED_USER_KEY; 47 | 48 | @Resource 49 | private ArticleService articleService; 50 | 51 | @Resource 52 | private UserLikeArticleService userLikeArticleService; 53 | 54 | @Resource 55 | private RedisTemplate redisTemplate; 56 | 57 | @Scheduled(cron = "0 0 0/1 * * ? ") 58 | public void redisDataToMySQL() { 59 | logger.info("time:{},开始执行Redis数据持久化到MySQL任务", LocalDateTime.now().format(formatter)); 60 | //1.更新文章总的点赞数 61 | Map articleCountMap = redisTemplate.opsForHash().entries(ARTICLE_LIKED_USER_KEY); 62 | for (Map.Entry entry : articleCountMap.entrySet()) { 63 | String articleId = entry.getKey(); 64 | Set userIdSet = FastjsonUtil.deserializeToSet(entry.getValue(), Long.class); 65 | //1.同步某篇文章总的点赞数到MySQL 66 | synchronizeTotalLikeCount(articleId, userIdSet); 67 | //2.同步用户喜欢的文章 68 | synchronizeUserLikeArticle(articleId, userIdSet); 69 | } 70 | logger.info("time:{},结束执行Redis数据持久化到MySQL任务", LocalDateTime.now().format(formatter)); 71 | } 72 | 73 | /** 74 | * 同步某篇文章总的点赞数到MySQL 75 | */ 76 | private void synchronizeTotalLikeCount(String articleId, Set userIdSet) { 77 | Long totalLikeCount = new Long(userIdSet.size()); 78 | Article article = buildArticle(totalLikeCount, articleId); 79 | articleService.modifyById(article); 80 | } 81 | 82 | /** 83 | * 同步用户喜欢的文章 84 | * 85 | * @param articleId 86 | * @param userIdSet 87 | */ 88 | private void synchronizeUserLikeArticle(String articleId, Set userIdSet) { 89 | for (Long userId : userIdSet) { 90 | UserLikeArticle userLikeArticle = buildUserLikeArticle(articleId, userId); 91 | if (userLikeArticleService.selectOne(userLikeArticle) == null) { 92 | userLikeArticleService.insert(userLikeArticle); 93 | } 94 | } 95 | } 96 | 97 | /** 98 | * 构造UserLikeArticle对象 99 | * 100 | * @param articleId 101 | * @param userId 102 | * @return 103 | */ 104 | private UserLikeArticle buildUserLikeArticle(String articleId, Long userId) { 105 | UserLikeArticle userLikeArticle = new UserLikeArticle(); 106 | userLikeArticle.setArticleId(Long.parseLong(articleId)); 107 | userLikeArticle.setUserId(userId); 108 | 109 | return userLikeArticle; 110 | } 111 | 112 | /** 113 | * 构造Article对象 114 | * 115 | * @param articleId 116 | * @param totalLikeCount 117 | * @return 118 | */ 119 | private Article buildArticle(Long totalLikeCount, String articleId) { 120 | Article article = new Article(); 121 | article.setId(Long.parseLong(articleId)); 122 | article.setTotalLikeCount(totalLikeCount); 123 | 124 | return article; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/config/MyBatisPlusConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/config/MyBatisPlusConfig.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/enums/ErrorCodeEnum.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/enums/ErrorCodeEnum.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/exception/CustomException.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/exception/CustomException.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/generator/MpGenerator$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/generator/MpGenerator$1.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/generator/MpGenerator$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/generator/MpGenerator$2.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/generator/MpGenerator.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/generator/MpGenerator.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/ArticleService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/ArticleService.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/BaseService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/BaseService.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/RedisService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/RedisService.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/UserLikeArticleService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/UserLikeArticleService.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/UserService.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/UserService.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/impl/ArticleServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/impl/ArticleServiceImpl.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/impl/BaseServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/impl/BaseServiceImpl.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/impl/RedisServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/impl/RedisServiceImpl.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/impl/UserLikeArticleServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/impl/UserLikeArticleServiceImpl.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/service/impl/UserServiceImpl.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/service/impl/UserServiceImpl.class -------------------------------------------------------------------------------- /redis-like-service/target/classes/com/h2t/study/task/ScheduleTask.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-service/target/classes/com/h2t/study/task/ScheduleTask.class -------------------------------------------------------------------------------- /redis-like-web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 4.0.0 7 | 8 | com.h2t.study 9 | redis-like 10 | 1.0.0-SNAPSHOT 11 | 12 | 13 | redis-like-web 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter 19 | 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-web 24 | 25 | 26 | 27 | com.h2t.study 28 | redis-like-service 29 | 30 | 31 | 32 | mysql 33 | mysql-connector-java 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-aop 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-quartz 44 | 45 | 46 | -------------------------------------------------------------------------------- /redis-like-web/redis-like-web.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /redis-like-web/src/main/java/com/h2t/study/Runner.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.scheduling.annotation.EnableScheduling; 6 | import org.springframework.transaction.annotation.EnableTransactionManagement; 7 | 8 | /** 9 | * 项目启动类 10 | */ 11 | @SpringBootApplication 12 | @EnableScheduling 13 | public class Runner { 14 | public static void main(String[] args) { 15 | SpringApplication.run(Runner.class, args); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /redis-like-web/src/main/java/com/h2t/study/aspect/ResponseAspect.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.aspect; 2 | 3 | import com.h2t.study.response.BaseResponse; 4 | import org.aspectj.lang.ProceedingJoinPoint; 5 | import org.aspectj.lang.annotation.Around; 6 | import org.aspectj.lang.annotation.Aspect; 7 | import org.springframework.stereotype.Component; 8 | 9 | /** 10 | * 统一返回结果切面 11 | * 12 | * @author hetiantian 13 | * @version 1.0 14 | * @Date 2019/08/02 9:56 15 | */ 16 | @Aspect 17 | @Component 18 | public class ResponseAspect { 19 | @Around("execution(* com.h2t.study.controller..*(..))") 20 | public Object controllerProcess(ProceedingJoinPoint pjd) throws Throwable { 21 | Object result = pjd.proceed(); 22 | //如果controller不返回结果 23 | if (result == null) { 24 | return BaseResponse.success(null); 25 | } 26 | 27 | return BaseResponse.success(result); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /redis-like-web/src/main/java/com/h2t/study/controller/ArticleLikeController.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.controller; 2 | 3 | import com.h2t.study.service.ArticleService; 4 | import com.h2t.study.service.RedisService; 5 | import org.springframework.web.bind.annotation.*; 6 | 7 | import javax.annotation.Resource; 8 | 9 | /** 10 | * 点赞文章控制层 11 | * 12 | * @author hetiantian 13 | * @version 1.0 14 | * @Date 2019/09/30 15:31 15 | */ 16 | @RestController 17 | @RequestMapping("/api/article") 18 | public class ArticleLikeController { 19 | @Resource 20 | private RedisService redisService; 21 | 22 | @Resource 23 | private ArticleService articleService; 24 | 25 | /** 26 | * 点赞文章 27 | */ 28 | @PostMapping("/{articleId}/{likedUserId}/{likedPoseId}") 29 | public Object likeArticle(@PathVariable("articleId") Long articleId, 30 | @PathVariable("likedUserId") Long likedUserId, 31 | @PathVariable("likedPoseId") Long likedPoseId) { 32 | redisService.likeArticle(articleId, likedUserId, likedPoseId); 33 | return articleId; 34 | } 35 | 36 | /** 37 | * 取消点赞 38 | */ 39 | @DeleteMapping("/{articleId}/{likedUserId}/{likedPoseId}") 40 | public Object unlikeArticle(@PathVariable("articleId") Long articleId, 41 | @PathVariable("likedUserId") Long likedUserId, 42 | @PathVariable("likedPoseId") Long likedPoseId) { 43 | redisService.unlikeArticle(articleId, likedUserId, likedPoseId); 44 | return articleId; 45 | } 46 | 47 | /** 48 | * 获取用户点赞的文章 49 | */ 50 | @GetMapping("/user/{likedPoseId}/like") 51 | public Object getUserLikeArticle(@PathVariable("likedPoseId") Long likedPoseId) { 52 | return articleService.selectByIds(redisService.getUserLikeArticleIds(likedPoseId)); 53 | } 54 | 55 | /** 56 | * 统计用户总的文章点赞数 57 | */ 58 | @GetMapping("/total/user/{likedUserId}") 59 | public Object countUserLike(@PathVariable("likedUserId") Long likedUserId) { 60 | return redisService.countUserLike(likedUserId); 61 | } 62 | 63 | /** 64 | * 统计某篇文章总点赞数 65 | */ 66 | @GetMapping("/total/article/{articleId}") 67 | public Object countArticleLike(@PathVariable("articleId") Long articleId) { 68 | return redisService.countArticleLike(articleId); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /redis-like-web/src/main/java/com/h2t/study/controller/TestController.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | /** 7 | * 测试类,用于测试项目是否正常构建 8 | * 9 | * @author hetiantian 10 | * @version 1.0 11 | * @Date 2019/08/01 14:23 12 | */ 13 | @RestController 14 | public class TestController { 15 | @GetMapping("/hello") 16 | public Object hello() { 17 | new Thread( 18 | new Runnable() { 19 | @Override 20 | public void run() { 21 | throw new IllegalArgumentException(); 22 | } 23 | } 24 | ).start(); 25 | return "hello world"; 26 | } 27 | 28 | @GetMapping("/test") 29 | public Object test() { 30 | return "test"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /redis-like-web/src/main/java/com/h2t/study/handler/ResponseHandler.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.handler; 2 | 3 | import com.h2t.study.exception.CustomException; 4 | import com.h2t.study.response.BaseResponse; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import org.springframework.http.HttpStatus; 8 | import org.springframework.web.bind.annotation.ControllerAdvice; 9 | import org.springframework.web.bind.annotation.ExceptionHandler; 10 | import org.springframework.web.bind.annotation.ResponseBody; 11 | 12 | import javax.servlet.http.HttpServletRequest; 13 | 14 | /** 15 | * 统一返回结果异常处理类 16 | * 17 | * @author hetiantian 18 | * @version 1.0 19 | * @Date 2019/08/02 10:16 20 | */ 21 | @ControllerAdvice 22 | @ResponseBody 23 | public class ResponseHandler { 24 | private static Logger logger = LoggerFactory.getLogger(ResponseHandler.class); 25 | 26 | @ExceptionHandler({CustomException.class}) 27 | public BaseResponse customException(CustomException e, HttpServletRequest request) { 28 | logger.error(request.getRequestURI() + ":服务运行异常", e); 29 | return BaseResponse.fail(e.getErrorCodeEnum().getErrorCode(), e.getErrorCodeEnum().getErrorMsg()); 30 | } 31 | 32 | @ExceptionHandler({Exception.class}) 33 | public BaseResponse otherResponse(Exception e, HttpServletRequest request) { 34 | logger.error(request.getRequestURI() + ":自定义异常", e); 35 | return BaseResponse.fail(String.valueOf(HttpStatus.INTERNAL_SERVER_ERROR.value()), 36 | e.getMessage()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /redis-like-web/src/main/java/com/h2t/study/response/BaseResponse.java: -------------------------------------------------------------------------------- 1 | package com.h2t.study.response; 2 | 3 | /** 4 | * 统一返回结果 5 | * 6 | * @author hetiantian 7 | * @version 1.0 8 | * @Date 2019/08/01 16:45 9 | */ 10 | public class BaseResponse { 11 | /** 12 | * 返回的data 13 | */ 14 | private T data; 15 | 16 | /** 17 | * 错误码 18 | */ 19 | private String errorCode; 20 | 21 | /** 22 | * 错误信息 23 | */ 24 | private String errorMsg; 25 | 26 | /** 27 | * 是否成功 28 | */ 29 | private boolean success = false; 30 | 31 | /** 32 | * 出现异常的构造函数 33 | */ 34 | public BaseResponse(String errorCode, String errorMsg) { 35 | this.errorCode = errorCode; 36 | this.errorMsg = errorMsg; 37 | } 38 | 39 | /** 40 | * 成功返回的结果 41 | */ 42 | public BaseResponse(T data) { 43 | success = true; 44 | this.data = data; 45 | } 46 | 47 | public static BaseResponse success(T data) { 48 | return new BaseResponse(data); 49 | } 50 | 51 | public static BaseResponse fail(String errorCode, String errorMsg) { 52 | return new BaseResponse(errorCode, errorMsg); 53 | } 54 | 55 | public T getData() { 56 | return data; 57 | } 58 | 59 | public void setData(T data) { 60 | this.data = data; 61 | } 62 | 63 | public String getErrorCode() { 64 | return errorCode; 65 | } 66 | 67 | public void setErrorCode(String errorCode) { 68 | this.errorCode = errorCode; 69 | } 70 | 71 | public String getErrorMsg() { 72 | return errorMsg; 73 | } 74 | 75 | public void setErrorMsg(String errorMsg) { 76 | this.errorMsg = errorMsg; 77 | } 78 | 79 | public boolean isSuccess() { 80 | return success; 81 | } 82 | 83 | public void setSuccess(boolean success) { 84 | this.success = success; 85 | } 86 | 87 | @Override 88 | public String toString() { 89 | return "BaseResponse{" + 90 | "data=" + data + 91 | ", errorCode='" + errorCode + '\'' + 92 | ", errorMsg='" + errorMsg + '\'' + 93 | ", success=" + success + 94 | '}'; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /redis-like-web/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/src/main/resources/application.properties -------------------------------------------------------------------------------- /redis-like-web/src/main/resources/log4j2-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | log/info 6 | log/error 7 | %d [%t] %-5p [%c] - %m%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /redis-like-web/src/main/resources/log4j2.component.properties: -------------------------------------------------------------------------------- 1 | Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -------------------------------------------------------------------------------- /redis-like-web/target/classes/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/application.properties -------------------------------------------------------------------------------- /redis-like-web/target/classes/com/h2t/study/Runner.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/com/h2t/study/Runner.class -------------------------------------------------------------------------------- /redis-like-web/target/classes/com/h2t/study/aspect/ResponseAspect.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/com/h2t/study/aspect/ResponseAspect.class -------------------------------------------------------------------------------- /redis-like-web/target/classes/com/h2t/study/controller/ArticleLikeController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/com/h2t/study/controller/ArticleLikeController.class -------------------------------------------------------------------------------- /redis-like-web/target/classes/com/h2t/study/controller/TestController.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/com/h2t/study/controller/TestController.class -------------------------------------------------------------------------------- /redis-like-web/target/classes/com/h2t/study/handler/ResponseHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/com/h2t/study/handler/ResponseHandler.class -------------------------------------------------------------------------------- /redis-like-web/target/classes/com/h2t/study/response/BaseResponse.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TiantianUpup/like-article/4de68201ef5262845f8f00f494befa346e36b0a1/redis-like-web/target/classes/com/h2t/study/response/BaseResponse.class -------------------------------------------------------------------------------- /redis-like-web/target/classes/log4j2-spring.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | log/info 6 | log/error 7 | %d [%t] %-5p [%c] - %m%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /redis-like-web/target/classes/log4j2.component.properties: -------------------------------------------------------------------------------- 1 | Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -------------------------------------------------------------------------------- /redis-like.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sql/article-like.sql: -------------------------------------------------------------------------------- 1 | /* 2 | SQLyog Ultimate v11.33 (64 bit) 3 | MySQL - 5.7.23-log : Database - article-like 4 | ********************************************************************* 5 | */ 6 | 7 | /*!40101 SET NAMES utf8 */; 8 | 9 | /*!40101 SET SQL_MODE=''*/; 10 | 11 | /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; 12 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 13 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 14 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 15 | CREATE DATABASE /*!32312 IF NOT EXISTS*/`article-like` /*!40100 DEFAULT CHARACTER SET latin1 */; 16 | 17 | USE `article-like`; 18 | 19 | /*Table structure for table `article` */ 20 | 21 | DROP TABLE IF EXISTS `article`; 22 | 23 | CREATE TABLE `article` ( 24 | `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', 25 | `user_id` bigint(20) NOT NULL COMMENT '用户ID', 26 | `article_name` varchar(200) NOT NULL, 27 | `content` blob COMMENT '文章内容', 28 | `total_like_count` bigint(20) NOT NULL DEFAULT '0' COMMENT '文章总点赞数', 29 | `deleted` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否删除', 30 | `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', 31 | `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '生成时间', 32 | PRIMARY KEY (`id`) 33 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 34 | 35 | /*Table structure for table `base` */ 36 | 37 | DROP TABLE IF EXISTS `base`; 38 | 39 | CREATE TABLE `base` ( 40 | `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', 41 | `deleted` tinyint(4) NOT NULL DEFAULT '0', 42 | `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', 43 | `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '生成时间', 44 | PRIMARY KEY (`id`) 45 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 46 | 47 | /*Table structure for table `user` */ 48 | 49 | DROP TABLE IF EXISTS `user`; 50 | 51 | CREATE TABLE `user` ( 52 | `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', 53 | `username` varchar(20) CHARACTER SET latin1 DEFAULT NULL COMMENT '用户名', 54 | `password` varchar(20) CHARACTER SET latin1 DEFAULT NULL COMMENT '密码', 55 | `deleted` tinyint(4) NOT NULL DEFAULT '0', 56 | `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', 57 | `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '生成时间', 58 | PRIMARY KEY (`id`) 59 | ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; 60 | 61 | /*Table structure for table `user_like_article` */ 62 | 63 | DROP TABLE IF EXISTS `user_like_article`; 64 | 65 | CREATE TABLE `user_like_article` ( 66 | `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', 67 | `user_id` bigint(20) NOT NULL COMMENT '用户ID', 68 | `article_id` bigint(20) NOT NULL COMMENT '文章ID', 69 | `deleted` tinyint(4) NOT NULL DEFAULT '0', 70 | `gmt_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间', 71 | `gmt_create` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '生成时间', 72 | PRIMARY KEY (`id`) 73 | ) ENGINE=InnoDB AUTO_INCREMENT=42 DEFAULT CHARSET=utf8; 74 | 75 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 76 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 77 | /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; 78 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 79 | --------------------------------------------------------------------------------