├── .idea ├── compiler.xml ├── encodings.xml ├── inspectionProfiles │ └── Project_Default.xml ├── kotlinc.xml ├── libraries │ ├── Maven__ch_qos_logback_logback_classic_1_2_3.xml │ ├── Maven__ch_qos_logback_logback_core_1_2_3.xml │ ├── Maven__cn_hutool_hutool_core_5_2_4.xml │ ├── Maven__cn_hutool_hutool_log_5_2_4.xml │ ├── Maven__cn_hutool_hutool_setting_5_2_4.xml │ ├── Maven__com_alibaba_druid_1_1_16.xml │ ├── Maven__com_alibaba_druid_spring_boot_starter_1_1_16.xml │ ├── Maven__com_alibaba_fastjson_1_2_41.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_7.xml │ ├── Maven__com_fasterxml_jackson_core_jackson_databind_2_9_7.xml │ ├── Maven__com_fasterxml_jackson_datatype_jackson_datatype_jdk8_2_9_7.xml │ ├── Maven__com_fasterxml_jackson_datatype_jackson_datatype_jsr310_2_9_7.xml │ ├── Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_9_7.xml │ ├── Maven__com_github_jsqlparser_jsqlparser_0_9_5.xml │ ├── Maven__com_github_pagehelper_pagehelper_4_1_6.xml │ ├── Maven__com_google_guava_guava_20_0.xml │ ├── Maven__com_jayway_jsonpath_json_path_2_4_0.xml │ ├── Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml │ ├── Maven__com_zaxxer_HikariCP_2_7_9.xml │ ├── Maven__commons_codec_commons_codec_1_11.xml │ ├── Maven__io_springfox_springfox_core_2_9_2.xml │ ├── Maven__io_springfox_springfox_schema_2_9_2.xml │ ├── Maven__io_springfox_springfox_spi_2_9_2.xml │ ├── Maven__io_springfox_springfox_spring_web_2_9_2.xml │ ├── Maven__io_springfox_springfox_swagger2_2_9_2.xml │ ├── Maven__io_springfox_springfox_swagger_common_2_9_2.xml │ ├── Maven__io_springfox_springfox_swagger_ui_2_9_2.xml │ ├── Maven__io_swagger_swagger_annotations_1_5_20.xml │ ├── Maven__io_swagger_swagger_models_1_5_20.xml │ ├── Maven__javax_annotation_javax_annotation_api_1_3_2.xml │ ├── Maven__javax_validation_validation_api_2_0_1_Final.xml │ ├── Maven__junit_junit_4_10.xml │ ├── Maven__mysql_mysql_connector_java_5_1_47.xml │ ├── Maven__net_bytebuddy_byte_buddy_1_7_11.xml │ ├── Maven__net_bytebuddy_byte_buddy_agent_1_7_11.xml │ ├── Maven__net_minidev_accessors_smart_1_2.xml │ ├── Maven__net_minidev_json_smart_2_3.xml │ ├── Maven__org_antlr_antlr4_runtime_4_7_1.xml │ ├── Maven__org_apache_commons_commons_collections4_4_2.xml │ ├── Maven__org_apache_commons_commons_pool2_2_5_0.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_shardingsphere_sharding_core_api_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_common_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_entry_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_execute_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_merge_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_optimize_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_parse_common_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_parse_mysql_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_parse_oracle_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_parse_postgresql_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_parse_spi_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_parse_sqlserver_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_rewrite_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_core_route_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_jdbc_core_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_jdbc_spring_boot_starter_4_0_0_RC1.xml │ ├── Maven__org_apache_shardingsphere_sharding_transaction_core_4_0_0_RC1.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_34.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_el_8_5_34.xml │ ├── Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_34.xml │ ├── Maven__org_assertj_assertj_core_3_9_1.xml │ ├── Maven__org_attoparser_attoparser_2_0_5_RELEASE.xml │ ├── Maven__org_codehaus_groovy_groovy_indy_2_4_5.xml │ ├── Maven__org_hamcrest_hamcrest_core_1_3.xml │ ├── Maven__org_hamcrest_hamcrest_library_1_3.xml │ ├── Maven__org_hibernate_validator_hibernate_validator_6_0_13_Final.xml │ ├── Maven__org_jboss_logging_jboss_logging_3_3_2_Final.xml │ ├── Maven__org_mapstruct_mapstruct_1_2_0_Final.xml │ ├── Maven__org_mockito_mockito_core_2_15_0.xml │ ├── Maven__org_mybatis_mybatis_3_5_1.xml │ ├── Maven__org_mybatis_mybatis_spring_2_0_1.xml │ ├── Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_2_0_1.xml │ ├── Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_2_0_1.xml │ ├── Maven__org_objenesis_objenesis_2_6.xml │ ├── Maven__org_ow2_asm_asm_5_0_4.xml │ ├── Maven__org_skyscreamer_jsonassert_1_5_0.xml │ ├── Maven__org_slf4j_jcl_over_slf4j_1_7_25.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_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_autoconfigure_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_devtools_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_jdbc_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_json_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_logging_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_redis_1_4_7_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_test_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_thymeleaf_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_tomcat_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_starter_web_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_test_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_boot_spring_boot_test_autoconfigure_2_0_6_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_commons_2_0_11_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_keyvalue_2_0_11_RELEASE.xml │ ├── Maven__org_springframework_data_spring_data_redis_2_0_11_RELEASE.xml │ ├── Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml │ ├── Maven__org_springframework_plugin_spring_plugin_metadata_1_2_0_RELEASE.xml │ ├── Maven__org_springframework_spring_aop_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_beans_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_context_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_context_support_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_core_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_expression_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_jcl_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_jdbc_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_oxm_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_test_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_tx_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_web_5_0_10_RELEASE.xml │ ├── Maven__org_springframework_spring_webmvc_5_0_10_RELEASE.xml │ ├── Maven__org_thymeleaf_extras_thymeleaf_extras_java8time_3_0_1_RELEASE.xml │ ├── Maven__org_thymeleaf_thymeleaf_3_0_10_RELEASE.xml │ ├── Maven__org_thymeleaf_thymeleaf_spring5_3_0_10_RELEASE.xml │ ├── Maven__org_unbescape_unbescape_1_1_6_RELEASE.xml │ ├── Maven__org_xmlunit_xmlunit_core_2_5_1.xml │ ├── Maven__org_yaml_snakeyaml_1_19.xml │ └── Maven__redis_clients_jedis_2_9_0.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml ├── vcs.xml └── workspace.xml ├── ReadMe.md ├── SpringBoot_Sharding.iml ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── lyl │ │ ├── StartApplication.java │ │ ├── algorithm │ │ ├── MyPreciseDBShardingAlgorithm.java │ │ └── MyPreciseTableShardingAlgorithm.java │ │ ├── bean │ │ ├── JobBean.java │ │ ├── Role.java │ │ └── User.java │ │ ├── config │ │ ├── PageHelperConfig.java │ │ ├── RedisMessageListenerConfig.java │ │ └── Swagger2Config.java │ │ ├── constant │ │ └── SystemConstant.java │ │ ├── controller │ │ ├── RoleRestController.java │ │ └── UserRestController.java │ │ ├── dao │ │ ├── RoleDao.java │ │ └── UserDao.java │ │ ├── listener │ │ ├── RedisJobEventMessageListener.java │ │ └── RedisJobInitServletContextListener.java │ │ ├── quartz │ │ ├── RoleStatisticsJob.java │ │ ├── SchedulerQuartzConfig.java │ │ ├── StartQuartzJobListener.java │ │ └── UserStatisticsJob.java │ │ ├── service │ │ ├── RoleService.java │ │ ├── UserService.java │ │ └── impl │ │ │ ├── RoleServiceImpl.java │ │ │ └── UserServiceImpl.java │ │ └── utils │ │ ├── RedisTemplateUtils.java │ │ ├── RequestParameter.java │ │ ├── Response.java │ │ ├── ResponseCode.java │ │ ├── ShardingUtils.java │ │ └── SpringContextJobUtil.java ├── resources │ ├── application-log.properties │ ├── application-mybatis.properties │ ├── application-quartz.properties │ ├── application-redis.properties │ ├── application-shardingJDBC.properties │ ├── application-shardingJDBCInline.properties │ ├── application.properties │ ├── banner.txt │ ├── mapper │ │ ├── Role.xml │ │ └── User.xml │ ├── mybatis-config.xml │ └── sql │ │ ├── springboot0.sql │ │ └── springboot1.sql └── webapp │ └── WEB-INF │ └── web.xml └── test └── java └── com └── lyl ├── RoleRestAPITest.java └── UserRestAPITest.java /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 36 | -------------------------------------------------------------------------------- /.idea/kotlinc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | -------------------------------------------------------------------------------- /.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__cn_hutool_hutool_core_5_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__cn_hutool_hutool_log_5_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__cn_hutool_hutool_setting_5_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_druid_1_1_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_druid_spring_boot_starter_1_1_16.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_alibaba_fastjson_1_2_41.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_7.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_7.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_7.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_7.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_7.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_github_jsqlparser_jsqlparser_0_9_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_github_pagehelper_pagehelper_4_1_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_guava_guava_20_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_jayway_jsonpath_json_path_2_4_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_zaxxer_HikariCP_2_7_9.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_codec_commons_codec_1_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_core_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_schema_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_spi_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_spring_web_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_swagger2_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_swagger_common_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_springfox_springfox_swagger_ui_2_9_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_swagger_swagger_annotations_1_5_20.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__io_swagger_swagger_models_1_5_20.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__junit_junit_4_10.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__mysql_mysql_connector_java_5_1_47.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_bytebuddy_byte_buddy_1_7_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_bytebuddy_byte_buddy_agent_1_7_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_minidev_accessors_smart_1_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__net_minidev_json_smart_2_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_antlr_antlr4_runtime_4_7_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_collections4_4_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_commons_commons_pool2_2_5_0.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_shardingsphere_sharding_core_api_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_common_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_entry_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_execute_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_merge_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_optimize_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_parse_common_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_parse_mysql_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_parse_oracle_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_parse_postgresql_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_parse_spi_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_parse_sqlserver_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_rewrite_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_core_route_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_jdbc_core_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_jdbc_spring_boot_starter_4_0_0_RC1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_apache_shardingsphere_sharding_transaction_core_4_0_0_RC1.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_34.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_34.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_34.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_assertj_assertj_core_3_9_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_attoparser_attoparser_2_0_5_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_codehaus_groovy_groovy_indy_2_4_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_library_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hibernate_validator_hibernate_validator_6_0_13_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_mapstruct_mapstruct_1_2_0_Final.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mockito_mockito_core_2_15_0.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_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_2_0_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_objenesis_objenesis_2_6.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_ow2_asm_asm_5_0_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_skyscreamer_jsonassert_1_5_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_slf4j_jcl_over_slf4j_1_7_25.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_6_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_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_devtools_2_0_6_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_6_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_0_6_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_6_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_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_redis_1_4_7_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_test_2_0_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_starter_thymeleaf_2_0_6_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_6_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_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_test_2_0_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_boot_spring_boot_test_autoconfigure_2_0_6_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_0_11_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_0_11_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_0_11_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_plugin_spring_plugin_core_1_2_0_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_plugin_spring_plugin_metadata_1_2_0_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_aop_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_beans_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_context_support_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_core_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_expression_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jcl_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_jdbc_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_oxm_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_test_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_tx_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_web_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_springframework_spring_webmvc_5_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_thymeleaf_extras_thymeleaf_extras_java8time_3_0_1_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_thymeleaf_thymeleaf_3_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_thymeleaf_thymeleaf_spring5_3_0_10_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_unbescape_unbescape_1_1_6_RELEASE.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_xmlunit_xmlunit_core_2_5_1.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/libraries/Maven__redis_clients_jedis_2_9_0.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 | -------------------------------------------------------------------------------- /.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 | ## 项目信息: 2 | 3 | 此项目是基于**SpringBoot**的,并在其基础上设计了 **RestFul** 风格的接口 。除此之外,还整合了其它的功能: 4 | 5 | 1. 整合了**swagger**生成在线的接口文档,并且实现统一格式的响应及异常情况处理; 6 | 2. 集成了 **PageHelper** 分页插件,支持更加友好的分页查询; 7 | 3. 整合了 **Mybatis** 、**Redis**,以及 详细的 日志配置; 8 | 4. 整合了 **Sharding-JDBC** ,实现了 分库分表,并且在分库分表中实现了自定义的分片算法; 一致性Hash算法,易于扩容; 9 | 5. 添加了 **单元测试**,使用Spring提供的RestTemplate调用RestFul风格的API接口; 10 | 6. 整合了 **quartz 定时任务框架** ,并进行了封装,只需在构建完定时任务Job类后,在 **application-quartz.properties** 配置文件中进行简单配置即可; 11 | 7. 实现了 **reids 分布式锁** ,当项目部署集群时,使用分布式锁来避免多台节点的定时任务重复执行; 12 | 8. 使用 **redis key 过期机制** 实现了定时任务,注意:此定时任务执行时存在延时的,如果对时间不敏感可以尝试使用; 13 | 14 | 15 | 16 | ## 参考资料: 17 | 18 | 1. 本项目的Swagger在线文档打开地址:http://localhost:8083/swagger-ui.html#/ 19 | 2. SpringBoot项目整体结构搭建 :https://www.cnblogs.com/xuwujing/p/8260935.html 20 | 3. SpringBoot项目整合swagger(这只是一种整合方式) :https://www.jianshu.com/p/d6424d98b02e 21 | 4. SpringBoot项目整合PageHelper分页插件:https://www.cnblogs.com/DawnCHENXI/p/9221653.html 22 | 5. SpringBoot项目简单的日志配置:https://www.cnblogs.com/bigdataZJ/p/springboot-log.html 23 | 6. SpringBoot项目集成Redis:https://www.jianshu.com/p/fd65156ff630 24 | 7. SpringBoot项目集成Sharding-JDBC:https://shardingsphere.apache.org/document/legacy/3.x/document/cn/manual/ 25 | 8. SpringBoot项目集成Quartz:https://blog.csdn.net/upxiaofeng/article/details/79415108 26 | 27 | 28 | 29 | ## 博主信息: 30 | 31 | 1. CSDN博客:https://blog.csdn.net/feichitianxia 32 | 2. 掘金博客:https://juejin.im/user/5c67b8046fb9a049a7125a58/posts 33 | 3. 思否博客:https://segmentfault.com/u/muzilei_5e72d30d2c9fb/articles 34 | 4. GitHub地址:https://github.com/leishen6?tab=repositories 35 | 5. 开源中国:https://my.oschina.net/u/4216693 36 | 6. 个人网站地址:https://leishen6.github.io/ 37 | 7. 微信公众号:木子雷 38 | -------------------------------------------------------------------------------- /SpringBoot_Sharding.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 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 4.0.0 6 | 7 | com.lyl 8 | SpringBoot_Sharding 9 | 1.0.1 10 | 11 | 12 | SpringBoot_Sharding 13 | 14 | http://www.example.com 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-parent 20 | 2.0.6.RELEASE 21 | 22 | 23 | 24 | 25 | 26 | UTF-8 27 | 1.7 28 | 29 | 1.2.0 30 | 5.1.39 31 | 1.2.41 32 | 33 | 34 | 35 | 36 | 37 | org.springframework.boot 38 | spring-boot-starter-web 39 | 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter-data-redis 44 | 2.2.1.RELEASE 45 | 46 | 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-thymeleaf 51 | 52 | 53 | 54 | org.springframework.boot 55 | spring-boot-devtools 56 | true 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-starter-test 62 | test 63 | 64 | 65 | 66 | 67 | 68 | org.mybatis.spring.boot 69 | mybatis-spring-boot-starter 70 | 2.0.1 71 | 72 | 73 | 74 | 75 | mysql 76 | mysql-connector-java 77 | 78 | 79 | 80 | 81 | com.alibaba 82 | druid-spring-boot-starter 83 | 1.1.16 84 | 85 | 86 | 87 | com.alibaba 88 | fastjson 89 | ${fastjson} 90 | 91 | 92 | 93 | 94 | io.springfox 95 | springfox-swagger-ui 96 | 2.9.2 97 | 98 | 99 | 100 | io.springfox 101 | springfox-swagger2 102 | 2.9.2 103 | 104 | 105 | 106 | 107 | com.github.pagehelper 108 | pagehelper 109 | 4.1.6 110 | 111 | 112 | 113 | junit 114 | junit 115 | 4.13.1 116 | 117 | 118 | 119 | 120 | org.apache.shardingsphere 121 | sharding-jdbc-spring-boot-starter 122 | 4.0.0-RC1 123 | 124 | 125 | 126 | 127 | cn.hutool 128 | hutool-setting 129 | 5.2.4 130 | 131 | 132 | 133 | 134 | 135 | org.quartz-scheduler 136 | quartz 137 | 2.3.2 138 | 139 | 140 | 141 | 142 | 143 | 144 | ${project.artifactId} 145 | 146 | 147 | 148 | 149 | org.springframework.boot 150 | spring-boot-maven-plugin 151 | 152 | true 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/StartApplication.java: -------------------------------------------------------------------------------- 1 | package com.lyl; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | import org.springframework.boot.SpringApplication; 6 | import org.springframework.boot.autoconfigure.SpringBootApplication; 7 | import org.springframework.boot.web.servlet.ServletComponentScan; 8 | 9 | /** 10 | * @Title: Application 11 | * @Description: springboot 的启动类 12 | * @date: 2019年8月23日 下午4:38:42 13 | */ 14 | @SpringBootApplication // 启动类注解,是一个复合注解 15 | @ServletComponentScan(basePackages = "com.lyl.listener") 16 | public class StartApplication { 17 | 18 | private static final Logger LOG = LoggerFactory.getLogger(StartApplication.class); 19 | 20 | public static void main(String[] args) { 21 | // 启动嵌入式的 Tomcat 并初始化 Spring 环境及其各 Spring 组件 22 | SpringApplication.run(StartApplication.class, args); 23 | LOG.info("程序启动成功......"); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/algorithm/MyPreciseDBShardingAlgorithm.java: -------------------------------------------------------------------------------- 1 | package com.lyl.algorithm; 2 | 3 | import cn.hutool.setting.dialect.Props; 4 | import com.lyl.constant.SystemConstant; 5 | import com.lyl.utils.ShardingUtils; 6 | import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm; 7 | import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.Collection; 12 | 13 | /** 14 | * @PACKAGE_NAME: com.lyl.algorithm 15 | * @ClassName: MyPreciseDBShardingAlgorithm 16 | * @Description: 自定义数据库的精确分片算法,根据用户名进行分片 17 | * @Date: 2020-06-18 17:28 18 | **/ 19 | public class MyPreciseDBShardingAlgorithm implements PreciseShardingAlgorithm { 20 | 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | 23 | /** 24 | * 分库虚拟节点数量 25 | */ 26 | public static int virtualNodeCount; 27 | 28 | /** 29 | * 分库虚拟节点范围 30 | */ 31 | public static String virtualNodeCountRang; 32 | 33 | 34 | public MyPreciseDBShardingAlgorithm() { 35 | } 36 | 37 | 38 | /** 39 | * 数据分片 40 | * 41 | * @param dbNames 实际数据源集合; springboot0、springboot1 42 | * @param preciseShardingValue 分片键 name 用户名值 43 | * @return 44 | */ 45 | @Override 46 | public String doSharding(Collection dbNames, PreciseShardingValue preciseShardingValue) { 47 | 48 | Props props = new Props("application-shardingJDBC.properties"); 49 | // 初始化分库的虚拟节点数量和范围 50 | virtualNodeCount = props.getInt(SystemConstant.SHARDING_DATASOURCE_VIRTUAL_NODE_COUNT); 51 | virtualNodeCountRang = props.getStr(SystemConstant.SHARDING_DATASOURCE_VIRTUAL_NODE_COUNT_RANG); 52 | 53 | // 根据用户名的hash值对《virtualNodeCount》进行取余后,得到余数,余数一定在0,《virtualNodeCount》之间的 54 | Integer mod = preciseShardingValue.getValue().hashCode() % virtualNodeCount; 55 | 56 | // 由于获取的字符串的hash值可能存在负数,所以需要需要取其绝对值 57 | mod = ShardingUtils.getAbsoluteValue(mod); 58 | 59 | // 虚拟节点范围映射到实际物理节点 60 | Integer shardingValue = ShardingUtils.getPhysicNodeByVisualNode(mod, virtualNodeCountRang); 61 | 62 | for (String each : dbNames) { 63 | // 将余数与配置的实际数据库名进行匹配 64 | if (each.endsWith(String.valueOf(shardingValue))) { 65 | logger.info("logic DB : {}", each); 66 | return each; 67 | } 68 | } 69 | 70 | throw new UnsupportedOperationException(); 71 | } 72 | } -------------------------------------------------------------------------------- /src/main/java/com/lyl/algorithm/MyPreciseTableShardingAlgorithm.java: -------------------------------------------------------------------------------- 1 | package com.lyl.algorithm; 2 | 3 | import cn.hutool.setting.dialect.Props; 4 | import com.lyl.constant.SystemConstant; 5 | import com.lyl.utils.ShardingUtils; 6 | import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm; 7 | import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.Collection; 12 | 13 | /** 14 | * @PACKAGE_NAME: com.lyl.algorithm 15 | * @ClassName: MyPreciseTableShardingAlgorithm 16 | * @Description: 自定义表的精确分片算法,根据用户名进行分片 17 | * @Date: 2020-06-18 17:11 18 | **/ 19 | public class MyPreciseTableShardingAlgorithm implements PreciseShardingAlgorithm { 20 | 21 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 22 | 23 | /** 24 | * 分表虚拟节点数量 25 | */ 26 | public static int virtualNodeCount; 27 | 28 | /** 29 | * 分表虚拟节点范围 30 | */ 31 | public static String virtualNodeCountRang; 32 | 33 | 34 | public MyPreciseTableShardingAlgorithm() { 35 | 36 | } 37 | 38 | 39 | /** 40 | * 数据分片 41 | * 42 | * @param tableNames 实际表集合; t_user0、t_user1、t_user2 43 | * @param preciseShardingValue 分片键 name 用户名值 44 | * @return 45 | */ 46 | @Override 47 | public String doSharding(Collection tableNames, PreciseShardingValue preciseShardingValue) { 48 | 49 | Props props = new Props("application-shardingJDBC.properties"); 50 | // 初始化分表的虚拟节点数量和范围 51 | virtualNodeCount = props.getInt(SystemConstant.SHARDING_TABLE_VIRTUAL_NODE_COUNT); 52 | virtualNodeCountRang = props.getStr(SystemConstant.SHARDING_TABLE_VIRTUAL_NODE_COUNT_RANG); 53 | 54 | 55 | // 根据用户名的hash值对《virtualNodeCount》进行取余后,得到余数,余数一定在0,《virtualNodeCount》之间的 56 | Integer mod = preciseShardingValue.getValue().hashCode() % virtualNodeCount; 57 | 58 | // 由于获取的字符串的hash值可能存在负数,所以需要需要取其绝对值 59 | mod = ShardingUtils.getAbsoluteValue(mod); 60 | 61 | // 虚拟节点范围映射到实际物理节点 62 | Integer shardingValue = ShardingUtils.getPhysicNodeByVisualNode(mod, virtualNodeCountRang); 63 | 64 | for (String each : tableNames) { 65 | // 将余数与配置的实际表名进行匹配 66 | if (each.endsWith(String.valueOf(shardingValue))) { 67 | logger.info("logic table : {}", each); 68 | return each; 69 | } 70 | } 71 | 72 | throw new UnsupportedOperationException(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/bean/JobBean.java: -------------------------------------------------------------------------------- 1 | package com.lyl.bean; 2 | 3 | /** 4 | * @PACKAGE_NAME: com.lyl.bean 5 | * @ClassName: JobBean 6 | * @Description: job 任务bean 7 | * @Date: 2020-06-26 19:42 8 | **/ 9 | public class JobBean { 10 | 11 | /** 12 | * 任务描述, 任务名 13 | */ 14 | private String jobName; 15 | 16 | /** 17 | * 任务运行时间表达式 18 | */ 19 | private String cronExpression; 20 | 21 | /** 22 | * 任务分组 23 | */ 24 | private String jobGroup; 25 | 26 | /** 27 | * 任务类的全路径 28 | */ 29 | private String jobClass; 30 | 31 | 32 | public String getJobName() { 33 | return jobName; 34 | } 35 | 36 | public void setJobName(String jobName) { 37 | this.jobName = jobName; 38 | } 39 | 40 | public String getCronExpression() { 41 | return cronExpression; 42 | } 43 | 44 | public void setCronExpression(String cronExpression) { 45 | this.cronExpression = cronExpression; 46 | } 47 | 48 | public String getJobGroup() { 49 | return jobGroup; 50 | } 51 | 52 | public void setJobGroup(String jobGroup) { 53 | this.jobGroup = jobGroup; 54 | } 55 | 56 | public String getJobClass() { 57 | return jobClass; 58 | } 59 | 60 | public void setJobClass(String jobClass) { 61 | this.jobClass = jobClass; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/bean/Role.java: -------------------------------------------------------------------------------- 1 | package com.lyl.bean; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @PACKAGE_NAME: com.lyl.bean 9 | * @ClassName: Role 10 | * @Description: 角色 11 | * @Date: 2020-06-19 12:54 12 | **/ 13 | public class Role implements Serializable { 14 | 15 | private static final long serialVersionUID = 1L; 16 | 17 | /** 18 | * 编号 19 | */ 20 | private int id; 21 | 22 | /** 23 | * 姓名 24 | */ 25 | private String roleName; 26 | 27 | 28 | public Role() { 29 | } 30 | 31 | 32 | public int getId() { 33 | return id; 34 | } 35 | 36 | public void setId(int id) { 37 | this.id = id; 38 | } 39 | 40 | public String getRoleName() { 41 | return roleName; 42 | } 43 | 44 | public void setRoleName(String roleName) { 45 | this.roleName = roleName; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return JSONObject.toJSONString(this); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/bean/User.java: -------------------------------------------------------------------------------- 1 | package com.lyl.bean; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | import com.github.pagehelper.PageInfo; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @Title: User 10 | * @Description: 用户 11 | * @date: 2019年8月23日 下午4:21:11 12 | */ 13 | @SuppressWarnings("rawtypes") 14 | public class User implements Serializable { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | /** 19 | * 编号 20 | */ 21 | private int id; 22 | 23 | /** 24 | * 姓名 25 | */ 26 | private String name; 27 | 28 | /** 29 | * 年龄 30 | */ 31 | private int age; 32 | 33 | /** 34 | * 分页插件所需要使用的 35 | */ 36 | private PageInfo pageinfo; 37 | 38 | public User() { 39 | 40 | } 41 | 42 | public User(PageInfo pageinfo) { 43 | this.pageinfo = pageinfo; 44 | } 45 | 46 | public int getId() { 47 | return id; 48 | } 49 | 50 | public void setId(int id) { 51 | this.id = id; 52 | } 53 | 54 | public String getName() { 55 | return name; 56 | } 57 | 58 | public void setName(String name) { 59 | this.name = name; 60 | } 61 | 62 | public int getAge() { 63 | return age; 64 | } 65 | 66 | public void setAge(int age) { 67 | this.age = age; 68 | } 69 | 70 | public PageInfo getPageinfo() { 71 | return pageinfo; 72 | } 73 | 74 | public void setPageinfo(PageInfo pageinfo) { 75 | this.pageinfo = pageinfo; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return JSONObject.toJSONString(this); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/config/PageHelperConfig.java: -------------------------------------------------------------------------------- 1 | package com.lyl.config; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import java.util.Properties; 10 | 11 | /** 12 | * @Title: PageHelperConfig 13 | * @Description: 使用PageHelper分页插件的一个配置类,除了使用配置类外,还可以直接在配置文件中进行配置。 14 | * @date: 2019年8月24日 下午1:18:01 15 | */ 16 | @Configuration 17 | public class PageHelperConfig { 18 | 19 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 20 | 21 | @Bean 22 | public PageHelper pageHelper() { 23 | logger.info("\n MyBatisConfiguration.pageHelper()分页插件成功注册到容器中......"); 24 | 25 | PageHelper pageHelper = new PageHelper(); 26 | Properties properties = new Properties(); 27 | properties.setProperty("offsetAsPageNum", "true"); 28 | properties.setProperty("rowBoundsWithCount", "true"); 29 | properties.setProperty("reasonable", "true"); 30 | // 配置mysql数据库的方言 31 | properties.setProperty("dialect", "mysql"); 32 | pageHelper.setProperties(properties); 33 | return pageHelper; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/config/RedisMessageListenerConfig.java: -------------------------------------------------------------------------------- 1 | package com.lyl.config; 2 | 3 | import cn.hutool.setting.dialect.Props; 4 | import com.lyl.bean.JobBean; 5 | import com.lyl.constant.SystemConstant; 6 | import com.lyl.listener.RedisJobEventMessageListener; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.context.annotation.Bean; 11 | import org.springframework.context.annotation.Configuration; 12 | import org.springframework.data.redis.connection.RedisConnectionFactory; 13 | import org.springframework.data.redis.core.StringRedisTemplate; 14 | import org.springframework.data.redis.listener.RedisMessageListenerContainer; 15 | 16 | import java.util.ArrayList; 17 | import java.util.List; 18 | import java.util.concurrent.TimeUnit; 19 | 20 | /** 21 | * @PACKAGE_NAME: com.lyl.config 22 | * @ClassName: MessageListenerConfig 23 | * @Description: redis 消息监听器配置类,使用注解将自定义的消息过期监听器注入到IOC中等 24 | * @Date: 2020-12-21 11:22 25 | * @Author: 木子雷 公众号 26 | **/ 27 | @Configuration 28 | public class RedisMessageListenerConfig { 29 | 30 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 31 | 32 | @Autowired 33 | StringRedisTemplate redisTemplate; 34 | 35 | 36 | /** 37 | * redis 定时任务启动 38 | */ 39 | public void startRedisJob() 40 | throws Exception { 41 | List redisJobBeanList = getRedisJobBeanByConfig(); 42 | if (redisJobBeanList != null && redisJobBeanList.size() > 0) { 43 | for (JobBean redisJobBean : redisJobBeanList) { 44 | // 调用 redisTemplate 对象设置一个300s 后过期的键,不出意外 300s 后键过期后会触发事件打印结果 45 | redisTemplate.boundValueOps(redisJobBean.getJobGroup()).set(redisJobBean.getJobGroup(), 46 | Integer.parseInt(redisJobBean.getCronExpression()), TimeUnit.SECONDS); 47 | } 48 | } 49 | } 50 | 51 | 52 | /** 53 | * 获取 redis 定时任务配置参数 54 | * 55 | * @return 56 | * @throws Exception 57 | */ 58 | private List getRedisJobBeanByConfig() 59 | throws Exception { 60 | Props props = new Props("application-redis.properties"); 61 | String redisJobList = props.getStr("redisJobList"); 62 | if (redisJobList == null || "".equals(redisJobList)) { 63 | throw new Exception("Redis 定时任务集合 redisJobList 未配置 . . . . . ."); 64 | } 65 | List redisJobBeanList = new ArrayList<>(); 66 | String[] redisJobs = redisJobList.split(","); 67 | 68 | for (int i = 0; i < redisJobs.length; i++) { 69 | JobBean jobBean = new JobBean(); 70 | jobBean.setJobClass(props.getStr(redisJobs[i] + ".jobClass")); 71 | jobBean.setJobName(props.getStr(redisJobs[i] + ".name")); 72 | // 用于设置redis 的key 73 | jobBean.setJobGroup(redisJobs[i]); 74 | jobBean.setCronExpression(props.getStr(redisJobs[i] + ".expireTime")); 75 | redisJobBeanList.add(jobBean); 76 | // 将获取到的redis定时任务的过期key 和 对应过期处理放到map中 77 | SystemConstant.map.put(redisJobs[i], jobBean); 78 | } 79 | return redisJobBeanList; 80 | } 81 | 82 | 83 | /** 84 | * Redis 消息监听器容器. 85 | * 86 | * @param redisConnectionFactory the redis connection factory 87 | * @return the redis message listener container 88 | */ 89 | @Bean 90 | public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory) { 91 | RedisMessageListenerContainer redisMessageListenerContainer = new RedisMessageListenerContainer(); 92 | redisMessageListenerContainer.setConnectionFactory(redisConnectionFactory); 93 | return redisMessageListenerContainer; 94 | } 95 | 96 | 97 | /** 98 | * Redis 定时任务监听器注册为Bean. 99 | * 100 | * @param redisMessageListenerContainer the redis message listener container 101 | * @return the redis event message listener 102 | */ 103 | @Bean 104 | public RedisJobEventMessageListener redisEventMessageListener(RedisMessageListenerContainer redisMessageListenerContainer) { 105 | return new RedisJobEventMessageListener(redisMessageListenerContainer); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/config/Swagger2Config.java: -------------------------------------------------------------------------------- 1 | package com.lyl.config; 2 | 3 | import com.google.common.collect.Sets; 4 | import com.lyl.constant.SystemConstant; 5 | import org.springframework.context.annotation.Bean; 6 | import org.springframework.context.annotation.Configuration; 7 | import springfox.documentation.builders.ApiInfoBuilder; 8 | import springfox.documentation.builders.PathSelectors; 9 | import springfox.documentation.builders.RequestHandlerSelectors; 10 | import springfox.documentation.service.ApiInfo; 11 | import springfox.documentation.spi.DocumentationType; 12 | import springfox.documentation.spring.web.plugins.Docket; 13 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 14 | 15 | /** 16 | * @Title: Swagger2 17 | * @Description: Swagger2配置类 18 | * 实现Swagger除了需要在controller中的方法使用@ApiOperation注解外,还需要定义一个Swagger2配置类 19 | * @date: 2019年8月23日 下午5:22:02 20 | */ 21 | @Configuration 22 | @EnableSwagger2 23 | public class Swagger2Config { 24 | 25 | @Bean 26 | public Docket createRestApi() { 27 | return new Docket(DocumentationType.SWAGGER_2).protocols(Sets.newHashSet("http")) // 协议,http或https 28 | .apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(SystemConstant.BASE_PACKAGE)) // 一定要写对,会在这个路径下扫描controller定义 29 | .paths(PathSelectors.any()).build().apiInfo(new ApiInfoBuilder() // 配置网站基本信息 30 | .description("SpringBoot Sharding 接口文档").build()); 31 | } 32 | 33 | private ApiInfo apiInfo() { 34 | return new ApiInfoBuilder().title("REST接口定义").version("1.0").description("用于测试RESTful API , 接口版本为 v1").build(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/constant/SystemConstant.java: -------------------------------------------------------------------------------- 1 | package com.lyl.constant; 2 | 3 | 4 | import com.lyl.bean.JobBean; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | /** 10 | * @PACKAGE_NAME: com.lyl.constant 11 | * @ClassName: SystemConstant 12 | * @Description: 常量类,存放使用的常量 13 | * @Date: 2020-06-18 14:05 14 | **/ 15 | public class SystemConstant { 16 | 17 | /** 18 | * Swagger2 扫描controller包的路径 19 | **/ 20 | public static final String BASE_PACKAGE = "com.lyl.controller"; 21 | 22 | /** 23 | * findAll 全部查询数据的redis的key 24 | **/ 25 | public static final String USER_FINDUSERALL = "User_findUserAll"; 26 | 27 | /** 28 | * 分库的虚拟节点范围 29 | **/ 30 | public static final String SHARDING_DATASOURCE_VIRTUAL_NODE_COUNT_RANG = "sharding.datasource.virtual.node.count.rang"; 31 | 32 | /** 33 | * 分表的虚拟节点范围 34 | **/ 35 | public static final String SHARDING_TABLE_VIRTUAL_NODE_COUNT_RANG = "sharding.table.virtual.node.count.rang"; 36 | 37 | /** 38 | * 分库的虚拟节点数量 39 | **/ 40 | public static final String SHARDING_DATASOURCE_VIRTUAL_NODE_COUNT = "sharding.datasource.virtual.node.count"; 41 | 42 | /** 43 | * 分表的虚拟节点数量 44 | **/ 45 | public static final String SHARDING_TABLE_VIRTUAL_NODE_COUNT = "sharding.table.virtual.node.count"; 46 | 47 | /** 48 | * 分割符 49 | **/ 50 | public static final String _DEFAULT_SEPARATOR_COMMA = ","; 51 | 52 | /** 53 | * 是否启用redis, 默认不启用 54 | **/ 55 | public static final String DEFAULT_IF_DISABLE_REDIS = "default_if_disable_redis"; 56 | 57 | /** 58 | * redis 分布式锁的过期时间 59 | **/ 60 | public static final int DISTRIBUTEDLOCK_EXPIRETIME = 1000; 61 | 62 | /** 63 | * redis 定时任务使用,系统启动时获取redis定时任务key 和 过期时key对应的处理流程 64 | */ 65 | public static Map map = new HashMap(); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/controller/RoleRestController.java: -------------------------------------------------------------------------------- 1 | package com.lyl.controller; 2 | 3 | import com.lyl.bean.Role; 4 | import com.lyl.service.RoleService; 5 | import com.lyl.utils.RequestParameter; 6 | import com.lyl.utils.Response; 7 | import com.lyl.utils.ResponseCode; 8 | import io.swagger.annotations.Api; 9 | import io.swagger.annotations.ApiOperation; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.web.bind.annotation.PostMapping; 14 | import org.springframework.web.bind.annotation.RequestBody; 15 | import org.springframework.web.bind.annotation.RequestMapping; 16 | import org.springframework.web.bind.annotation.RestController; 17 | 18 | /** 19 | * @PACKAGE_NAME: com.lyl.controller 20 | * @ClassName: RoleRestController 21 | * @Description: 22 | * @Date: 2020-06-19 13:10 23 | **/ 24 | @RestController 25 | @Api(tags = "角色数据接口") 26 | @RequestMapping(value = "/v1/api") 27 | public class RoleRestController { 28 | 29 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 30 | 31 | @Autowired 32 | private RoleService roleService; 33 | 34 | 35 | @ApiOperation(value = "新增角色", notes = "新增角色") 36 | @PostMapping("/role/addRole") 37 | public Response addRole(@RequestBody RequestParameter requestParameter) { 38 | logger.info("request: {}", requestParameter.toString()); 39 | logger.info("开始新增..."); 40 | 41 | boolean flag = roleService.addRole(requestParameter.getData()); 42 | Response response = null; 43 | if (flag) { 44 | response = new Response(flag, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 45 | } else { 46 | response = new Response(flag, ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 47 | } 48 | logger.info("response: {} \n", response.toString()); 49 | return response; 50 | } 51 | 52 | 53 | @ApiOperation(value = "根据name查询角色", notes = "根据名字查询角色数据") 54 | @PostMapping("/role/findRoleByName") 55 | public Response findRoleByName(@RequestBody RequestParameter requestParameter) { 56 | logger.info("request: {}", requestParameter.toString()); 57 | logger.info("开始根据名字查询角色数据..."); 58 | 59 | Role role = roleService.findRoleByName(requestParameter.getData()); 60 | 61 | Response response = null; 62 | if (role != null) { 63 | response = new Response(role, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 64 | } else { 65 | response = new Response("", ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 66 | } 67 | logger.info("response: {} \n", response.toString()); 68 | return response; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/controller/UserRestController.java: -------------------------------------------------------------------------------- 1 | package com.lyl.controller; 2 | 3 | import com.github.pagehelper.PageHelper; 4 | import com.github.pagehelper.PageInfo; 5 | import com.lyl.bean.User; 6 | import com.lyl.constant.SystemConstant; 7 | import com.lyl.service.UserService; 8 | import com.lyl.utils.RedisTemplateUtils; 9 | import com.lyl.utils.RequestParameter; 10 | import com.lyl.utils.Response; 11 | import com.lyl.utils.ResponseCode; 12 | import io.swagger.annotations.Api; 13 | import io.swagger.annotations.ApiOperation; 14 | import org.slf4j.Logger; 15 | import org.slf4j.LoggerFactory; 16 | import org.springframework.beans.factory.annotation.Autowired; 17 | import org.springframework.web.bind.annotation.GetMapping; 18 | import org.springframework.web.bind.annotation.PostMapping; 19 | import org.springframework.web.bind.annotation.RequestBody; 20 | import org.springframework.web.bind.annotation.RequestMapping; 21 | import org.springframework.web.bind.annotation.RestController; 22 | 23 | import java.util.List; 24 | 25 | /** 26 | * @Title: UserRestController 27 | * @Description: 在Controller中没有必要根据删除、修改等特意的去使用deleteMapping、putMapping等, 28 | * 因为这些都是需要有请求参数的,所以可以直接只使用postMapping即可 29 | * @date: 2019年8月23日 下午4:30:56 30 | */ 31 | 32 | @RestController 33 | @Api(tags = "用户数据接口") 34 | @RequestMapping(value = "/v1/api") 35 | @SuppressWarnings({"rawtypes", "unchecked"}) 36 | public class UserRestController { 37 | 38 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 39 | 40 | /** 41 | * redis中key时用户前缀 42 | */ 43 | private String prex = "User_"; 44 | 45 | @Autowired 46 | RedisTemplateUtils redisU; 47 | 48 | @Autowired 49 | private UserService userService; 50 | 51 | 52 | /** 53 | * @param requestParameter 54 | * @return 55 | * @ApiOperation 这个注解是使用swagger生成rest接口的在线文档 56 | */ 57 | @ApiOperation(value = "新增用户", notes = "新增用户") 58 | @PostMapping("/user/addUser") 59 | public Response addUser(@RequestBody RequestParameter requestParameter) { 60 | logger.info("request: " + requestParameter.toString()); 61 | logger.info("开始新增..."); 62 | 63 | boolean flag = userService.addUser(requestParameter.getData()); 64 | Response response = null; 65 | if (flag) { 66 | response = new Response(flag, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 67 | 68 | // 新增用户成功,所以将可能之前缓存的findAll全部查询结果删除 69 | logger.info("清空redis中key:{} 缓存数据...", SystemConstant.USER_FINDUSERALL); 70 | redisU.deleteByKey(SystemConstant.USER_FINDUSERALL); 71 | } else { 72 | response = new Response(flag, ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 73 | } 74 | logger.info("response: {} \n", response.toString()); 75 | return response; 76 | } 77 | 78 | 79 | @ApiOperation(value = "根据name更新用户", notes = "根据名字更新用户数据") 80 | @PostMapping("/user/updateUserByName") 81 | public Response updateUserByName(@RequestBody RequestParameter requestParameter) { 82 | logger.info("request: {}", requestParameter.toString()); 83 | logger.info("开始更新..."); 84 | 85 | boolean flag = userService.updateUser(requestParameter.getData()); 86 | Response response = null; 87 | if (flag) { 88 | response = new Response(flag, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 89 | 90 | // 更新成功,需要将redis中与此 User 相关的缓存数据清除 91 | String name = requestParameter.getData().getName(); 92 | logger.info("清空redis中与 {} 相关的缓存数据...", name); 93 | redisU.deleteByKey(SystemConstant.USER_FINDUSERALL); 94 | redisU.deleteByKey(prex + name); 95 | } else { 96 | response = new Response(flag, ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 97 | } 98 | logger.info("response: {} \n", response.toString()); 99 | return response; 100 | } 101 | 102 | 103 | @ApiOperation(value = "根据用户name删除用户", notes = "根据名字删除用户数据") 104 | @PostMapping("/user/deleteUserByName") 105 | public Response delete(@RequestBody RequestParameter requestParameter) { 106 | logger.info("request: {}", requestParameter.toString()); 107 | logger.info("开始删除... {}", requestParameter.getData()); 108 | 109 | boolean flag = userService.deleteUser(requestParameter.getData()); 110 | Response response = null; 111 | if (flag) { 112 | response = new Response(flag, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 113 | 114 | // 删除成功,需要将redis中与此 User 相关的缓存数据清空 115 | String name = requestParameter.getData(); 116 | logger.info("清空redis中与 {} 相关的缓存数据...", name); 117 | redisU.deleteByKey(SystemConstant.USER_FINDUSERALL); 118 | redisU.deleteByKey(prex + name); 119 | } else { 120 | response = new Response(flag, ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 121 | } 122 | logger.info("response: {} \n", response.toString()); 123 | return response; 124 | } 125 | 126 | 127 | @ApiOperation(value = "根据name查询用户", notes = "根据名字查询用户数据") 128 | @PostMapping("/user/findUserByName") 129 | public Response findUserByName(@RequestBody RequestParameter requestParameter) { 130 | logger.info("request: {}", requestParameter.toString()); 131 | logger.info("开始根据名字查询数据..."); 132 | 133 | User user = redisU.get("User_" + requestParameter.getData(), User.class); 134 | 135 | if (user == null) { 136 | user = userService.findUserByName(requestParameter.getData()); 137 | } 138 | 139 | Response response = null; 140 | if (user != null) { 141 | response = new Response(user, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 142 | 143 | logger.info("将数据放到redis缓存中......"); 144 | redisU.set(prex + requestParameter.getData(), user); 145 | } else { 146 | response = new Response("", ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 147 | } 148 | logger.info("response: {} \n", response.toString()); 149 | return response; 150 | } 151 | 152 | 153 | @ApiOperation(value = "查询全部用户", notes = "查询全部用户数据") 154 | @GetMapping("/user/findUserAll") 155 | public Response> findAll() { 156 | logger.info("开始查询所有数据..."); 157 | 158 | List findAll; 159 | // redis缓存中查询 160 | findAll = redisU.get(SystemConstant.USER_FINDUSERALL, List.class); 161 | 162 | if (!(findAll != null && findAll.size() > 0)) { 163 | findAll = userService.findAll(); 164 | } 165 | 166 | Response response = null; 167 | if (findAll != null && findAll.size() != 0) { 168 | response = new Response(findAll, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 169 | 170 | logger.info("将数据放到redis缓存中......"); 171 | redisU.set(SystemConstant.USER_FINDUSERALL, findAll); 172 | } else { 173 | response = new Response(findAll, ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 174 | } 175 | logger.info("response: {} \n", response.toString()); 176 | return response; 177 | } 178 | 179 | 180 | @ApiOperation(value = "分页查询全部用户", notes = "分页查询全部用户数据") 181 | @PostMapping("/user/findUserAllByPage") 182 | public Response findAllByPage(@RequestBody RequestParameter requestParameter) { 183 | logger.info("request: {}", requestParameter.toString()); 184 | logger.info("开始分页查询数据..."); 185 | 186 | PageHelper.startPage(requestParameter.getData().getPageinfo().getPageNum(), requestParameter.getData().getPageinfo().getPageSize()); 187 | List findAll = userService.findAll(); 188 | PageInfo pageinfo = new PageInfo<>(findAll); 189 | 190 | Response response = null; 191 | if (findAll.size() != 0) { 192 | response = new Response(pageinfo, ResponseCode.SUCCESS.code(), ResponseCode.SUCCESS.message()); 193 | } else { 194 | response = new Response(pageinfo, ResponseCode.ERROR.code(), ResponseCode.ERROR.message()); 195 | } 196 | logger.info("response: {} \n", response.toString()); 197 | return response; 198 | } 199 | 200 | } -------------------------------------------------------------------------------- /src/main/java/com/lyl/dao/RoleDao.java: -------------------------------------------------------------------------------- 1 | package com.lyl.dao; 2 | 3 | import com.lyl.bean.Role; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | /** 7 | * @PACKAGE_NAME: com.lyl.dao 8 | * @ClassName: RoleDao 9 | * @Description: 角色 dao 10 | * @Date: 2020-06-19 12:58 11 | **/ 12 | @Mapper 13 | public interface RoleDao { 14 | 15 | /** 16 | * 添加角色 17 | * 18 | * @param role 19 | */ 20 | void addRole(Role role); 21 | 22 | /** 23 | * 根据名称 查询角色 24 | * 25 | * @param roleName 26 | * @return 27 | */ 28 | Role findRoleByName(String roleName); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/dao/UserDao.java: -------------------------------------------------------------------------------- 1 | package com.lyl.dao; 2 | 3 | import com.lyl.bean.User; 4 | import org.apache.ibatis.annotations.Mapper; 5 | 6 | import java.util.List; 7 | 8 | /** 9 | * @Title: UserDao 10 | * @Description: 用户 dao 11 | * @date: 2019年8月23日 下午4:25:40 12 | */ 13 | @Mapper 14 | public interface UserDao { 15 | 16 | /** 17 | * 添加用户 18 | * 19 | * @param user 20 | */ 21 | void addUser(User user); 22 | 23 | /** 24 | * 更新用户信息 25 | * 26 | * @param user 27 | */ 28 | void updateUser(User user); 29 | 30 | /** 31 | * 根据用户名 删除用户 32 | * 33 | * @param userName 34 | */ 35 | void deleteUser(String userName); 36 | 37 | /** 38 | * @param userName 39 | * @return 40 | */ 41 | User findByName(String userName); 42 | 43 | /** 44 | * 查询全部用户 45 | * 46 | * @return 47 | */ 48 | List findAll(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/listener/RedisJobEventMessageListener.java: -------------------------------------------------------------------------------- 1 | package com.lyl.listener; 2 | 3 | import com.lyl.bean.JobBean; 4 | import com.lyl.constant.SystemConstant; 5 | import org.quartz.Job; 6 | import org.quartz.JobExecutionException; 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.data.redis.connection.Message; 11 | import org.springframework.data.redis.core.StringRedisTemplate; 12 | import org.springframework.data.redis.listener.KeyExpirationEventMessageListener; 13 | import org.springframework.data.redis.listener.RedisMessageListenerContainer; 14 | import org.springframework.stereotype.Component; 15 | 16 | import java.text.SimpleDateFormat; 17 | import java.util.Date; 18 | import java.util.concurrent.TimeUnit; 19 | 20 | 21 | /** 22 | * @PACKAGE_NAME: com.lyl.listener 23 | * @ClassName: RedisJobEventMessageListener 24 | * @Description: 重写了 Redis 的 Key 失效监听器,使用其实现 定时任务 ; 25 | * 当redis 中的key过期时,触发一个事件,并不会准点触发事件,适用于时间不是特别敏感的触发需求 ; 26 | * 我们可以算好需要执行的时间间隔作为key失效时间,这样就可以保证到点执行逻辑了 ; 27 | * @Date: 2020-12-21 11:20 28 | * @Author: 木子雷 公众号 29 | **/ 30 | @Component 31 | public class RedisJobEventMessageListener extends KeyExpirationEventMessageListener { 32 | 33 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 34 | 35 | @Autowired 36 | StringRedisTemplate redisTemplate; 37 | 38 | 39 | public RedisJobEventMessageListener(RedisMessageListenerContainer listenerContainer) { 40 | super(listenerContainer); 41 | } 42 | 43 | 44 | /** 45 | * redis 过期消息处理器 46 | * 47 | * @param message 48 | */ 49 | @Override 50 | protected void doHandleMessage(Message message) { 51 | // 过期消息的key 52 | String key = message.toString(); 53 | 54 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 55 | 56 | // 这个就是过期的key ,过期后,也就是事件触发后对应的value是拿不到的。 57 | // 这里实现业务逻辑,如果是服务器集群的话需要使用分布式锁进行抢占执行。 58 | logger.info("key = {}", key); 59 | logger.info("end = {}", dateFormat.format(new Date())); 60 | 61 | if (SystemConstant.map.containsKey(key)) { 62 | JobBean redisJobBean = SystemConstant.map.get(key); 63 | try { 64 | // 注意:这里是你自己的定时任务处理的内容 65 | Job redisJob = (Job) Class.forName(redisJobBean.getJobClass()).newInstance(); 66 | redisJob.execute(null); 67 | 68 | } catch (InstantiationException e) { 69 | logger.error("redis 定时任务:{} 过期处理失败!", key, e); 70 | } catch (IllegalAccessException e) { 71 | logger.error("redis 定时任务:{} 过期处理失败!", key, e); 72 | } catch (ClassNotFoundException e) { 73 | logger.error("redis 定时任务:{} 过期处理失败!", key, e); 74 | } catch (JobExecutionException e) { 75 | logger.error("redis 定时任务:{} 过期处理失败!", key, e); 76 | } 77 | 78 | // redis key过期处理完后,需要重新设置key及其过期时间,实现定时任务的定时执行 79 | redisTemplate.boundValueOps(redisJobBean.getJobGroup()).set(redisJobBean.getJobGroup(), 80 | Integer.parseInt(redisJobBean.getCronExpression()), TimeUnit.SECONDS); 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/listener/RedisJobInitServletContextListener.java: -------------------------------------------------------------------------------- 1 | package com.lyl.listener; 2 | 3 | import com.lyl.config.RedisMessageListenerConfig; 4 | import org.slf4j.Logger; 5 | import org.slf4j.LoggerFactory; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import javax.servlet.ServletContextEvent; 9 | import javax.servlet.ServletContextListener; 10 | import javax.servlet.annotation.WebListener; 11 | import java.text.SimpleDateFormat; 12 | import java.util.Date; 13 | 14 | /** 15 | * @PACKAGE_NAME: com.lyl.listener 16 | * @ClassName: RedisJobInitServletContextListener 17 | * @Description: Redis 定时任务初始化 监听器 18 | * @Date: 2020-12-21 11:24 19 | * @Author: 木子雷 公众号 20 | **/ 21 | @WebListener 22 | public class RedisJobInitServletContextListener implements ServletContextListener { 23 | 24 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 25 | 26 | @Autowired 27 | RedisMessageListenerConfig redisMessageListenerConfig; 28 | 29 | @Override 30 | public void contextInitialized(ServletContextEvent sce) { 31 | 32 | try { 33 | // redis 定时任务启动 34 | redisMessageListenerConfig.startRedisJob(); 35 | } catch (Exception e) { 36 | logger.error("Redis 定时任务启动失败!", e); 37 | } 38 | 39 | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 40 | logger.info("redis job start begin = {}", dateFormat.format(new Date())); 41 | 42 | logger.info("redis 定时任务监听器数据初始化成功。。。"); 43 | } 44 | 45 | @Override 46 | public void contextDestroyed(ServletContextEvent sce) { 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/quartz/RoleStatisticsJob.java: -------------------------------------------------------------------------------- 1 | package com.lyl.quartz; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.lyl.bean.Role; 5 | import com.lyl.constant.SystemConstant; 6 | import com.lyl.service.RoleService; 7 | import com.lyl.utils.RedisTemplateUtils; 8 | import com.lyl.utils.SpringContextJobUtil; 9 | import org.quartz.Job; 10 | import org.quartz.JobExecutionContext; 11 | import org.quartz.JobExecutionException; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | /** 16 | * @PACKAGE_NAME: com.lyl.quartz 17 | * @ClassName: RoleStatisticsJob 18 | * @Description: 定时任务 19 | * @Date: 2020-06-27 13:34 20 | **/ 21 | public class RoleStatisticsJob implements Job { 22 | 23 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 24 | 25 | 26 | private static final String LOCK_KEY = "RoleStatisticsJob"; 27 | 28 | private static final String LOCK_VALUE = "RoleStatisticsJob"; 29 | 30 | @Override 31 | public void execute(JobExecutionContext arg0) 32 | throws JobExecutionException { 33 | logger.debug("Role Quartz execute start . . . . . . ."); 34 | 35 | RedisTemplateUtils redisTemplateUtils = (RedisTemplateUtils) SpringContextJobUtil 36 | .getBean("redisTemplateUtils"); 37 | 38 | // 获取分布式锁 39 | boolean flag = redisTemplateUtils.tryGetDistributedLock(LOCK_KEY, LOCK_VALUE, 40 | SystemConstant.DISTRIBUTEDLOCK_EXPIRETIME); 41 | 42 | try { 43 | if (flag) { 44 | // TODO 业务逻辑 45 | /** 46 | * 通过工具类获取Spring容器中的实例bean 47 | * 在quartz框架中,Job 是通过反射出来的实例,不受spring的管理,即使使用@Component注解, 48 | * 将其标记为组件类,它也不会被注册到容器中,所以就无法直接通过自动注入service服务层对象等 49 | */ 50 | RoleService roleService = (RoleService) SpringContextJobUtil 51 | .getBean("roleService"); 52 | Role role = roleService.findRoleByName("程序员"); 53 | logger.debug("find role by name : {}", JSON.toJSONString(role)); 54 | } 55 | } finally { 56 | // 保证分布式锁最终被释放 57 | if (flag) { 58 | redisTemplateUtils.releaseDistributedLock(LOCK_KEY, LOCK_VALUE); 59 | } 60 | } 61 | 62 | logger.debug("Role Quartz execute end . . . . . . . ."); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/quartz/SchedulerQuartzConfig.java: -------------------------------------------------------------------------------- 1 | package com.lyl.quartz; 2 | 3 | import cn.hutool.setting.dialect.Props; 4 | import com.lyl.bean.JobBean; 5 | import org.quartz.CronScheduleBuilder; 6 | import org.quartz.CronTrigger; 7 | import org.quartz.Job; 8 | import org.quartz.JobBuilder; 9 | import org.quartz.JobDetail; 10 | import org.quartz.JobKey; 11 | import org.quartz.Scheduler; 12 | import org.quartz.SchedulerException; 13 | import org.quartz.TriggerBuilder; 14 | import org.quartz.TriggerKey; 15 | import org.slf4j.Logger; 16 | import org.slf4j.LoggerFactory; 17 | import org.springframework.beans.factory.annotation.Autowired; 18 | import org.springframework.context.annotation.Configuration; 19 | 20 | import java.util.ArrayList; 21 | import java.util.Date; 22 | import java.util.List; 23 | 24 | /** 25 | * @PACKAGE_NAME: com.lyl.quartz 26 | * @ClassName: QuartzScheduler 27 | * @Description: 定时任务 quartz 配置类 28 | * @Date: 2020-06-26 17:52 29 | **/ 30 | @Configuration 31 | public class SchedulerQuartzConfig { 32 | 33 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 34 | 35 | /** 36 | * 任务调度器 37 | */ 38 | @Autowired 39 | private Scheduler scheduler; 40 | 41 | /** 42 | * 开始执行所有定时任务 43 | * 44 | * @throws SchedulerException 45 | */ 46 | public void startJob() 47 | throws Exception { 48 | List jobBeanList = getJobBeanByConfig(); 49 | 50 | if (jobBeanList != null && jobBeanList.size() > 0) { 51 | for (JobBean jobBean : jobBeanList) { 52 | registerJobToScheduler(scheduler, jobBean); 53 | } 54 | } 55 | scheduler.start(); 56 | } 57 | 58 | 59 | /** 60 | * 获取定时任务配置参数 61 | * 62 | * @return 63 | * @throws Exception 64 | */ 65 | private List getJobBeanByConfig() 66 | throws Exception { 67 | Props props = new Props("application-quartz.properties"); 68 | String jobList = props.getStr("jobList"); 69 | if (jobList == null || "".equals(jobList)) { 70 | throw new Exception("定时任务集合 jobList 未配置 . . . . . ."); 71 | } 72 | List jobBeanList = new ArrayList<>(); 73 | String[] jobs = jobList.split(","); 74 | 75 | for (int i = 0; i < jobs.length; i++) { 76 | JobBean jobBean = new JobBean(); 77 | jobBean.setJobClass(props.getStr(jobs[i] + ".jobClass")); 78 | jobBean.setJobGroup(jobs[i]); 79 | jobBean.setJobName(props.getStr(jobs[i] + ".name")); 80 | jobBean.setCronExpression(props.getStr(jobs[i] + ".cron")); 81 | jobBeanList.add(jobBean); 82 | } 83 | return jobBeanList; 84 | } 85 | 86 | 87 | /** 88 | * 将定时任务与其对应的触发器注册到调度器Scheduler中 89 | * 90 | * @param scheduler 91 | * @param jobBean 92 | */ 93 | private void registerJobToScheduler(Scheduler scheduler, JobBean jobBean) { 94 | 95 | try { 96 | Class jobClass = (Class) Class.forName(jobBean.getJobClass()); 97 | 98 | // 通过JobBuilder构建JobDetail实例,JobDetail规定只能是实现Job接口的实例 99 | // JobDetail 是具体Job实例 100 | JobDetail jobDetail = JobBuilder.newJob(jobClass) 101 | .withIdentity(jobBean.getJobName(), jobBean.getJobGroup()).build(); 102 | 103 | // 基于表达式构建触发器的执行时间配置 104 | CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder 105 | .cronSchedule(jobBean.getCronExpression()); 106 | 107 | // CronTrigger表达式触发器 继承于Trigger 108 | // TriggerBuilder 用于构建《 触发器实例 》 109 | CronTrigger cronTrigger = TriggerBuilder.newTrigger() 110 | .withIdentity(jobBean.getJobName(), jobBean.getJobGroup()) 111 | .withSchedule(cronScheduleBuilder).build(); 112 | 113 | scheduler.scheduleJob(jobDetail, cronTrigger); 114 | 115 | } catch (Exception e) { 116 | logger.error("\n定时任务注册到调度器失败:", e); 117 | } 118 | } 119 | 120 | 121 | /** 122 | * 获取Job信息 123 | * 124 | * @param name 125 | * @param group 126 | * @return 127 | * @throws SchedulerException 128 | */ 129 | private String getJobInfo(String name, String group) 130 | throws SchedulerException { 131 | TriggerKey triggerKey = new TriggerKey(name, group); 132 | CronTrigger cronTrigger = (CronTrigger) scheduler.getTrigger(triggerKey); 133 | return String.format("time:%s,state:%s", cronTrigger.getCronExpression(), 134 | scheduler.getTriggerState(triggerKey).name()); 135 | } 136 | 137 | /** 138 | * 修改某个任务的执行时间 139 | * 140 | * @param name 141 | * @param group 142 | * @param time 143 | * @return 144 | * @throws SchedulerException 145 | */ 146 | private boolean modifyJob(String name, String group, String time) 147 | throws SchedulerException { 148 | Date date = null; 149 | TriggerKey triggerKey = new TriggerKey(name, group); 150 | CronTrigger cronTrigger = (CronTrigger) scheduler.getTrigger(triggerKey); 151 | String oldTime = cronTrigger.getCronExpression(); 152 | if (!oldTime.equalsIgnoreCase(time)) { 153 | CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(time); 154 | CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(name, group) 155 | .withSchedule(cronScheduleBuilder).build(); 156 | date = scheduler.rescheduleJob(triggerKey, trigger); 157 | } 158 | return date != null; 159 | } 160 | 161 | /** 162 | * 暂停所有任务 163 | * 164 | * @throws SchedulerException 165 | */ 166 | private void pauseAllJob() 167 | throws SchedulerException { 168 | scheduler.pauseAll(); 169 | } 170 | 171 | /** 172 | * 暂停某个任务 173 | * 174 | * @param name 175 | * @param group 176 | * @throws SchedulerException 177 | */ 178 | private void pauseJob(String name, String group) 179 | throws SchedulerException { 180 | JobKey jobKey = new JobKey(name, group); 181 | JobDetail jobDetail = scheduler.getJobDetail(jobKey); 182 | if (jobDetail == null) { 183 | return; 184 | } 185 | scheduler.pauseJob(jobKey); 186 | } 187 | 188 | /** 189 | * 恢复所有任务 190 | * 191 | * @throws SchedulerException 192 | */ 193 | private void resumeAllJob() 194 | throws SchedulerException { 195 | scheduler.resumeAll(); 196 | } 197 | 198 | /** 199 | * 恢复某个任务 200 | * 201 | * @param name 202 | * @param group 203 | * @throws SchedulerException 204 | */ 205 | private void resumeJob(String name, String group) 206 | throws SchedulerException { 207 | JobKey jobKey = new JobKey(name, group); 208 | JobDetail jobDetail = scheduler.getJobDetail(jobKey); 209 | if (jobDetail == null) { 210 | return; 211 | } 212 | scheduler.resumeJob(jobKey); 213 | } 214 | 215 | /** 216 | * 删除某个任务 217 | * 218 | * @param name 219 | * @param group 220 | * @throws SchedulerException 221 | */ 222 | private void deleteJob(String name, String group) 223 | throws SchedulerException { 224 | JobKey jobKey = new JobKey(name, group); 225 | JobDetail jobDetail = scheduler.getJobDetail(jobKey); 226 | if (jobDetail == null) { 227 | return; 228 | } 229 | scheduler.deleteJob(jobKey); 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/quartz/StartQuartzJobListener.java: -------------------------------------------------------------------------------- 1 | package com.lyl.quartz; 2 | 3 | import cn.hutool.setting.dialect.Props; 4 | import org.quartz.Scheduler; 5 | import org.quartz.SchedulerException; 6 | import org.quartz.SchedulerFactory; 7 | import org.quartz.impl.StdSchedulerFactory; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | import org.springframework.beans.factory.annotation.Autowired; 11 | import org.springframework.context.ApplicationListener; 12 | import org.springframework.context.annotation.Bean; 13 | import org.springframework.context.annotation.Configuration; 14 | import org.springframework.context.event.ContextRefreshedEvent; 15 | 16 | /** 17 | * @PACKAGE_NAME: com.lyl.quartz 18 | * @ClassName: StartQuartzJobListener 19 | * @Description: Scheduler注入到Spring容器,并采用spring容器加载完毕后的监听事件,启动定时任务 20 | * @Date: 2020-06-26 20:47 21 | **/ 22 | @Configuration 23 | public class StartQuartzJobListener implements ApplicationListener { 24 | 25 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 26 | 27 | 28 | @Autowired 29 | private SchedulerQuartzConfig quartzScheduler; 30 | 31 | 32 | @Override 33 | public void onApplicationEvent(ContextRefreshedEvent event) { 34 | try { 35 | Props props = new Props("application-quartz.properties"); 36 | boolean flag = props.getBool("default_if_disable_quartz"); 37 | // 在配置文件中获取是否启用定时任务 38 | if (!flag) { 39 | quartzScheduler.startJob(); 40 | logger.debug("定时任务已经启动......."); 41 | } 42 | } catch (Exception e) { 43 | logger.error("定时任务启动失败:", e); 44 | } 45 | } 46 | 47 | 48 | /** 49 | * 向Spring 容器 初始注入scheduler 50 | * 51 | * @return 52 | * @throws SchedulerException 53 | */ 54 | @Bean 55 | public Scheduler scheduler() 56 | throws SchedulerException { 57 | SchedulerFactory schedulerFactoryBean = new StdSchedulerFactory(); 58 | return schedulerFactoryBean.getScheduler(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/quartz/UserStatisticsJob.java: -------------------------------------------------------------------------------- 1 | package com.lyl.quartz; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.lyl.bean.User; 5 | import com.lyl.constant.SystemConstant; 6 | import com.lyl.service.UserService; 7 | import com.lyl.utils.RedisTemplateUtils; 8 | import com.lyl.utils.SpringContextJobUtil; 9 | import org.quartz.Job; 10 | import org.quartz.JobExecutionContext; 11 | import org.quartz.JobExecutionException; 12 | import org.slf4j.Logger; 13 | import org.slf4j.LoggerFactory; 14 | 15 | import java.util.List; 16 | 17 | /** 18 | * @PACKAGE_NAME: com.lyl.quartz 19 | * @ClassName: UserStatisticsJob 20 | * @Description: 定时任务 21 | * @Date: 2020-06-26 17:34 22 | **/ 23 | public class UserStatisticsJob implements Job { 24 | 25 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 26 | 27 | private static final String LOCK_KEY = "UserStatisticsJob"; 28 | 29 | private static final String LOCK_VALUE = "UserStatisticsJob"; 30 | 31 | @Override 32 | public void execute(JobExecutionContext arg0) 33 | throws JobExecutionException { 34 | logger.debug("User Quartz execute start . . . . . . ."); 35 | 36 | RedisTemplateUtils redisTemplateUtils = (RedisTemplateUtils) SpringContextJobUtil 37 | .getBean("redisTemplateUtils"); 38 | 39 | // 获取分布式锁 40 | boolean flag = redisTemplateUtils.tryGetDistributedLock(LOCK_KEY, LOCK_VALUE, 41 | SystemConstant.DISTRIBUTEDLOCK_EXPIRETIME); 42 | 43 | try { 44 | if (flag) { 45 | logger.debug("User tryGetDistributedLock success . . . . "); 46 | // TODO 业务逻辑 47 | /** 48 | * 通过工具类获取Spring容器中的实例bean 49 | * 在quartz框架中,Job 是通过反射出来的实例,不受spring的管理,即使使用@Component注解, 50 | * 将其标记为组件类,它也不会被注册到容器中,所以就无法直接通过自动注入service服务层对象等 51 | */ 52 | UserService userService = (UserService) SpringContextJobUtil 53 | .getBean("userService"); 54 | List users = userService.findAll(); 55 | logger.debug("find All user : {}", JSON.toJSONString(users)); 56 | } 57 | } finally { 58 | // 保证分布式锁最终被释放 59 | if (flag) { 60 | redisTemplateUtils.releaseDistributedLock(LOCK_KEY, LOCK_VALUE); 61 | } 62 | } 63 | 64 | logger.debug("User Quartz execute end . . . . . . . ."); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/service/RoleService.java: -------------------------------------------------------------------------------- 1 | package com.lyl.service; 2 | 3 | import com.lyl.bean.Role; 4 | 5 | /** 6 | * @PACKAGE_NAME: com.lyl.service 7 | * @ClassName: RoleService 8 | * @Description: 9 | * @Date: 2020-06-19 13:02 10 | **/ 11 | public interface RoleService { 12 | 13 | /** 14 | * 新增角色 15 | * @param role 16 | */ 17 | boolean addRole(Role role); 18 | 19 | /** 20 | * 根据角色名字查询角色信息 21 | * @param roleName 22 | * @return 23 | */ 24 | Role findRoleByName(String roleName); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/service/UserService.java: -------------------------------------------------------------------------------- 1 | package com.lyl.service; 2 | 3 | import com.lyl.bean.User; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | *@Title: UserService 9 | * @Description: 10 | * @date: 2019年8月23日 下午4:28:01 11 | */ 12 | public interface UserService { 13 | 14 | /** 15 | * 新增用户 16 | * @param user 17 | * @return 18 | */ 19 | boolean addUser(User user); 20 | 21 | /** 22 | * 修改用户 23 | * @param user 24 | * @return 25 | */ 26 | boolean updateUser(User user); 27 | 28 | 29 | /** 30 | * 删除用户 31 | * @param id 32 | * @return 33 | */ 34 | boolean deleteUser(String userName); 35 | 36 | /** 37 | * 根据用户名字查询用户信息 38 | * @param userName 39 | */ 40 | User findUserByName(String userName); 41 | 42 | 43 | 44 | /** 45 | * 查询所有 46 | * @return 47 | */ 48 | List findAll(); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/service/impl/RoleServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lyl.service.impl; 2 | 3 | import com.lyl.bean.Role; 4 | import com.lyl.dao.RoleDao; 5 | import com.lyl.service.RoleService; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Propagation; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | /** 14 | * @PACKAGE_NAME: com.lyl.service.impl 15 | * @ClassName: RoleServiceImpl 16 | * @Description: 17 | * @Date: 2020-06-19 13:04 18 | **/ 19 | @Service("roleService") 20 | public class RoleServiceImpl implements RoleService { 21 | 22 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 23 | 24 | @Autowired 25 | private RoleDao roleDao; 26 | 27 | @Override 28 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) 29 | public boolean addRole(Role role) { 30 | boolean flag = false; 31 | try { 32 | roleDao.addRole(role); 33 | flag = true; 34 | } catch (Exception e) { 35 | logger.error("add role fail .", e); 36 | } 37 | return flag; 38 | } 39 | 40 | @Override 41 | public Role findRoleByName(String roleName) { 42 | return roleDao.findRoleByName(roleName); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/service/impl/UserServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.lyl.service.impl; 2 | 3 | import com.lyl.bean.User; 4 | import com.lyl.dao.UserDao; 5 | import com.lyl.service.UserService; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.stereotype.Service; 10 | import org.springframework.transaction.annotation.Propagation; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import java.util.List; 14 | 15 | /** 16 | * @Title: UserServiceImpl 17 | * @Description: 18 | * @date: 2019年8月23日 下午4:29:01 19 | */ 20 | @Service("userService") // 表示此是服务层 21 | public class UserServiceImpl implements UserService { 22 | 23 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 24 | 25 | @Autowired 26 | private UserDao userDao; 27 | 28 | 29 | @Override 30 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)// 添加上事务 31 | public boolean addUser(User user) { 32 | boolean flag = false; 33 | try { 34 | userDao.addUser(user); 35 | flag = true; 36 | } catch (Exception e) { 37 | logger.error("add user fail .", e); 38 | } 39 | return flag; 40 | } 41 | 42 | 43 | @Override 44 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)// 添加上事务 45 | public boolean updateUser(User user) { 46 | boolean flag = false; 47 | try { 48 | userDao.updateUser(user); 49 | flag = true; 50 | } catch (Exception e) { 51 | logger.error("update user fail .", e); 52 | } 53 | return flag; 54 | } 55 | 56 | 57 | @Override 58 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)// 添加上事务 59 | public boolean deleteUser(String userName) { 60 | boolean flag = false; 61 | try { 62 | userDao.deleteUser(userName); 63 | flag = true; 64 | } catch (Exception e) { 65 | logger.error("delete user fail .", e); 66 | } 67 | return flag; 68 | } 69 | 70 | 71 | @Override 72 | public User findUserByName(String userName) { 73 | return userDao.findByName(userName); 74 | } 75 | 76 | 77 | @Override 78 | public List findAll() { 79 | return userDao.findAll(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/utils/RedisTemplateUtils.java: -------------------------------------------------------------------------------- 1 | package com.lyl.utils; 2 | 3 | import cn.hutool.setting.dialect.Props; 4 | import com.alibaba.fastjson.JSON; 5 | import com.lyl.constant.SystemConstant; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.beans.factory.annotation.Autowired; 9 | import org.springframework.data.redis.core.RedisTemplate; 10 | import org.springframework.data.redis.core.StringRedisTemplate; 11 | import org.springframework.data.redis.core.script.DefaultRedisScript; 12 | import org.springframework.data.redis.core.script.RedisScript; 13 | import org.springframework.data.redis.serializer.StringRedisSerializer; 14 | import org.springframework.stereotype.Service; 15 | 16 | import java.util.Collections; 17 | import java.util.List; 18 | import java.util.Set; 19 | 20 | /** 21 | * @Title: RedisTemplateService 22 | * @Description: 工具类 23 | * @date: 2019年9月5日 下午7:01:42 24 | */ 25 | @Service("redisTemplateUtils") 26 | public class RedisTemplateUtils { 27 | 28 | private final Logger logger = LoggerFactory.getLogger(this.getClass()); 29 | 30 | 31 | private static boolean flag; 32 | 33 | static { 34 | // 是否启用redis, 注意:默认是不启用的 35 | flag = new Props("application-redis.properties").getBool(SystemConstant.DEFAULT_IF_DISABLE_REDIS); 36 | } 37 | 38 | 39 | @Autowired 40 | StringRedisTemplate stringRedisTemplate; 41 | 42 | @Autowired 43 | RedisTemplate redisTemplate; 44 | 45 | 46 | /** 47 | * @param key 48 | * @param value 49 | * @return 50 | * @Description: 插入 51 | * @date: 2019年9月5日 下午7:02:45 52 | */ 53 | public boolean set(String key, T value) { 54 | // 是否启用redis 55 | if (flag) { 56 | return true; 57 | } 58 | 59 | try { 60 | 61 | // 任意类型转换成String 62 | String val = beanToString(value); 63 | 64 | if (val == null || val.length() <= 0) { 65 | return false; 66 | } 67 | 68 | stringRedisTemplate.opsForValue().set(key, val); 69 | return true; 70 | } catch (Exception e) { 71 | logger.error("redis set fail .", e); 72 | return false; 73 | } 74 | } 75 | 76 | /** 77 | * @param key 78 | * @param clazz 79 | * @return 80 | * @Description: 根据key获取元素 81 | * @date: 2019年9月5日 下午7:03:16 82 | */ 83 | public T get(String key, Class clazz) { 84 | 85 | // 是否启用redis 86 | if (flag) { 87 | return stringToBean(null, clazz); 88 | } 89 | 90 | try { 91 | String value = stringRedisTemplate.opsForValue().get(key); 92 | 93 | return stringToBean(value, clazz); 94 | } catch (Exception e) { 95 | logger.error("redis get fail .", e); 96 | return null; 97 | } 98 | } 99 | 100 | 101 | /** 102 | * @param prex 103 | * @Description: 模糊查询key,然后删除模糊查询出的所有key 104 | * @date: 2019年9月5日 下午7:53:25 105 | */ 106 | public void deleteByPrex(String prex) { 107 | if (prex != null && !"".equals(prex)) { 108 | Set keys = stringRedisTemplate.keys(prex); 109 | if (keys.size() > 0) { 110 | stringRedisTemplate.delete(keys); 111 | } 112 | } 113 | } 114 | 115 | 116 | /** 117 | * 根据 key 删除redis缓存 118 | * 119 | * @param key 120 | */ 121 | public void deleteByKey(String key) { 122 | // 是否启用redis 123 | if (flag) { 124 | return; 125 | } 126 | 127 | if (key != null && !"".equals(key)) { 128 | stringRedisTemplate.delete(key); 129 | } 130 | } 131 | 132 | 133 | private static final Long SUCCESS = 1L; 134 | 135 | private final String releaseDistributedLocakLua = "if redis.call('get', KEYS[1]) == ARGV[1] " + 136 | "then " + 137 | "return redis.call('del', KEYS[1]) " + 138 | "else " + 139 | "return 0 " + 140 | "end"; 141 | 142 | private final String getDistributedLocakLua = "if redis.call('setNx',KEYS[1],ARGV[1]) then " + 143 | " if redis.call('get',KEYS[1])==ARGV[1] then " + 144 | " return redis.call('expire',KEYS[1],ARGV[2]) " + 145 | " else " + 146 | " return 0 " + 147 | " end " + 148 | "end"; 149 | 150 | 151 | /** 152 | * 获取分布式锁 153 | * 154 | * @param lockKey 155 | * @param lockValue 156 | * @param expireTime 157 | * @return 158 | */ 159 | public boolean tryGetDistributedLock(final String lockKey, final String lockValue, int expireTime) { 160 | // 是否启用redis 161 | if (flag) { 162 | return true; 163 | } 164 | 165 | // redis脚本,执行脚本的返回类型为 Long 166 | RedisScript redisScript = new DefaultRedisScript<>(getDistributedLocakLua, Long.class); 167 | 168 | // 对非string类型的序列化 169 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 170 | redisTemplate.setValueSerializer(new StringRedisSerializer()); 171 | Object result = redisTemplate.execute(redisScript, Collections.singletonList(lockKey), 172 | lockValue, String.valueOf(expireTime)); 173 | 174 | if (SUCCESS.equals(result)) { 175 | return true; 176 | } 177 | 178 | return false; 179 | } 180 | 181 | 182 | /** 183 | * 释放分布式锁 184 | * 185 | * @param lockKey 186 | * @param lockValue 187 | * @return 188 | */ 189 | public synchronized boolean releaseDistributedLock(final String lockKey, final String lockValue) { 190 | // 是否启用redis 191 | if (flag) { 192 | return true; 193 | } 194 | 195 | // redis脚本,执行脚本的返回类型为 Long 196 | RedisScript redisScript = new DefaultRedisScript<>(releaseDistributedLocakLua, Long.class); 197 | 198 | // 对非string类型的序列化 199 | redisTemplate.setKeySerializer(new StringRedisSerializer()); 200 | redisTemplate.setValueSerializer(new StringRedisSerializer()); 201 | 202 | try { 203 | Object result = redisTemplate.execute(redisScript, Collections.singletonList(lockKey), lockValue); 204 | if (SUCCESS.equals(result)) { 205 | return true; 206 | } 207 | } catch (Exception e) { 208 | logger.error("releaseDistributedLock fail : ", e); 209 | } 210 | return false; 211 | } 212 | 213 | 214 | /** 215 | * @param value 216 | * @param clazz 217 | * @return 218 | * @Description: 将字符串转为对象 219 | * @date: 2019年9月5日 下午7:04:05 220 | */ 221 | @SuppressWarnings("unchecked") 222 | private T stringToBean(String value, Class clazz) { 223 | if (value == null || value.length() <= 0 || clazz == null) { 224 | return null; 225 | } 226 | 227 | if (clazz == int.class || clazz == Integer.class) { 228 | return (T) Integer.valueOf(value); 229 | } else if (clazz == long.class || clazz == Long.class) { 230 | return (T) Long.valueOf(value); 231 | } else if (clazz == String.class) { 232 | return (T) value; 233 | } else if (clazz == List.class) { 234 | return JSON.toJavaObject(JSON.parseArray(value), clazz); 235 | } else { 236 | return JSON.toJavaObject(JSON.parseObject(value), clazz); 237 | } 238 | } 239 | 240 | 241 | /** 242 | * @param value 243 | * @return 244 | * @Description: 将任意对象转为字符串 245 | * @date: 2019年9月5日 下午7:04:41 246 | */ 247 | private String beanToString(T value) { 248 | 249 | if (value == null) { 250 | return null; 251 | } 252 | Class clazz = value.getClass(); 253 | if (clazz == int.class || clazz == Integer.class) { 254 | return "" + value; 255 | } else if (clazz == long.class || clazz == Long.class) { 256 | return "" + value; 257 | } else if (clazz == String.class) { 258 | return (String) value; 259 | } else { 260 | return JSON.toJSONString(value); 261 | } 262 | } 263 | 264 | } 265 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/utils/RequestParameter.java: -------------------------------------------------------------------------------- 1 | package com.lyl.utils; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | import java.util.UUID; 6 | 7 | /** 8 | * 请求报文 9 | * 10 | * @param 11 | * @date: 2019年8月23日 下午7:07:01 12 | */ 13 | public class RequestParameter { 14 | 15 | /** 16 | * 请求时间戳 17 | */ 18 | private long timestamp; 19 | 20 | /** 21 | * 版本号 22 | */ 23 | private String version; 24 | 25 | 26 | private String serialNo; 27 | 28 | 29 | /** 30 | * 业务参数,不同业务接口不同.(请求参数) 31 | */ 32 | private T data; 33 | 34 | 35 | public RequestParameter() { 36 | this.timestamp = System.currentTimeMillis(); 37 | this.serialNo = UUID.randomUUID().toString().replaceAll("-", ""); 38 | } 39 | 40 | 41 | public long getTimestamp() { 42 | return timestamp; 43 | } 44 | 45 | public void setTimestamp(long timestamp) { 46 | this.timestamp = timestamp; 47 | } 48 | 49 | public String getVersion() { 50 | return version; 51 | } 52 | 53 | public void setVersion(String version) { 54 | this.version = version; 55 | } 56 | 57 | public String getSerialNo() { 58 | return serialNo; 59 | } 60 | 61 | public void setSerialNo(String serialNo) { 62 | this.serialNo = serialNo; 63 | } 64 | 65 | 66 | public T getData() { 67 | return data; 68 | } 69 | 70 | public void setData(T data) { 71 | this.data = data; 72 | } 73 | 74 | 75 | @Override 76 | public String toString() { 77 | return JSONObject.toJSONString(this); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/utils/Response.java: -------------------------------------------------------------------------------- 1 | package com.lyl.utils; 2 | 3 | import com.alibaba.fastjson.JSONObject; 4 | 5 | import java.io.Serializable; 6 | 7 | /** 8 | * @Title: Response 9 | * @Description: 封装的统一的响应返回类 10 | * @date: 2019年8月23日 下午7:07:13 11 | */ 12 | @SuppressWarnings("serial") 13 | public class Response implements Serializable { 14 | 15 | /** 16 | * 响应数据 17 | */ 18 | private T date; 19 | 20 | /** 21 | * 响应状态码 22 | */ 23 | private Integer code; 24 | 25 | /** 26 | * 响应描述信息 27 | */ 28 | private String message; 29 | 30 | public Response(T date, Integer code, String message) { 31 | super(); 32 | this.date = date; 33 | this.code = code; 34 | this.message = message; 35 | } 36 | 37 | 38 | public T getDate() { 39 | return date; 40 | } 41 | 42 | public void setDate(T date) { 43 | this.date = date; 44 | } 45 | 46 | public Integer getCode() { 47 | return code; 48 | } 49 | 50 | public void setCode(Integer code) { 51 | this.code = code; 52 | } 53 | 54 | public String getMessage() { 55 | return message; 56 | } 57 | 58 | public void setMessage(String message) { 59 | this.message = message; 60 | } 61 | 62 | 63 | @Override 64 | public String toString() { 65 | return JSONObject.toJSONString(this); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/utils/ResponseCode.java: -------------------------------------------------------------------------------- 1 | package com.lyl.utils; 2 | 3 | /** 4 | * @Title: ResponseCode 5 | * @Description: 使用枚举类封装好的响应状态码及对应的响应消息 6 | * @date: 2019年8月23日 下午7:12:50 7 | */ 8 | public enum ResponseCode { 9 | 10 | SUCCESS(1200, "请求成功"), 11 | 12 | ERROR(1400, "请求失败"); 13 | 14 | 15 | private Integer code; 16 | 17 | private String message; 18 | 19 | private ResponseCode(Integer code, String message) { 20 | this.code = code; 21 | this.message = message; 22 | } 23 | 24 | public Integer code() { 25 | return this.code; 26 | } 27 | 28 | public String message() { 29 | return this.message; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/utils/ShardingUtils.java: -------------------------------------------------------------------------------- 1 | package com.lyl.utils; 2 | 3 | import com.lyl.constant.SystemConstant; 4 | 5 | /** 6 | * @PACKAGE_NAME: com.lyl.utils 7 | * @ClassName: ShardingUtils 8 | * @Description: 分库分表的工具类 9 | * @Date: 2020-06-19 22:01 10 | **/ 11 | public class ShardingUtils { 12 | 13 | /** 14 | * 根据取模后的值获取虚拟节点对应的物理节点 15 | * 16 | * @param mod 取模数据 17 | * @return 物理节点 18 | */ 19 | public static Integer getPhysicNodeByVisualNode(int mod, String virtualNodeCountRang) { 20 | String[] rangArr = virtualNodeCountRang.split(SystemConstant._DEFAULT_SEPARATOR_COMMA); 21 | Integer physicCount = null; 22 | for (int i = 0; i < rangArr.length; i++) { 23 | String[] tmpArr = rangArr[i].split("-"); 24 | if ((mod >= Integer.parseInt(tmpArr[0])) && (mod <= Integer.parseInt(tmpArr[1]))) { 25 | physicCount = i; 26 | break; 27 | } 28 | } 29 | 30 | return physicCount; 31 | } 32 | 33 | 34 | /** 35 | * 通过位运算获取一个数的绝对值, 位运算比较快 36 | * 37 | * @param value 正数或负数 38 | * @return 39 | */ 40 | public static Integer getAbsoluteValue(Integer value) { 41 | Integer absoluteValue = 0; 42 | if (value != null) { 43 | absoluteValue = (value + (value >> 31)) ^ (value >> 31); 44 | } 45 | return absoluteValue; 46 | } 47 | 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/lyl/utils/SpringContextJobUtil.java: -------------------------------------------------------------------------------- 1 | package com.lyl.utils; 2 | 3 | import org.springframework.beans.BeansException; 4 | import org.springframework.context.ApplicationContext; 5 | import org.springframework.context.ApplicationContextAware; 6 | import org.springframework.stereotype.Component; 7 | 8 | import java.util.Locale; 9 | 10 | /** 11 | * @PACKAGE_NAME: com.lyl.utils 12 | * @ClassName: SpringContextJobUtil 13 | * @Description: spring 上下文工具类,用于在spring容器启动后,使用getBean方法获取容器中的实例bean 14 | * @Date: 2020-06-26 23:46 15 | **/ 16 | @Component // 工具类需要注入到容器中 17 | public class SpringContextJobUtil implements ApplicationContextAware { 18 | 19 | private static ApplicationContext context; 20 | 21 | @Override 22 | @SuppressWarnings("static-access") 23 | public void setApplicationContext(ApplicationContext contex) 24 | throws BeansException { 25 | this.context = contex; 26 | } 27 | 28 | public static Object getBean(String beanName) { 29 | return context.getBean(beanName); 30 | } 31 | 32 | public static String getMessage(String key) { 33 | return context.getMessage(key, null, Locale.getDefault()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/resources/application-log.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leishen6/SpringBoot_shardDB_shardTable/1699375a5a2f2f8b982d5ec5984e597ce30db04e/src/main/resources/application-log.properties -------------------------------------------------------------------------------- /src/main/resources/application-mybatis.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leishen6/SpringBoot_shardDB_shardTable/1699375a5a2f2f8b982d5ec5984e597ce30db04e/src/main/resources/application-mybatis.properties -------------------------------------------------------------------------------- /src/main/resources/application-quartz.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leishen6/SpringBoot_shardDB_shardTable/1699375a5a2f2f8b982d5ec5984e597ce30db04e/src/main/resources/application-quartz.properties -------------------------------------------------------------------------------- /src/main/resources/application-redis.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leishen6/SpringBoot_shardDB_shardTable/1699375a5a2f2f8b982d5ec5984e597ce30db04e/src/main/resources/application-redis.properties -------------------------------------------------------------------------------- /src/main/resources/application-shardingJDBC.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leishen6/SpringBoot_shardDB_shardTable/1699375a5a2f2f8b982d5ec5984e597ce30db04e/src/main/resources/application-shardingJDBC.properties -------------------------------------------------------------------------------- /src/main/resources/application-shardingJDBCInline.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/leishen6/SpringBoot_shardDB_shardTable/1699375a5a2f2f8b982d5ec5984e597ce30db04e/src/main/resources/application-shardingJDBCInline.properties -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | # 配置springboot的端口号,不配置的话默认是8080 3 | server.port=8083 4 | 5 | # 引入配置文件 6 | spring.profiles.active=shardingJDBC,mybatis,redis,log 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | ${AnsiColor.BRIGHT_BLUE} 2 | __ __ __ __ ________ ________ ________ ________ ________ ________ __ __ __ __ 3 | / / / / / / / / / _____/ / _____/ / _____/ / _____/ / _____/ / _____/ \ \ \ \ \ \ \ \ 4 | / / / / / / / / / __ \ / __ \ / __ \ / __ \ / __ \ / __ \ \ \ \ \ \ \ \ \ 5 | \ \ \ \ \ \ \ \ \ |__\ \\ |__\ \\ |__\ \\ |__\ \\ |__\ \\ |__\ \ / / / / / / / / 6 | \_\ \_\ \_\ \_\ \_____ / \_____ / \_____ / \_____ / \_____ / \_____ / /_/ /_/ /_/ /_/ 7 | \/ \/ \/ \/ \/ \/ -------------------------------------------------------------------------------- /src/main/resources/mapper/Role.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | INSERT INTO t_role ( 12 | id, role_name 13 | ) 14 | VALUES ( 15 | #{id,jdbcType=INTEGER}, 16 | #{roleName,jdbcType=VARCHAR} 17 | ) 18 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/main/resources/mapper/User.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | INSERT INTO t_user ( 13 | id, age, name 14 | ) 15 | VALUES ( 16 | #{id,jdbcType=INTEGER}, 17 | #{age,jdbcType=INTEGER}, 18 | #{name,jdbcType=VARCHAR} 19 | ) 20 | 21 | 22 | 25 | 26 | 29 | 30 | 31 | update t_user set age=#{age} where name=#{name, jdbcType=VARCHAR} 32 | 33 | 34 | 35 | delete from t_user where name=#{userName, jdbcType=VARCHAR} 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/main/resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/main/resources/sql/springboot0.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 127.0.0.1_3306 5 | Source Server Version : 50716 6 | Source Host : 127.0.0.1:3306 7 | Source Database : springboot0 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50716 11 | File Encoding : 65001 12 | 13 | Date: 2020-06-19 14:23:35 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for t_role 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `t_role`; 22 | CREATE TABLE `t_role` ( 23 | `id` int(11) NOT NULL AUTO_INCREMENT, 24 | `role_name` varchar(128) NOT NULL, 25 | PRIMARY KEY (`id`) 26 | ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; 27 | 28 | -- ---------------------------- 29 | -- Table structure for t_user0 30 | -- ---------------------------- 31 | DROP TABLE IF EXISTS `t_user0`; 32 | CREATE TABLE `t_user0` ( 33 | `id` int(65) NOT NULL AUTO_INCREMENT COMMENT 'id', 34 | `name` varchar(10) DEFAULT NULL COMMENT '姓名', 35 | `age` int(2) DEFAULT NULL COMMENT '年龄', 36 | PRIMARY KEY (`id`) 37 | ) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8; 38 | 39 | -- ---------------------------- 40 | -- Table structure for t_user1 41 | -- ---------------------------- 42 | DROP TABLE IF EXISTS `t_user1`; 43 | CREATE TABLE `t_user1` ( 44 | `id` int(65) NOT NULL AUTO_INCREMENT COMMENT 'id', 45 | `name` varchar(10) DEFAULT NULL COMMENT '姓名', 46 | `age` int(2) DEFAULT NULL COMMENT '年龄', 47 | PRIMARY KEY (`id`) 48 | ) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8; 49 | 50 | -- ---------------------------- 51 | -- Table structure for t_user2 52 | -- ---------------------------- 53 | DROP TABLE IF EXISTS `t_user2`; 54 | CREATE TABLE `t_user2` ( 55 | `id` int(65) NOT NULL AUTO_INCREMENT COMMENT 'id', 56 | `name` varchar(10) DEFAULT NULL COMMENT '姓名', 57 | `age` int(2) DEFAULT NULL COMMENT '年龄', 58 | PRIMARY KEY (`id`) 59 | ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8; 60 | -------------------------------------------------------------------------------- /src/main/resources/sql/springboot1.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : 127.0.0.1_3306 5 | Source Server Version : 50716 6 | Source Host : 127.0.0.1:3306 7 | Source Database : springboot1 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50716 11 | File Encoding : 65001 12 | 13 | Date: 2020-06-19 14:23:42 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for t_user0 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `t_user0`; 22 | CREATE TABLE `t_user0` ( 23 | `id` int(65) NOT NULL AUTO_INCREMENT COMMENT 'id', 24 | `name` varchar(10) DEFAULT NULL COMMENT '姓名', 25 | `age` int(2) DEFAULT NULL COMMENT '年龄', 26 | PRIMARY KEY (`id`) 27 | ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8; 28 | 29 | -- ---------------------------- 30 | -- Table structure for t_user1 31 | -- ---------------------------- 32 | DROP TABLE IF EXISTS `t_user1`; 33 | CREATE TABLE `t_user1` ( 34 | `id` int(65) NOT NULL AUTO_INCREMENT COMMENT 'id', 35 | `name` varchar(10) DEFAULT NULL COMMENT '姓名', 36 | `age` int(2) DEFAULT NULL COMMENT '年龄', 37 | PRIMARY KEY (`id`) 38 | ) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8; 39 | 40 | -- ---------------------------- 41 | -- Table structure for t_user2 42 | -- ---------------------------- 43 | DROP TABLE IF EXISTS `t_user2`; 44 | CREATE TABLE `t_user2` ( 45 | `id` int(65) NOT NULL AUTO_INCREMENT COMMENT 'id', 46 | `name` varchar(10) DEFAULT NULL COMMENT '姓名', 47 | `age` int(2) DEFAULT NULL COMMENT '年龄', 48 | PRIMARY KEY (`id`) 49 | ) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8; 50 | -------------------------------------------------------------------------------- /src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | Archetype Created Web Application 8 | 9 | -------------------------------------------------------------------------------- /src/test/java/com/lyl/RoleRestAPITest.java: -------------------------------------------------------------------------------- 1 | package com.lyl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.lyl.bean.Role; 6 | import com.lyl.utils.RequestParameter; 7 | import org.junit.Test; 8 | import org.springframework.web.client.RestTemplate; 9 | 10 | /** 11 | * @PACKAGE_NAME: com.lyl 12 | * @ClassName: RoleRestAPITest 13 | * @Description: role 单元测试 14 | * @Date: 2020-06-19 13:24 15 | **/ 16 | public class RoleRestAPITest { 17 | 18 | private String roleName = "程序员"; 19 | 20 | @Test 21 | public void addRole() { 22 | RestTemplate restTemplate = new RestTemplate(); 23 | 24 | String url = "http://localhost:8083/v1/api/role/addRole"; 25 | 26 | // 请求参数 27 | RequestParameter re = new RequestParameter<>(); 28 | Role role = new Role(); 29 | role.setRoleName(roleName); 30 | re.setData(role); 31 | 32 | String result = restTemplate.postForObject(url, re, String.class); 33 | 34 | JSONObject resultJsonObject = JSON.parseObject(result); 35 | System.out.println(resultJsonObject.getString("date")); 36 | } 37 | 38 | 39 | @Test 40 | public void findRoleByName() { 41 | RestTemplate restTemplate = new RestTemplate(); 42 | 43 | String url = "http://localhost:8083/v1/api/role/findRoleByName"; 44 | 45 | // 请求参数 46 | RequestParameter re = new RequestParameter<>(); 47 | re.setData(roleName); 48 | 49 | String result = restTemplate.postForObject(url, re, String.class); 50 | 51 | JSONObject resultJsonObject = JSON.parseObject(result); 52 | System.out.println(resultJsonObject.getString("date")); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/lyl/UserRestAPITest.java: -------------------------------------------------------------------------------- 1 | package com.lyl; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.github.pagehelper.PageInfo; 6 | import com.lyl.bean.User; 7 | import com.lyl.utils.RequestParameter; 8 | import org.junit.Test; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | /** 12 | * @Title: UserRestAPITest 13 | * @Description: user 单元测试 14 | * @date: 2019年8月23日 下午8:27:34 15 | */ 16 | public class UserRestAPITest { 17 | 18 | private String userName = "单例模式"; 19 | 20 | 21 | @Test 22 | public void addUser() { 23 | RestTemplate restTemplate = new RestTemplate(); 24 | 25 | String url = "http://localhost:8083/v1/api/user/addUser"; 26 | 27 | // 请求参数 28 | RequestParameter re = new RequestParameter<>(); 29 | User user = new User(); 30 | user.setAge(25); 31 | user.setName(userName); 32 | re.setData(user); 33 | 34 | String result = restTemplate.postForObject(url, re, String.class); 35 | 36 | JSONObject resultJsonObject = JSON.parseObject(result); 37 | System.out.println(resultJsonObject.getString("date")); 38 | } 39 | 40 | @Test 41 | public void deleteUserByName() { 42 | RestTemplate restTemplate = new RestTemplate(); 43 | 44 | String url = "http://localhost:8083/v1/api/user/deleteUserByName"; 45 | // 请求参数 46 | RequestParameter re = new RequestParameter<>(); 47 | re.setData(userName); 48 | 49 | String result = restTemplate.postForObject(url, re, String.class); 50 | 51 | JSONObject resultJsonObject = JSON.parseObject(result); 52 | System.out.println(resultJsonObject.getString("date")); 53 | } 54 | 55 | @Test 56 | public void updateUser() { 57 | RestTemplate restTemplate = new RestTemplate(); 58 | 59 | String url = "http://localhost:8083/v1/api/user/updateUserByName"; 60 | 61 | // 请求参数 62 | RequestParameter re = new RequestParameter<>(); 63 | User user = new User(); 64 | user.setAge(36); 65 | user.setName(userName); 66 | re.setData(user); 67 | 68 | String result = restTemplate.postForObject(url, re, String.class); 69 | 70 | JSONObject resultJsonObject = JSON.parseObject(result); 71 | System.out.println(resultJsonObject.getString("date")); 72 | } 73 | 74 | 75 | @Test 76 | public void findUserByName() { 77 | RestTemplate restTemplate = new RestTemplate(); 78 | 79 | String url = "http://localhost:8083/v1/api/user/findUserByName"; 80 | 81 | // 请求参数 82 | RequestParameter re = new RequestParameter<>(); 83 | re.setData(userName); 84 | 85 | String result = restTemplate.postForObject(url, re, String.class); 86 | 87 | JSONObject resultJsonObject = JSON.parseObject(result); 88 | System.out.println(resultJsonObject.getString("date")); 89 | } 90 | 91 | 92 | @Test 93 | public void findAll() { 94 | RestTemplate restTemplate = new RestTemplate(); 95 | 96 | String url = "http://localhost:8083/v1/api/user/findUserAll"; 97 | 98 | // 无参数的查询使用 getForObject() 99 | String result = restTemplate.getForObject(url, String.class); 100 | 101 | JSONObject resultJsonObject = JSON.parseObject(result); 102 | System.out.println(resultJsonObject.getString("date")); 103 | } 104 | 105 | 106 | @Test 107 | public void findAllByPage() { 108 | RestTemplate restTemplate = new RestTemplate(); 109 | 110 | String url = "http://localhost:8083/v1/api/user/findUserAllByPage"; 111 | 112 | // 请求参数 113 | RequestParameter re = new RequestParameter<>(); 114 | // 分页工具类 115 | PageInfo pageinfo = new PageInfo(); 116 | User user = new User(pageinfo); 117 | user.getPageinfo().setPageNum(1); 118 | user.getPageinfo().setPageSize(10); 119 | re.setData(user); 120 | 121 | String result = restTemplate.postForObject(url, re, String.class); 122 | 123 | JSONObject resultJsonObject = JSON.parseObject(result); 124 | System.out.println(resultJsonObject.getString("date")); 125 | } 126 | 127 | } 128 | --------------------------------------------------------------------------------