
{"id":772,"date":"2020-03-01T12:16:18","date_gmt":"2020-03-01T04:16:18","guid":{"rendered":"https:\/\/www.changxuan.top\/?p=772"},"modified":"2021-04-30T08:51:22","modified_gmt":"2021-04-30T00:51:22","slug":"spring-boot2-x-%e5%8a%a8%e6%80%81%e6%95%b0%e6%8d%ae%e6%ba%90%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.changxuan.top\/?p=772","title":{"rendered":"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e"},"content":{"rendered":"\n<p>\u57fa\u4e8e Spring Boot 2.x\u3001Spring Data JPA\u3001druid\u3001mysql  \u7684\u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6eDemo\uff0c\u9002\u5408\u7528\u4e8e\u6570\u636e\u5e93\u7684\u8bfb\u5199\u5206\u79bb\u7b49\u5e94\u7528\u573a\u666f\u3002\u901a\u8fc7\u5728Service\u5c42\u65b9\u6cd5\u4e0a\u6dfb\u52a0\u81ea\u5b9a\u4e49\u6ce8\u89e3\u5b9e\u73b0\u8bfb\u5199\u4e0d\u540c\u7684\u6570\u636e\u5e93\u3002 \u540c\u65f6\u89e3\u51b3\u4e86\u4e0d\u80fd\u5728\u540c\u4e00\u4e2aService\u4e2d\u5207\u6362\u591a\u4e2a\u6570\u636e\u6e90\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u914d\u7f6e\u6587\u4ef6\u5df2\u914d\u7f6e\u597ddruid\u76d1\u63a7\u76f8\u5173\u5c5e\u6027\uff0c\u76d1\u63a7\u9875\u9762\u94fe\u63a5\uff1aip:8080\/druid\u3002\u8d26\u53f7\uff1aadmin\uff0c\u5bc6\u7801\uff1a123456\u3002\u8be6\u60c5\u67e5\u770b application.yml \u6587\u4ef6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879\uff08\u524d\u8a00\uff09<\/h4>\n\n\n\n<p>\u5728\u7f51\u4e0a\u6709\u5f88\u591a\u5173\u4e8e\u52a8\u6001\u5207\u6362\u6570\u636e\u6e90\u7684\u914d\u7f6e\u6559\u7a0b\uff0c\u5176\u4e2d\u767e\u5206\u4e4b\u4e5d\u5341\u7684\u90fd\u662f\u57fa\u4e8e Mybatis \u7684\u3002\u5f53\u7136\u4e5f\u6709\u96f6\u661f\u7684\u51e0\u7bc7\u57fa\u4e8e Spring Data JPA \u7684\u914d\u7f6e\u6559\u7a0b\uff0c\u4e0d\u8fc7\u5f53\u4f60\u6309\u7740\u8fd9\u4e9b\u6559\u7a0b\u4f7f\u7528\u540e\u5c31\u4f1a\u53d1\u73b0\u9760\u8c31\u4e00\u70b9\u7684\u8fd8\u53ef\u4ee5\u505a\u5230\u4e0d\u540c\u7684\u8bf7\u6c42\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u6570\u636e\u6e90\uff0c\u4f46\u662f\u65e0\u6cd5\u505a\u5230\u5728\u540c\u4e00\u4e2a\u8bf7\u6c42\u5185\u8fdb\u884c\u591a\u4e2a\u6570\u636e\u6e90\u4e4b\u95f4\u7684\u5207\u6362\u3002\u5728\u4e1a\u52a1\u903b\u8f91\u76f8\u5bf9\u590d\u6742\u7684\u60c5\u51b5\u4e0b\u80af\u5b9a\u662f\u4e0d\u80fd\u6ee1\u8db3\u9700\u6c42\u7684\u3002<\/p>\n\n\n\n<p><strong>\u90a3\u4e48\u662f\u4ec0\u4e48\u539f\u56e0\u5bfc\u81f4\u5728\u540c\u4e00\u8bf7\u6c42\u5185\u5207\u6362\u6570\u636e\u6e90\u5931\u8d25\u5462\uff1f<\/strong>\u7ecf\u8fc7\u5355\u6b65\u8c03\u8bd5\u548c\u67e5\u770b\u65e5\u5fd7\u53d1\u73b0\u81ea\u5df1\u5199\u7684\u6ce8\u89e3\u786e\u5b9e\u751f\u6548\u4e86\uff0c\u53ea\u4e0d\u8fc7\u5728\u7b2c\u4e8c\u6b21\u5207\u6362\u6570\u636e\u6e90\u65f6\u6ca1\u6709\u6267\u884c <code>AbstractRoutingDataSource<\/code> \u7684 <code>determineCurrentLookupKey()<\/code> \u7684\u65b9\u6cd5\u800c\u662f\u76f4\u63a5\u62ff\u5230\u4e86\u6570\u636e\u5e93\u8fde\u63a5\u53bb\u6267\u884c\u4e86SQL\u8bed\u53e5\u3002\u90a3\u4e48\u8fd9\u4e2a\u65b9\u6cd5\u662f\u505a\u4ec0\u4e48\u7684\u5462\uff1f<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">protected DataSource determineTargetDataSource() {\n        Assert.notNull(this.resolvedDataSources, \"DataSource router not initialized\");\n        Object lookupKey = this.determineCurrentLookupKey();\n        DataSource dataSource = (DataSource)this.resolvedDataSources.get(lookupKey);\n        if (dataSource == null &amp;amp;&amp;amp; (this.lenientFallback || lookupKey == null)) {\n            dataSource = this.resolvedDefaultDataSource;\n        }\n\n        if (dataSource == null) {\n            throw new IllegalStateException(\"Cannot determine target DataSource for lookup key [\" + lookupKey + \"]\");\n        } else {\n            return dataSource;\n        }\n    }<\/pre>\n\n\n\n<p>\u4ece\u65b9\u6cd5\u547d\u540d\u4e5f\u80fd\u770b\u51fa\u6765\u8fd9\u662f\u4e2a\u6765\u51b3\u5b9a\u4f7f\u7528\u54ea\u4e2a\u6570\u636e\u6e90\u7684\u65b9\u6cd5\u3002\u4e0a\u8ff0\u6e90\u7801\u7b2c\u4e09\u884c\u901a\u8fc7\u8c03\u7528 <code>this.determineCurrentLookupKey();<\/code> \u65b9\u6cd5\u83b7\u53d6\u5e94\u8be5\u4f7f\u7528\u7684\u6570\u636e\u6e90\u6240\u5bf9\u5e94\u7684 key \u503c\u3002\u4e5f\u5c31\u662f\u6211\u4eec\u5728 <code>DataSourceContextHolder<\/code> \u653e\u5230 <strong><em><code>contextHolder<\/code><\/em><\/strong> \u4e2d\u7684\u503c\u3002\u56e0\u4e3a\u6211\u4eec\u4f7f\u7528 <code>DynamicDataSource<\/code> \u7ee7\u627f <code>AbstractRoutingDataSource<\/code> \u5e76\u91cd\u5199\u4e86  <code>determineCurrentLookupKey() <\/code> \u65b9\u6cd5\u3002\u5728\u91cd\u5199\u7684\u65b9\u6cd5\u4e2d\u6211\u4eec\u83b7\u53d6\u5230\u4e86\u4e4b\u524d\u5b58\u5165\u7684\u6570\u636e\u6e90\u6240\u5bf9\u5e94\u7684key\uff0c\u6240\u4ee5\u5982\u679c\u6bcf\u6b21\u5207\u6362\u6570\u636e\u6e90\u65f6\u6267\u884c\u6b64\u65b9\u6cd5\u540e\u624d\u7b97\u5207\u6362\u6210\u529f\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\u4e3a\u4ec0\u4e48\u4f7f\u7528 Spring Data JPA \u5207\u6362\u4e00\u6b21\u6570\u636e\u6e90\u540e\u7b2c\u4e8c\u6b21\u5c31\u5207\u4e0d\u8fc7\u53bb\u4e86\u5462\uff1f\u7ecf\u8fc7\u67e5\u9605\u8d44\u6599\u53d1\u73b0\uff0c\u5728\u65b9\u6cd5\u95f4\u7684\u4e8b\u52a1\u4f20\u9012\u4e2d\u5982\u679c\u4e0d\u914d\u7f6e\u4e8b\u52a1\u7684\u4f20\u64ad\u7ea7\u522b\u662f\u4e0d\u4f1a\u5f00\u542f\u4e00\u4e2a\u65b0\u4e8b\u52a1\u7684\uff0c\u56e0\u4e3a Spring \u9ed8\u8ba4\u7684\u4e8b\u52a1\u7ea7\u522b\u662f <code> PROPAGATION_REQUIRED <\/code> \uff0c\u4f7f\u7528\u540c\u4e00\u4e2a\u4e8b\u52a1\u3002\u4e5f\u5c31\u662f\u8bf4\u5982\u679c\u4e0d\u5f00\u542f\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\u5c31\u4e0d\u4f1a\u8fdb\u884c\u6570\u636e\u6e90\u7684\u5207\u6362\u3002\u56e0\u4e3aSpring Data JPA \u6574\u5408\u4e86 hibernate \uff0c\u4e14 hibernate \u7684 session \u662f\u4e0e transaction \u7ed1\u5b9a\u7684\uff0c\u6240\u4ee5\u591a\u6b21\u5207\u6362\u6570\u636e\u6e90\u65f6\u83b7\u53d6\u5230\u7684 session \u7684 hashCode \u662f\u540c\u4e00\u4e2a\u4e5f\u5c31\u662f\u7b2c\u4e00\u6b21\u5207\u6362\u7684\u6570\u636e\u6e90\u3002\u8fd9\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48\u5728\u540c\u4e00\u4e2a Service \u4e2d\u65e0\u6cd5\u505a\u5230\u53ef\u4ee5\u5207\u6362\u591a\u4e2a\u6570\u636e\u6e90\u3002\uff08\u6ce8\uff1a\u6b64 session \u975e\u5e38\u8bf4\u7684 web \u4e2d\u7684\u90a3\u4e2a session\uff09<\/p>\n\n\n\n<p><strong>\u90a3\u600e\u4e48\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f<\/strong>\u65e2\u7136session\u548c\u5f53\u524d\u7684\u4e8b\u52a1\u662f\u7ed1\u5b9a\u7684\uff0c\u90a3\u662f\u4e0d\u662f\u5728\u5207\u7247\u4e2d\u628a\u8981\u5207\u6362\u7684 key \u503c\u5b58\u50a8\u5230   <strong><em><code>contextHolder<\/code><\/em><\/strong>  \u4e2d\u540e\uff0c\u624b\u52a8\u65ad\u6389\u539f\u6765\u7684session\u8fde\u63a5\u5c31\u53ef\u4ee5\u4e86\uff1f\u5728\u5207\u7247\u64cd\u4f5c\u4e2d\u52a0\u5165\u4e0b\u9762\u4e24\u884c\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SessionImplementor session = entityManager.unwrap(SessionImplementor.class);\n\/\/\u6700\u5173\u952e\u7684\u4e00\u53e5\u4ee3\u7801\uff0c \u624b\u52a8\u65ad\u5f00\u8fde\u63a5\uff0c\u4e0d\u7528\u91cd\u65b0\u8bbe\u7f6e \uff0c\u4f1a\u81ea\u52a8\u91cd\u65b0\u8bbe\u7f6e\u8fde\u63a5\u3002\nsession.disconnect();<\/pre>\n\n\n\n<p>\u7ecf\u8fc7\u6d4b\u8bd5\u8fd9\u6837\u8bbe\u7f6e\u540e\u5219\u53ef\u4ee5\u5728\u540c\u4e00\u4e2a Service \u4e2d\u5207\u6362\u64cd\u4f5c\u4e0d\u540c\u7684\u6570\u636e\u6e90\u8bfb\u5199\u6570\u636e\u3002<\/p>\n\n\n\n<p><strong>\u6ce8\u610f\uff1a<\/strong>\u5982\u679c\u5728\u4e00\u6b21\u8bf7\u6c42\u4e2d\u901a\u8fc7\u6570\u636e\u6e90A\u6267\u884c\u7684\u4e00\u6761SQL\u8bed\u53e5\uff0c\u7136\u540e\u53c8\u5207\u6362\u5230\u6570\u636e\u6e90B\u6267\u884c\u540c\u6837\u7684SQL\u8bed\u53e5\u3002\u6b64\u65f6\u6846\u67b6\u4e3a\u4e86\u6027\u80fd\u4f1a\u76f4\u63a5\u8fd4\u56de\u4ece\u6570\u636e\u6e90A\u7684\u6570\u636e\u5e93\u4e2d\u67e5\u8be2\u5230\u7684\u6570\u636e\u3002\u6240\u4ee5\u8fd9\u79cd\u60c5\u51b5\u662f\u4f1a\u5207\u6362\u5931\u8d25\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u914d\u7f6e pom.xml \u6587\u4ef6<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">     &lt;dependencies>\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-starter-aop&lt;\/artifactId>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>com.alibaba&lt;\/groupId>\n            &lt;artifactId>druid-spring-boot-starter&lt;\/artifactId>\n            &lt;version>1.1.21&lt;\/version>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>mysql&lt;\/groupId>\n            &lt;artifactId>mysql-connector-java&lt;\/artifactId>\n        &lt;\/dependency>\n\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-starter-data-jdbc&lt;\/artifactId>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-starter-data-jpa&lt;\/artifactId>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-starter-web&lt;\/artifactId>\n        &lt;\/dependency>\n\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-devtools&lt;\/artifactId>\n            &lt;scope>runtime&lt;\/scope>\n            &lt;optional>true&lt;\/optional>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-configuration-processor&lt;\/artifactId>\n            &lt;optional>true&lt;\/optional>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.projectlombok&lt;\/groupId>\n            &lt;artifactId>lombok&lt;\/artifactId>\n            &lt;optional>true&lt;\/optional>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>org.springframework.boot&lt;\/groupId>\n            &lt;artifactId>spring-boot-starter-test&lt;\/artifactId>\n            &lt;scope>test&lt;\/scope>\n            &lt;exclusions>\n                &lt;exclusion>\n                    &lt;groupId>org.junit.vintage&lt;\/groupId>\n                    &lt;artifactId>junit-vintage-engine&lt;\/artifactId>\n                &lt;\/exclusion>\n            &lt;\/exclusions>\n        &lt;\/dependency>\n        &lt;dependency>\n            &lt;groupId>junit&lt;\/groupId>\n            &lt;artifactId>junit&lt;\/artifactId>\n            &lt;scope>test&lt;\/scope>\n        &lt;\/dependency>\n    &lt;\/dependencies><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u914d\u7f6eapplication.yml\u6587\u4ef6<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"yaml\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">spring:\n  datasource:\n    druid:\n      primary:\n        driverClassName: com.mysql.cj.jdbc.Driver\n        username: root\n        password: root\n        url: jdbc:mysql:\/\/localhost:3306\/primary?useUnicode=true&amp;amp;characterEncoding=UTF-8&amp;amp;serverTimezone=GMT%2B8\n        filters: stat,wall\n      local:\n        driver-class-name: com.mysql.cj.jdbc.Driver\n        username: root\n        password: root\n        url: jdbc:mysql:\/\/localhost:3306\/local?useUnicode=true&amp;amp;characterEncoding=UTF-8&amp;amp;serverTimezone=GMT%2B8\n        filters: stat,wall\n      stat-view-servlet:\n        enabled: true\n        login-username: admin\n        login-password: 123456\n        reset-enable: false\n        url-pattern: \/druid\/*\n      web-stat-filter:\n        enabled: true\n        # \u6dfb\u52a0\u8fc7\u6ee4\u89c4\u5219\n        url-pattern: \/*\n        # \u5ffd\u7565\u8fc7\u6ee4\u683c\u5f0f\n        exclusions: \"*.js,*.gif,*.jpg,*.png,*.css,*.ico,\/druid\/*\"\n  jpa:\n    database: MYSQL\n    hibernate:\n      show_sql: true\n      format_sql: true\n      primary-dialect: org.hibernate.dialect.MySQL5InnoDBDialect\n      secondary-dialect: org.hibernate.dialect.MySQL5InnoDBDialect\n      # \u6253\u5f00\u540e\u4f1a\u81ea\u52a8\u5728\u4e3b\u5e93\u751f\u6210\u8868\n      # ddl-auto: update\n    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect\n    # \u6253\u5f00\u540e\u4f1a\u81ea\u52a8\u5728\u4e3b\u5e93\u751f\u6210\u8868\n    # generate-ddl: true\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u9879\u76ee\u76ee\u5f55\u7ed3\u6784<\/h4>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"511\" height=\"542\" src=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png\" alt=\"\" class=\"wp-image-775\" srcset=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png 511w, https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-283x300.png 283w\" sizes=\"auto, (max-width: 511px) 100vw, 511px\" \/><figcaption>\u76ee\u5f55\u7ed3\u6784<\/figcaption><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">DataSource.java<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package dynamic.data.annotation;\n\nimport dynamic.data.common.ContextConst;\n\nimport java.lang.annotation.*;\n\/**\n * @Author: ChangXuan\n * @Decription:\n * @Date: 22:25 2020\/2\/23\n **\/\n@Target({ElementType.TYPE,ElementType.METHOD})\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\npublic @interface DataSource {\n    ContextConst.DataSourceType value() default ContextConst.DataSourceType.PRIMARY;\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">DynamicDataSourceAspect.java<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package dynamic.data.aspect;\n\nimport dynamic.data.common.ContextConst;\nimport dynamic.data.datasource.DataSourceContextHolder;\nimport dynamic.data.annotation.DataSource;\nimport org.aspectj.lang.JoinPoint;\nimport org.aspectj.lang.annotation.After;\nimport org.aspectj.lang.annotation.Aspect;\nimport org.aspectj.lang.annotation.Before;\nimport org.aspectj.lang.reflect.MethodSignature;\nimport org.springframework.stereotype.Component;\n\nimport javax.persistence.EntityManager;\nimport java.lang.reflect.Method;\n\/**\n * @Author: ChangXuan\n * @Decription:\n * @Date: 22:28 2020\/2\/23\n **\/\n@Component\n@Aspect\npublic class DynamicDataSourceAspect {\n\n    @Autowired\n    private EntityManager entityManager;\n    @Before(\"execution(* dynamic.data.service..*.*(..))\")\n    public void before(JoinPoint point){\n        try {\n            DataSource annotationOfClass = point.getTarget().getClass().getAnnotation(DataSource.class);\n            String methodName = point.getSignature().getName();\n            Class[] parameterTypes = ((MethodSignature) point.getSignature()).getParameterTypes();\n            Method method = point.getTarget().getClass().getMethod(methodName, parameterTypes);\n            DataSource methodAnnotation = method.getAnnotation(DataSource.class);\n            methodAnnotation = methodAnnotation == null ? annotationOfClass:methodAnnotation;\n            ContextConst.DataSourceType dataSourceType = methodAnnotation != null &amp;amp;&amp;amp; methodAnnotation.value() !=null ? methodAnnotation.value() :ContextConst.DataSourceType.PRIMARY ;\n            DataSourceContextHolder.setDataSource(dataSourceType.name());\n            SessionImplementor session = entityManager.unwrap(SessionImplementor.class);\n            \/\/\u6700\u5173\u952e\u7684\u4e00\u53e5\u4ee3\u7801\uff0c \u624b\u52a8\u65ad\u5f00\u8fde\u63a5\uff0c\u4e0d\u7528\u91cd\u65b0\u8bbe\u7f6e \uff0c\u4f1a\u81ea\u52a8\u91cd\u65b0\u8bbe\u7f6e\u8fde\u63a5\u3002\n            session.disconnect();\n        } catch (NoSuchMethodException e) {\n            e.printStackTrace();\n        }\n    }\n\n    @After(\"execution(* dynamic.data.service..*.*(..))\")\n    public void after(JoinPoint point){\n        DataSourceContextHolder.clearDataSource();\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"> ContextConst.java<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package dynamic.data.common;\n\n\/**\n * @Author: ChangXuan\n * @Decription:\n * @Date: 22:17 2020\/2\/23\n **\/\npublic interface ContextConst {\n    enum DataSourceType{\n        PRIMARY,LOCAL\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">DataSourceContextHolder .java<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package dynamic.data.datasource;\n\n\/**\n * @Author: ChangXuan\n * @Decription:\n * @Date: 22:23 2020\/2\/23\n **\/\npublic class DataSourceContextHolder {\n\n    private static final ThreadLocal&amp;lt;String&amp;gt; contextHolder = new ThreadLocal&amp;lt;String&amp;gt;();\n\n    public static void setDataSource(String dbType){\n        System.out.println(\"\u5207\u6362\u5230[\"+dbType+\"]\u6570\u636e\u6e90\");\n        contextHolder.set(dbType);\n    }\n\n    public static String getDataSource(){\n        return contextHolder.get();\n    }\n\n    public static void clearDataSource(){\n        contextHolder.remove();\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">DynamicDataSource.java<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package dynamic.data.datasource;\n\nimport org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;\n\n\/**\n * @Author: ChangXuan\n * @Decription:\n * @Date: 22:22 2020\/2\/23\n **\/\npublic class DynamicDataSource extends AbstractRoutingDataSource {\n    @Override\n    protected Object determineCurrentLookupKey() {\n        return DataSourceContextHolder.getDataSource();\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">MutiplyDataSource.java<\/h4>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">package dynamic.data.datasource;\n\nimport com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;\nimport dynamic.data.common.ContextConst;\nimport org.springframework.boot.context.properties.ConfigurationProperties;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.jdbc.datasource.DataSourceTransactionManager;\nimport org.springframework.transaction.PlatformTransactionManager;\n\nimport javax.sql.DataSource;\nimport java.util.HashMap;\n\/**\n * @Author: ChangXuan\n * @Decription:\n * @Date: 22:15 2020\/2\/23\n **\/\n@Configuration\npublic class MutiplyDataSource {\n    @Bean(name = \"dataSourcePrimary\")\n    @ConfigurationProperties(prefix = \"spring.datasource.druid.primary\")\n    public DataSource primaryDataSource(){\n        return DruidDataSourceBuilder.create().build();\n    }\n\n    @Bean(name = \"dataSourceLocal\")\n    @ConfigurationProperties(prefix = \"spring.datasource.druid.local\")\n    public DataSource localDataSource(){\n        return DruidDataSourceBuilder.create().build();\n    }\n\n    @Primary\n    @Bean(name = \"dynamicDataSource\")\n    public DataSource dynamicDataSource() {\n        DynamicDataSource dynamicDataSource = new DynamicDataSource();\n        \/\/\u914d\u7f6e\u9ed8\u8ba4\u6570\u636e\u6e90\n        dynamicDataSource.setDefaultTargetDataSource(primaryDataSource());\n\n        \/\/\u914d\u7f6e\u591a\u6570\u636e\u6e90\n        HashMap&lt;Object, Object> dataSourceMap = new HashMap();\n        dataSourceMap.put(ContextConst.DataSourceType.PRIMARY.name(),primaryDataSource());\n        dataSourceMap.put(ContextConst.DataSourceType.LOCAL.name(),localDataSource());\n        dynamicDataSource.setTargetDataSources(dataSourceMap);\n        return dynamicDataSource;\n    }\n\n    \/**\n     * \u914d\u7f6e@Transactional\u6ce8\u89e3\u4e8b\u52a1\n     * @return\n     *\/\n    @Bean\n    public PlatformTransactionManager transactionManager() {\n        return new DataSourceTransactionManager(dynamicDataSource());\n    }\n\n\n}\n\n<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f7f\u7528<\/h4>\n\n\n\n<p>\u5728 DynamicDataSourceAspect.java \u4e2d\u914d\u7f6e\u7684service\u4e0b\u4f7f\u7528\u6ce8\u89e3\u7684\u65b9\u5f0f\u6307\u5b9a\u6267\u884c\u7684\u65b9\u6cd5\u4f7f\u7528\u54ea\u4e2a\u6570\u636e\u5e93\u3002\u793a\u4f8b\u53c2\u8003\u4e0b\u65b9\u4ee3\u7801\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"890\" height=\"460\" src=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-1.png\" alt=\"\" class=\"wp-image-778\" srcset=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-1.png 890w, https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-1-300x155.png 300w, https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-1-768x397.png 768w\" sizes=\"auto, (max-width: 890px) 100vw, 890px\" \/><figcaption>\u4f7f\u7528\u793a\u4f8b<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"483\" height=\"281\" src=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-2.png\" alt=\"\" class=\"wp-image-781\" srcset=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-2.png 483w, https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-2-300x175.png 300w\" sizes=\"auto, (max-width: 483px) 100vw, 483px\" \/><figcaption>primary\u6570\u636e\u5e93<\/figcaption><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"485\" height=\"285\" src=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-3.png\" alt=\"\" class=\"wp-image-782\" srcset=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-3.png 485w, https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image-3-300x176.png 300w\" sizes=\"auto, (max-width: 485px) 100vw, 485px\" \/><figcaption>local<\/figcaption><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e Spring Boot 2.x\u3001Spring Data JPA\u3001druid\u3001mysql \u7684\u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e &hellip; <a href=\"https:\/\/www.changxuan.top\/?p=772\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,54],"tags":[77,75,76],"class_list":["post-772","post","type-post","status-publish","format-standard","hentry","category-tech","category-54","tag-druid","tag-springboot","tag-76"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e - \u5e38\u8f69<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.changxuan.top\/?p=772\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e - \u5e38\u8f69\" \/>\n<meta property=\"og:description\" content=\"\u57fa\u4e8e Spring Boot 2.x\u3001Spring Data JPA\u3001druid\u3001mysql \u7684\u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e &hellip; \u7ee7\u7eed\u9605\u8bfbSpring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.changxuan.top\/?p=772\" \/>\n<meta property=\"og:site_name\" content=\"\u5e38\u8f69\" \/>\n<meta property=\"article:published_time\" content=\"2020-03-01T04:16:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-04-30T00:51:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png\" \/>\n<meta name=\"author\" content=\"\u5e38\u8f69\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u5e38\u8f69\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772\"},\"author\":{\"name\":\"\u5e38\u8f69\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/#\\\/schema\\\/person\\\/08c8f0af44536928094dc1b4f88da3bd\"},\"headline\":\"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e\",\"datePublished\":\"2020-03-01T04:16:18+00:00\",\"dateModified\":\"2021-04-30T00:51:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772\"},\"wordCount\":74,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/#\\\/schema\\\/person\\\/08c8f0af44536928094dc1b4f88da3bd\"},\"image\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/image.png\",\"keywords\":[\"druid\",\"SpringBoot\",\"\u591a\u6570\u636e\u6e90\"],\"articleSection\":[\"\u6280\u672f\",\"\u6559\u7a0b\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.changxuan.top\\\/?p=772#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772\",\"url\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772\",\"name\":\"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e - \u5e38\u8f69\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/image.png\",\"datePublished\":\"2020-03-01T04:16:18+00:00\",\"dateModified\":\"2021-04-30T00:51:22+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.changxuan.top\\\/?p=772\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#primaryimage\",\"url\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/image.png\",\"contentUrl\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2020\\\/03\\\/image.png\",\"width\":511,\"height\":542},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/?p=772#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\\\/\\\/www.changxuan.top\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/#website\",\"url\":\"https:\\\/\\\/www.changxuan.top\\\/\",\"name\":\"\u5e38\u8f69\",\"description\":\"\u95fb\u9053\u6709\u5148\u540e\uff0c\u672f\u4e1a\u6709\u4e13\u653b-\u4e00\u4e8c\u4e09\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/#\\\/schema\\\/person\\\/08c8f0af44536928094dc1b4f88da3bd\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.changxuan.top\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/#\\\/schema\\\/person\\\/08c8f0af44536928094dc1b4f88da3bd\",\"name\":\"\u5e38\u8f69\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/IMG_008520200606-095631.jpg\",\"url\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/IMG_008520200606-095631.jpg\",\"contentUrl\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/IMG_008520200606-095631.jpg\",\"width\":960,\"height\":960,\"caption\":\"\u5e38\u8f69\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.changxuan.top\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/IMG_008520200606-095631.jpg\"},\"description\":\"\u603b\u8981\u505a\u70b9\u4ec0\u4e48\u5427\uff01\",\"sameAs\":[\"https:\\\/\\\/www.changxuan.top\"],\"url\":\"https:\\\/\\\/www.changxuan.top\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e - \u5e38\u8f69","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.changxuan.top\/?p=772","og_locale":"zh_CN","og_type":"article","og_title":"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e - \u5e38\u8f69","og_description":"\u57fa\u4e8e Spring Boot 2.x\u3001Spring Data JPA\u3001druid\u3001mysql \u7684\u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e &hellip; \u7ee7\u7eed\u9605\u8bfbSpring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e","og_url":"https:\/\/www.changxuan.top\/?p=772","og_site_name":"\u5e38\u8f69","article_published_time":"2020-03-01T04:16:18+00:00","article_modified_time":"2021-04-30T00:51:22+00:00","og_image":[{"url":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png","type":"","width":"","height":""}],"author":"\u5e38\u8f69","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u5e38\u8f69","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.changxuan.top\/?p=772#article","isPartOf":{"@id":"https:\/\/www.changxuan.top\/?p=772"},"author":{"name":"\u5e38\u8f69","@id":"https:\/\/www.changxuan.top\/#\/schema\/person\/08c8f0af44536928094dc1b4f88da3bd"},"headline":"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e","datePublished":"2020-03-01T04:16:18+00:00","dateModified":"2021-04-30T00:51:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.changxuan.top\/?p=772"},"wordCount":74,"commentCount":0,"publisher":{"@id":"https:\/\/www.changxuan.top\/#\/schema\/person\/08c8f0af44536928094dc1b4f88da3bd"},"image":{"@id":"https:\/\/www.changxuan.top\/?p=772#primaryimage"},"thumbnailUrl":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png","keywords":["druid","SpringBoot","\u591a\u6570\u636e\u6e90"],"articleSection":["\u6280\u672f","\u6559\u7a0b"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.changxuan.top\/?p=772#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.changxuan.top\/?p=772","url":"https:\/\/www.changxuan.top\/?p=772","name":"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e - \u5e38\u8f69","isPartOf":{"@id":"https:\/\/www.changxuan.top\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.changxuan.top\/?p=772#primaryimage"},"image":{"@id":"https:\/\/www.changxuan.top\/?p=772#primaryimage"},"thumbnailUrl":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png","datePublished":"2020-03-01T04:16:18+00:00","dateModified":"2021-04-30T00:51:22+00:00","breadcrumb":{"@id":"https:\/\/www.changxuan.top\/?p=772#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.changxuan.top\/?p=772"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.changxuan.top\/?p=772#primaryimage","url":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png","contentUrl":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2020\/03\/image.png","width":511,"height":542},{"@type":"BreadcrumbList","@id":"https:\/\/www.changxuan.top\/?p=772#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.changxuan.top\/"},{"@type":"ListItem","position":2,"name":"Spring Boot2.x \u52a8\u6001\u6570\u636e\u6e90\u914d\u7f6e"}]},{"@type":"WebSite","@id":"https:\/\/www.changxuan.top\/#website","url":"https:\/\/www.changxuan.top\/","name":"\u5e38\u8f69","description":"\u95fb\u9053\u6709\u5148\u540e\uff0c\u672f\u4e1a\u6709\u4e13\u653b-\u4e00\u4e8c\u4e09","publisher":{"@id":"https:\/\/www.changxuan.top\/#\/schema\/person\/08c8f0af44536928094dc1b4f88da3bd"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.changxuan.top\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.changxuan.top\/#\/schema\/person\/08c8f0af44536928094dc1b4f88da3bd","name":"\u5e38\u8f69","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2021\/04\/IMG_008520200606-095631.jpg","url":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2021\/04\/IMG_008520200606-095631.jpg","contentUrl":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2021\/04\/IMG_008520200606-095631.jpg","width":960,"height":960,"caption":"\u5e38\u8f69"},"logo":{"@id":"https:\/\/www.changxuan.top\/wp-content\/uploads\/2021\/04\/IMG_008520200606-095631.jpg"},"description":"\u603b\u8981\u505a\u70b9\u4ec0\u4e48\u5427\uff01","sameAs":["https:\/\/www.changxuan.top"],"url":"https:\/\/www.changxuan.top\/?author=1"}]}},"views":2182,"_links":{"self":[{"href":"https:\/\/www.changxuan.top\/index.php?rest_route=\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.changxuan.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.changxuan.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.changxuan.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.changxuan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=772"}],"version-history":[{"count":19,"href":"https:\/\/www.changxuan.top\/index.php?rest_route=\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":1428,"href":"https:\/\/www.changxuan.top\/index.php?rest_route=\/wp\/v2\/posts\/772\/revisions\/1428"}],"wp:attachment":[{"href":"https:\/\/www.changxuan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.changxuan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.changxuan.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}