{"id":3744,"date":"2022-08-19T14:15:52","date_gmt":"2022-08-19T06:15:52","guid":{"rendered":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=3744"},"modified":"2022-08-19T14:15:52","modified_gmt":"2022-08-19T06:15:52","slug":"mybatis-plus%e5%ae%9e%e7%8e%b0%e5%a4%9a%e7%a7%9f%e6%88%b7%e6%9e%b6%e6%9e%84","status":"publish","type":"post","link":"https:\/\/www.zeroheart.xyz\/wordpress\/?p=3744","title":{"rendered":"Mybatis-plus\u5b9e\u73b0\u591a\u79df\u6237\u67b6\u6784"},"content":{"rendered":"\n<p>\u4e4b\u524d\u505a\u8fc7sass\u7684\u5e94\u7528\uff0c\u4f7f\u7528\u7684\u662f\u52a8\u6001\u6570\u636e\u6e90<\/p>\n\n\n\n<p>\u51c6\u5907\u4e86\u89e3\u4e0bmybatisplus\u7684\u67b6\u6784\uff0c\u53d1\u73b0\u65f6\u5b57\u6bb5\u7ea7\u522b\u7684\u591a\u79df\u6237\uff0c\u5c0f\u89c4\u6a21\u5e94\u7528\u6216\u8bb8\u80fd\u7528\u7528\u3002<\/p>\n\n\n\n<p>\u539f\u6587\uff1a<a href=\"http:\/\/www.qb5200.com\/article\/474692.html\">Mybatis-plus\u5b9e\u73b0\u591a\u79df\u6237\u67b6\u6784(IT\u6280\u672f) (qb5200.com)<\/a><\/p>\n\n\n\n<p>\u591a\u79df\u6237(Multi-Tenant)\u662fSaaS\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u6982\u5ff5\uff0c\u5b83\u662f\u4e00\u79cd\u8f6f\u4ef6\u67b6\u6784\u6280\u672f\uff0c\u5728\u591a\u4e2a\u79df\u6237\u7684\u73af\u5883\u4e0b\uff0c\u5171\u4eab\u540c\u4e00\u5957\u7cfb\u7edf\u5b9e\u4f8b\uff0c\u5e76\u4e14\u79df\u6237\u4e4b\u95f4\u7684\u6570\u636e\u5177\u6709\u9694\u79bb\u6027\uff0c\u4e5f\u5c31\u662f\u8bf4\u4e00\u4e2a\u79df\u6237\u4e0d\u80fd\u53bb\u8bbf\u95ee\u5176\u4ed6\u79df\u6237\u7684\u6570\u636e\u3002\u57fa\u4e8e\u4e0d\u540c\u7684\u9694\u79bb\u7ea7\u522b\uff0c\u901a\u5e38\u5177\u6709\u4e0b\u9762\u4e09\u79cd\u5b9e\u73b0\u65b9\u6848\uff1a<\/p>\n\n\n\n<p>1\u3001\u6bcf\u4e2a\u79df\u6237\u4f7f\u7528\u72ec\u7acbDataBase\uff0c\u9694\u79bb\u7ea7\u522b\u9ad8\uff0c\u6027\u80fd\u597d\uff0c\u4f46\u6210\u672c\u5927<\/p>\n\n\n\n<p>2\u3001\u79df\u6237\u4e4b\u95f4\u5171\u4eabDataBase\uff0c\u4f7f\u7528\u72ec\u7acb\u7684Schema<\/p>\n\n\n\n<p>3\u3001\u79df\u6237\u4e4b\u95f4\u5171\u4eabSchema\uff0c\u5728\u8868\u4e0a\u6dfb\u52a0\u79df\u6237\u5b57\u6bb5\uff0c\u5171\u4eab\u6570\u636e\u7a0b\u5ea6\u6700\u9ad8\uff0c\u9694\u79bb\u7ea7\u522b\u6700\u4f4e\u3002<\/p>\n\n\n\n<p>Mybatis-plus\u5728\u7b2c3\u5c42\u9694\u79bb\u7ea7\u522b\u4e0a\uff0c\u63d0\u4f9b\u4e86\u57fa\u4e8e\u5206\u9875\u63d2\u4ef6\u7684\u591a\u79df\u6237\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u6211\u4eec\u5bf9\u6b64\u6765\u8fdb\u884c\u4ecb\u7ecd\u3002\u5728\u6b63\u5f0f\u5f00\u59cb\u524d\uff0c\u9996\u5148\u505a\u597d\u51c6\u5907\u5de5\u4f5c\u521b\u5efa\u4e24\u5f20\u8868\uff0c\u5728\u57fa\u7840\u5b57\u6bb5\u540e\u90fd\u6dfb\u52a0\u79df\u6237\u5b57\u6bb5tenant_id\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TABLE `user` (\n  `id` bigint(20) NOT NULL,\n  `name` varchar(20) DEFAULT NULL,\n  `phone` varchar(11) DEFAULT NULL,\n  `address` varchar(64) DEFAULT NULL,\n  `tenant_id` bigint(20) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n)\nCREATE TABLE `dept` (\n  `id` bigint(20) NOT NULL,\n  `dept_name` varchar(64) DEFAULT NULL,\n  `comment` varchar(128) DEFAULT NULL,\n  `tenant_id` bigint(20) DEFAULT NULL,\n  PRIMARY KEY (`id`)\n)<\/pre>\n\n\n\n<p>\u5728\u9879\u76ee\u4e2d\u5bfc\u5165\u9700\u8981\u7684\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;dependency&gt;\n    &lt;groupId&gt;com.baomidou&lt;\/groupId&gt;\n    &lt;artifactId&gt;mybatis-plus-boot-starter&lt;\/artifactId&gt;\n    &lt;version&gt;3.3.2&lt;\/version&gt;\n&lt;\/dependency&gt;\n&lt;dependency&gt;\n    &lt;groupId&gt;com.github.jsqlparser&lt;\/groupId&gt;\n    &lt;artifactId&gt;jsqlparser&lt;\/artifactId&gt;\n    &lt;version&gt;3.1&lt;\/version&gt;\n&lt;\/dependency&gt;<\/pre>\n\n\n\n<p>Mybatis-plus \u914d\u7f6e\u7c7b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@EnableTransactionManagement(proxyTargetClass = true)\n@Configuration\npublic class MybatisPlusConfig {\n    @Bean\n    public PaginationInterceptor paginationInterceptor() {\n        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();\n\n        List&lt;ISqlParser&gt; sqlParserList=new ArrayList&lt;&gt;();\n        TenantSqlParser tenantSqlParser=new TenantSqlParser();\n        tenantSqlParser.setTenantHandler(new TenantHandler() {\n            @Override\n            public Expression getTenantId(boolean select) {               \n                String tenantId = \"3\";\n                return new StringValue(tenantId);\n            }\n\n            @Override\n            public String getTenantIdColumn() {\n                return \"tenant_id\";\n            }\n\n            @Override\n            public boolean doTableFilter(String tableName) {\n                return false;\n            }\n        });\n\n        sqlParserList.add(tenantSqlParser);\n        paginationInterceptor.setSqlParserList(sqlParserList);\n        return paginationInterceptor;\n    }\n}<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u4e3b\u8981\u5b9e\u73b0\u7684\u529f\u80fd\uff1a<\/p>\n\n\n\n<ul><li>\u521b\u5efaSQL\u89e3\u6790\u5668\u96c6\u5408<\/li><li>\u521b\u5efa\u79df\u6237SQL\u89e3\u6790\u5668<\/li><li>\u8bbe\u7f6e\u79df\u6237\u5904\u7406\u5668\uff0c\u5177\u4f53\u5904\u7406\u79df\u6237\u903b\u8f91<\/li><\/ul>\n\n\n\n<p>\u8fd9\u91cc\u6682\u65f6\u628a\u79df\u6237\u7684id\u56fa\u5b9a\u5199\u62103\uff0c\u6765\u8fdb\u884c\u6d4b\u8bd5\u3002\u6d4b\u8bd5\u6267\u884c\u5168\u8868\u8bed\u53e5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public List&lt;User&gt; getUserList() {\n    return userMapper.selectList(new LambdaQueryWrapper&lt;User&gt;().isNotNull(User::getId));\n}<\/pre>\n\n\n\n<p>\u4f7f\u7528\u63d2\u4ef6\u89e3\u6790\u6267\u884c\u7684SQL\u8bed\u53e5\uff0c\u53ef\u4ee5\u770b\u5230\u81ea\u52a8\u5728\u67e5\u8be2\u6761\u4ef6\u540e\u52a0\u4e0a\u4e86\u79df\u6237\u8fc7\u6ee4\u6761\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/8df5abefd5292652f43dd6ba3a6d0101.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u90a3\u4e48\u5728\u5b9e\u9645\u7684\u9879\u76ee\u4e2d\uff0c\u600e\u4e48\u5c06\u79df\u6237\u4fe1\u606f\u4f20\u7ed9\u79df\u6237\u5904\u7406\u5668\u5462\uff0c\u6839\u636e\u60c5\u51b5\u6211\u4eec\u53ef\u4ee5\u4ece\u7f13\u5b58\u6216\u8005\u8bf7\u6c42\u5934\u4e2d\u83b7\u53d6\uff0c\u4ee5\u4eceRequest\u8bf7\u6c42\u5934\u83b7\u53d6\u4e3a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Override\npublic Expression getTenantId(boolean select) {\n    ServletRequestAttributes attributes=(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();\n    HttpServletRequest request = attributes.getRequest();\n    String tenantId = request.getHeader(\"tenantId\");\n    return new StringValue(tenantId);\n}<\/pre>\n\n\n\n<p>\u524d\u7aef\u5728\u53d1\u8d77http\u8bf7\u6c42\u65f6\uff0c\u5728Header\u4e2d\u52a0\u5165tenantId\u5b57\u6bb5\uff0c\u540e\u7aef\u5728\u5904\u7406\u5668\u4e2d\u83b7\u53d6\u540e\uff0c\u8bbe\u7f6e\u4e3a\u5f53\u524d\u8fd9\u6b21\u8bf7\u6c42\u7684\u79df\u6237\u8fc7\u6ee4\u6761\u4ef6\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u662f\u57fa\u4e8e\u8bf7\u6c42\u5934\u643a\u5e26\u79df\u6237\u4fe1\u606f\u7684\u60c5\u51b5\uff0c\u90a3\u4e48\u5728\u4f7f\u7528\u4e2d\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e2a\u5751\uff0c\u5982\u679c\u5f53\u4f7f\u7528\u591a\u7ebf\u7a0b\u7684\u65f6\u5019\uff0c\u65b0\u5f00\u542f\u7684\u5f02\u6b65\u7ebf\u7a0b\u5e76\u4e0d\u4f1a\u81ea\u52a8\u643a\u5e26\u5f53\u524d\u7ebf\u7a0b\u7684Request\u8bf7\u6c42\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Override\npublic List&lt;User&gt; getUserListByFuture() {\n    Callable getUser=()-&gt; userMapper.selectList(new LambdaQueryWrapper&lt;User&gt;().isNotNull(User::getId));\n    FutureTask&lt;List&lt;User&gt;&gt; future=new FutureTask&lt;&gt;(getUser);\n    new Thread(future).start();\n    try {\n        return future.get();\n    } catch (Exception e) {\n        e.printStackTrace();\n    }\n    return null;\n}<\/pre>\n\n\n\n<p>\u6267\u884c\u4e0a\u9762\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u770b\u51fa\u662f\u83b7\u53d6\u4e0d\u5230\u5f53\u524d\u7684Request\u8bf7\u6c42\u7684\uff0c\u56e0\u6b64\u65e0\u6cd5\u83b7\u5f97\u79df\u6237id\uff0c\u4f1a\u5bfc\u81f4\u540e\u7eed\u62a5\u9519\u7a7a\u6307\u9488\u5f02\u5e38\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/9c32a9b4afef993af429ab03e8a1798c.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4fee\u6539\u7684\u8bdd\u4e5f\u975e\u5e38\u7b80\u5355\uff0c\u5f00\u542fRequestAttributes\u7684\u5b50\u7ebf\u7a0b\u5171\u4eab\uff0c\u4fee\u6539\u4e0a\u9762\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Override\npublic List&lt;User&gt; getUserListByFuture() {\n    ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();\n    Callable getUser=()-&gt; {\n        RequestContextHolder.setRequestAttributes(sra, true);\n        return userMapper.selectList(new LambdaQueryWrapper&lt;User&gt;().isNotNull(User::getId));\n    };\n    FutureTask&lt;List&lt;User&gt;&gt; future=new FutureTask&lt;&gt;(getUser);\n    new Thread(future).start();\n    try {\n        return future.get();\n    } catch (Exception e) {\n        e.printStackTrace();\n    }\n    return null;\n}<\/pre>\n\n\n\n<p>\u8fd9\u6837\u4fee\u6539\u540e\uff0c\u5728\u5f02\u6b65\u7ebf\u7a0b\u4e2d\u4e5f\u80fd\u6b63\u5e38\u7684\u83b7\u53d6\u79df\u6237\u4fe1\u606f\u4e86\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\uff0c\u6709\u7684\u5c0f\u4f19\u4f34\u53ef\u80fd\u8981\u95ee\u4e86\uff0c\u5728\u4e1a\u52a1\u4e2d\u5e76\u4e0d\u662f\u6240\u6709\u7684\u67e5\u8be2\u90fd\u9700\u8981\u8fc7\u6ee4\u79df\u6237\u6761\u4ef6\u554a\uff0c\u9488\u5bf9\u8fd9\u79cd\u60c5\u51b5\uff0c\u6709\u4e24\u79cd\u65b9\u5f0f\u6765\u8fdb\u884c\u5904\u7406\u3002<\/p>\n\n\n\n<p>1\u3001\u5982\u679c\u6574\u5f20\u8868\u7684\u6240\u6709SQL\u64cd\u4f5c\u90fd\u4e0d\u9700\u8981\u9488\u5bf9\u79df\u6237\u8fdb\u884c\u64cd\u4f5c\uff0c\u90a3\u4e48\u5c31\u5bf9\u8868\u8fdb\u884c\u8fc7\u6ee4\uff0c\u4fee\u6539doTableFilter\u65b9\u6cd5\uff0c\u6dfb\u52a0\u8868\u7684\u540d\u79f0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Override\npublic boolean doTableFilter(String tableName) {\n    List&lt;String&gt; IGNORE_TENANT_TABLES= Arrays.asList(\"dept\");\n    return IGNORE_TENANT_TABLES.stream().anyMatch(e-&gt;e.equalsIgnoreCase(tableName));\n}<\/pre>\n\n\n\n<p>\u8fd9\u6837\uff0c\u5728dept\u8868\u7684\u6240\u6709\u67e5\u8be2\u90fd\u4e0d\u8fdb\u884c\u8fc7\u6ee4\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/bdf6dd0ea5c0303191982570a3f4bf9a.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>2\u3001\u5982\u679c\u6709\u4e00\u4e9b\u7279\u5b9a\u7684SQL\u8bed\u53e5\u4e0d\u60f3\u88ab\u6267\u884c\u79df\u6237\u8fc7\u6ee4\uff0c\u53ef\u4ee5\u901a\u8fc7@SqlParser\u6ce8\u89e3\u7684\u5f62\u5f0f\u5f00\u542f\uff0c\u6ce8\u610f\u6ce8\u89e3\u53ea\u80fd\u52a0\u5728Mapper\u63a5\u53e3\u7684\u65b9\u6cd5\u4e0a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@SqlParser(filter = true)\n@Select(\"select * from user where name =#{name}\")\nUser selectUserByName(@Param(value=\"name\") String name);<\/pre>\n\n\n\n<p>\u6216\u5728\u5206\u9875\u62e6\u622a\u5668\u4e2d\u6307\u5b9a\u9700\u8981\u8fc7\u6ee4\u7684\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Bean\npublic PaginationInterceptor paginationInterceptor() {\n    PaginationInterceptor paginationInterceptor = new PaginationInterceptor();\n    paginationInterceptor.setSqlParserFilter(metaObject-&gt;{\n        MappedStatement ms = SqlParserHelper.getMappedStatement(metaObject);\n        \/\/ \u5bf9\u5e94Mapper\u3001dao\u4e2d\u7684\u65b9\u6cd5\n        if(\"com.cn.tenant.dao.UserMapper.selectUserByPhone\".equals(ms.getId())){\n            return true;\n        }\n        return false;\n    });\n    ...\n}<\/pre>\n\n\n\n<p>\u4e0a\u9762\u8fd9\u4e24\u79cd\u65b9\u5f0f\u5b9e\u73b0\u7684\u529f\u80fd\u76f8\u540c\uff0c\u4f46\u662f\u5982\u679c\u9700\u8981\u8fc7\u6ee4\u7684SQL\u8bed\u53e5\u5f88\u591a\uff0c\u90a3\u4e48\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u914d\u7f6e\u8d77\u6765\u4f1a\u6bd4\u8f83\u9ebb\u70e6\uff0c\u56e0\u6b64\u5efa\u8bae\u901a\u8fc7\u6ce8\u89e3\u7684\u65b9\u5f0f\u8fdb\u884c\u8fc7\u6ee4\u3002<\/p>\n\n\n\n<p>\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e2a\u6bd4\u8f83\u5bb9\u6613\u8e29\u7684\u5751\u5c31\u662f\u5728\u590d\u5236Bean\u65f6\uff0c\u4e0d\u8981\u590d\u5236\u79df\u6237id\u5b57\u6bb5\uff0c\u5426\u5219\u4f1a\u5bfc\u81f4SQL\u8bed\u53e5\u62a5\u9519\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public void createSnapshot(Long userId){\n    User user = userMapper.selectOne(new LambdaQueryWrapper&lt;User&gt;().eq(User::getId, userId));\n    UserSnapshot userSnapshot=new UserSnapshot();\n    BeanUtil.copyProperties(user,userSnapshot);\n    userSnapshotMapper.insert(userSnapshot);\n}<\/pre>\n\n\n\n<p>\u67e5\u770b\u62a5\u9519\u53ef\u4ee5\u770b\u51fa\uff0c\u672c\u8eabBean\u7684\u79df\u6237\u5b57\u6bb5\u4e0d\u4e3a\u7a7a\u7684\u60c5\u51b5\u4e0b\uff0cSQL\u53c8\u81ea\u52a8\u6dfb\u52a0\u4e00\u6b21\u79df\u6237\u67e5\u8be2\u6761\u4ef6\uff0c\u56e0\u6b64\u5bfc\u81f4\u4e86\u62a5\u9519\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/feb6a95812ca645b761de41c612cb268.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u4fee\u6539\u590d\u5236Bean\u8bed\u53e5\uff0c\u624b\u52a8\u5ffd\u7565\u79df\u6237id\u5b57\u6bb5\uff0c\u8fd9\u91cc\u4f7f\u7528\u7684\u662fhutool\u7684BeanUtil\u5de5\u5177\u7c7b\uff0c\u53ef\u4ee5\u6dfb\u52a0\u5ffd\u7565\u5b57\u6bb5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">BeanUtil.copyProperties(user,userSnapshot,\"tenantId\");<\/pre>\n\n\n\n<p>\u5728\u5ffd\u7565\u4e86\u79df\u6237id\u7684\u62f7\u8d1d\u540e\uff0c\u67e5\u8be2\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\u3002<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u518d\u6765\u770b\u4e00\u4e0b\u5bf9\u8054\u8868\u67e5\u8be2\u7684\u652f\u6301\uff0c\u9996\u5148\u770b\u4e00\u4e0b\u5305\u542b\u5b50\u67e5\u8be2\u7684SQL\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Select(\"select * from user where id in (select id from user_snapshot)\")\nList&lt;User&gt; selectSnapshot();<\/pre>\n\n\n\n<p>\u67e5\u770b\u6267\u884c\u7ed3\u679c\uff0c\u53ef\u4ee5\u770b\u89c1\uff0c\u5728\u5b50\u67e5\u8be2\u7684\u5185\u90e8\u4e5f\u81ea\u52a8\u6dfb\u52a0\u7684\u79df\u6237\u67e5\u8be2\u6761\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/3cb2b5775adf3f13cfa31b94825af85e.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u518d\u6765\u770b\u4e00\u4e0b\u4f7f\u7528Join\u8fdb\u884c\u8054\u8868\u67e5\u8be2\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Select(\"select u.* from user u left join user_snapshot us on u.id=us.id\")\nList&lt;User&gt; selectSnapshot();<\/pre>\n\n\n\n<p>\u540c\u6837\uff0c\u4f1a\u5728\u5de6\u53f3\u4e24\u5f20\u8868\u4e0a\u90fd\u6dfb\u52a0\u79df\u6237\u7684\u8fc7\u6ee4\u6761\u4ef6\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/b06b4cb9db81fee27d5aa36f5f620c3e.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u518d\u770b\u4e00\u4e0b\u4e0d\u4f7f\u7528Join\u7684\u666e\u901a\u8054\u8868\u67e5\u8be2\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@Select(\"select u.* from user u ,user_snapshot us,dept d where u.id=us.id and d.id is not null\")\nList&lt;User&gt; selectSnapshot();<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/img.soft10.net\/20220523\/bea220268ce3ec0ecd4f96e873ce6b78.png\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u67e5\u770b\u6267\u884c\u7ed3\u679c\uff0c\u53ef\u4ee5\u770b\u89c1\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u53ea\u5728FROM\u5173\u952e\u5b57\u540e\u9762\u7684\u7b2c\u4e00\u5f20\u8868\u4e0a\u6dfb\u52a0\u4e86\u79df\u6237\u7684\u8fc7\u6ee4\u6761\u4ef6\uff0c\u56e0\u6b64\u5982\u679c\u4f7f\u7528\u8fd9\u79cd\u67e5\u8be2\u65b9\u5f0f\uff0c\u9700\u8981\u989d\u5916\u6ce8\u610f\uff0c\u7528\u6237\u9700\u8981\u624b\u52a8\u5728SQL\u8bed\u53e5\u4e2d\u6dfb\u52a0\u79df\u6237\u8fc7\u6ee4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u505a\u8fc7sass\u7684\u5e94\u7528\uff0c\u4f7f\u7528\u7684\u662f\u52a8\u6001\u6570\u636e\u6e90 \u51c6\u5907\u4e86\u89e3\u4e0bmybatisplus\u7684\u67b6\u6784\uff0c\u53d1\u73b0\u65f6\u5b57\u6bb5\u7ea7\u522b\u7684\u591a\u79df\u6237\uff0c\u5c0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[233,239],"_links":{"self":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3744"}],"collection":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3744"}],"version-history":[{"count":4,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3744\/revisions"}],"predecessor-version":[{"id":3748,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/3744\/revisions\/3748"}],"wp:attachment":[{"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zeroheart.xyz\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}