{"id":1551,"date":"2024-01-17T16:36:02","date_gmt":"2024-01-17T08:36:02","guid":{"rendered":"https:\/\/fireinsect.top\/?p=1551"},"modified":"2024-01-17T16:36:02","modified_gmt":"2024-01-17T08:36:02","slug":"mybatisplus%e4%bb%a3%e7%a0%81%e7%94%9f%e6%88%90%e5%99%a8","status":"publish","type":"post","link":"https:\/\/fireinsect.top\/index.php\/2024\/01\/17\/mybatisplus%e4%bb%a3%e7%a0%81%e7%94%9f%e6%88%90%e5%99%a8\/","title":{"rendered":"MybatisPlus\u4ee3\u7801\u751f\u6210\u5668"},"content":{"rendered":"\n<p>MybatisPlus\u5b58\u5728\u4ee3\u7801\u751f\u6210\u5668\uff0c\u80fd\u591f\u6839\u636e\u6570\u636e\u5e93\u505a\u5230\u4ee3\u7801\u7684\u4e00\u952e\u751f\u6210\u3002<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u521b\u5efa\u4e00\u65b0\u7684\u9879\u76ee\uff0c\u63a5\u7740\u5bfc\u5165\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;dependency>\r\n    &lt;groupId>com.baomidou&lt;\/groupId>\r\n    &lt;artifactId>mybatis-plus-boot-starter&lt;\/artifactId>\r\n    &lt;version>3.5.3.1&lt;\/version>\r\n&lt;\/dependency>\r\n&lt;dependency>\r\n    &lt;groupId>com.baomidou&lt;\/groupId>\r\n    &lt;artifactId>mybatis-plus-generator&lt;\/artifactId>\r\n    &lt;version>3.5.3.1&lt;\/version>\r\n&lt;\/dependency>\r\n&lt;dependency>\r\n    &lt;groupId>org.apache.velocity&lt;\/groupId>\r\n    &lt;artifactId>velocity-engine-core&lt;\/artifactId>\r\n    &lt;version>2.3&lt;\/version>\r\n&lt;\/dependency><\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u914d\u7f6e\u4e00\u4e0b\u6570\u636e\u6e90\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">spring:\r\n  datasource:\r\n    url: jdbc:mysql:\/\/localhost:3306\/test\r\n    username: root\r\n    password: 123456\r\n    driver-class-name: com.mysql.cj.jdbc.Driver<\/code><\/pre>\n\n\n\n<p>\u63a5\u7740\u5c31\u53ef\u4ee5\u7f16\u5199\u81ea\u52a8\u751f\u6210\u811a\u672c\uff0c\u8fd9\u91cc\u9009\u62e9\u6d4b\u8bd5\u7c7b\uff0c\u7528\u5230<code>FastAutoGenerator<\/code>\u4f5c\u4e3a\u751f\u6210\u5668\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java\">@Configurable\r\nclass DemoApplicationTests {\r\n    @Resource\r\n    DataSource dataSource;\r\n    @Test\r\n    void contextLoads() {\r\n        FastAutoGenerator\r\n                .create(new DataSourceConfig.Builder(dataSource))\r\n                \/\/ \u914d\u7f6e\u4e00\u4e0b\u5168\u5c40\u8bbe\u7f6e\r\n                .globalConfig(builder -> {\r\n                    builder.author(\"lbw\");              \/\/\u4f5c\u8005\u4fe1\u606f\uff0c\u4e00\u4f1a\u4f1a\u53d8\u6210\u6ce8\u91ca\r\n                    builder.commentDate(\"2024-01-01\");  \/\/\u65e5\u671f\u4fe1\u606f\uff0c\u4e00\u4f1a\u4f1a\u53d8\u6210\u6ce8\u91ca\r\n                    builder.outputDir(\"src\/main\/java\"); \/\/\u8f93\u51fa\u76ee\u5f55\u8bbe\u7f6e\u4e3a\u5f53\u524d\u9879\u76ee\u7684\u76ee\u5f55\r\n\r\n                })\r\n                \/\/ \u914d\u7f6e\u6253\u5305\u8bbe\u7f6e\uff0c\u4e5f\u5c31\u662f\u9879\u76ee\u751f\u6210\u7684\u5305\r\n                .packageConfig(builder -> builder.parent(\"com.example\"))\r\n                .strategyConfig(builder -> {\r\n                    builder\r\n                            .mapperBuilder()\r\n                            .mapperAnnotation(Mapper.class)\r\n                            .build();\r\n                })\r\n                .execute();\r\n\r\n    }\r\n}<\/code><\/pre>\n\n\n\n<p>\u4e4b\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\uff0c\u4ee3\u7801\u751f\u6210\u5668\u4f1a\u81ea\u52a8\u751f\u6210\u4eceMapper\u5230Controller\u7684\u6240\u6709\u4ee3\u7801\uff0c\u6211\u4eec\u5c31\u53ea\u9700\u8981\u53bb\u5b8c\u6210\u4e1a\u52a1\u903b\u8f91\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u4e00\u4e9b\u6709\u7279\u6b8a\u8981\u6c42\u7684\u7528\u6237\u6765\u8bf4\uff0c\u6211\u4eec\u5e0c\u671b\u80fd\u591f\u4ee5\u81ea\u5df1\u7684\u6a21\u7248\u6765\u8fdb\u884c\u751f\u4ea7\uff0c\u600e\u4e48\u624d\u80fd\u4fee\u6539\u5b83\u81ea\u52a8\u751f\u6210\u7684\u4ee3\u7801\u6a21\u7248\u5462\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u627e\u5230<code>mybatis-plus-generator<\/code>\u7684\u6e90\u7801\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"263\" src=\"https:\/\/i0.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-29.png?resize=1024%2C263&#038;ssl=1\" alt=\"\" class=\"wp-image-1553\" srcset=\"https:\/\/i0.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-29.png?resize=1024%2C263&amp;ssl=1 1024w, https:\/\/i0.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-29.png?resize=300%2C77&amp;ssl=1 300w, https:\/\/i0.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-29.png?resize=768%2C197&amp;ssl=1 768w, https:\/\/i0.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-29.png?w=1437&amp;ssl=1 1437w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>\u751f\u6210\u6a21\u7248\u90fd\u5728\u5728\u8fd9\u4e2a\u91cc\u9762\u6709\u5199\uff0c\u6211\u4eec\u8981\u505a\u7684\u5c31\u662f\u53bb\u4fee\u6539\u8fd9\u4e9b\u6a21\u7248\uff0c\u53d8\u6210\u6211\u4eec\u81ea\u5df1\u5e0c\u671b\u7684\u6837\u5b50\uff0c\u7531\u4e8e\u9ed8\u8ba4\u7684\u6a21\u7248\u89e3\u6790\u5f15\u64ce\u4e3aVelocity\uff0c\u6211\u4eec\u9700\u8981\u590d\u5236\u4ee5<code>.vm<\/code>\u7ed3\u5c3e\u7684\u6587\u4ef6\u5230<code>resource<\/code>\u968f\u4fbf\u4e00\u4e2a\u76ee\u5f55\u4e2d\uff0c\u7136\u540e\u968f\u4fbf\u6539\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"281\" src=\"https:\/\/i1.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-30.png?resize=1024%2C281&#038;ssl=1\" alt=\"\" class=\"wp-image-1554\" srcset=\"https:\/\/i1.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-30.png?resize=1024%2C281&amp;ssl=1 1024w, https:\/\/i1.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-30.png?resize=300%2C82&amp;ssl=1 300w, https:\/\/i1.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-30.png?resize=768%2C211&amp;ssl=1 768w, https:\/\/i1.wp.com\/fireinsect.top\/wp-content\/uploads\/2024\/01\/image-30.png?w=1222&amp;ssl=1 1222w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>\u63a5\u7740\u6211\u4eec\u914d\u7f6e\u4e00\u4e0b\u6a21\u7248\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java\">@Test\r\nvoid contextLoads() {\r\n    FastAutoGenerator\r\n            ...\r\n      \t\t\t.strategyConfig(builder -> {\r\n                builder\r\n                        .mapperBuilder()\r\n                        .enableFileOverride()   \/\/\u5f00\u542f\u6587\u4ef6\u91cd\u5199\uff0c\u81ea\u52a8\u8986\u76d6\u65b0\u7684\r\n                        .mapperAnnotation(Mapper.class)\r\n                        .build();\r\n            })\r\n            .templateConfig(builder -> {\r\n                    builder.controller(\"\/template\/controller.java.vm\");\r\n            })\r\n            .execute();\r\n}<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6837\uff0c\u65b0\u751f\u6210\u7684\u4ee3\u7801\u4e2d\u5c31\u662f\u6309\u7167\u6211\u4eec\u81ea\u5df1\u7684\u6a21\u7248\u6765\u5b9a\u4e49\u4e86\uff0c\u9700\u8981\u4fee\u6539\u5176\u4ed6\u7c7b\u6a21\u7248\u53ea\u9700\u8981\u8c03\u7528\u4e0d\u540c\u7684builder\u7684\u65b9\u6cd5\u5c31\u884c\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MybatisPlus\u5b58\u5728\u4ee3\u7801\u751f\u6210\u5668\uff0c\u80fd\u591f\u6839\u636e\u6570\u636e\u5e93\u505a\u5230\u4ee3\u7801\u7684\u4e00\u952e\u751f\u6210\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-1551","post","type-post","status-publish","format-standard","hentry","category-6"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/1551"}],"collection":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/comments?post=1551"}],"version-history":[{"count":1,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/1551\/revisions"}],"predecessor-version":[{"id":1555,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/1551\/revisions\/1555"}],"wp:attachment":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/media?parent=1551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/categories?post=1551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/tags?post=1551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}