{"id":2037,"date":"2023-04-01T20:35:03","date_gmt":"2023-04-01T12:35:03","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=2037"},"modified":"2023-04-07T06:12:26","modified_gmt":"2023-04-06T22:12:26","slug":"mybatis-mybatis-generator-configuration","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/04\/01\/mybatis-mybatis-generator-configuration\/","title":{"rendered":"MyBatis mybatis-generator\u914d\u7f6e"},"content":{"rendered":"<h2>\u6570\u636e\u5e93\u8fde\u63a5\u914d\u7f6e<\/h2>\n<p>generator.properties<\/p>\n<p><!-- more --><\/p>\n<pre><code>generator.jdbc.driver=com.mysql.jdbc.Driver\ngenerator.jdbc.url=jdbc\\:mysql\\:\/\/192.168.161.11\\:3306\/appblog?useUnicode\\=true&amp;characterEncoding\\=utf-8&amp;autoReconnect\\=true\ngenerator.jdbc.username=appblog\ngenerator.jdbc.password=xxxxxx<\/code><\/pre>\n<h2>DAO\u751f\u6210\u914d\u7f6e<\/h2>\n<p>generatorConfig.xml<\/p>\n<pre><code class=\"language-xml\">&lt;!--&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;--&gt;\n&lt;!DOCTYPE generatorConfiguration PUBLIC &quot;-\/\/mybatis.org\/\/DTD MyBatis Generator Configuration 1.0\/\/EN&quot; &quot;http:\/\/mybatis.org\/dtd\/mybatis-generator-config_1_0.dtd&quot; &gt;\n&lt;generatorConfiguration&gt;\n\n    &lt;!-- \u914d\u7f6e\u6587\u4ef6 --&gt;\n    &lt;properties resource=&quot;generator.properties&quot;&gt;&lt;\/properties&gt;\n\n    &lt;context id=&quot;MysqlContext&quot; targetRuntime=&quot;MyBatis3&quot; defaultModelType=&quot;flat&quot;&gt;\n\n        &lt;property name=&quot;javaFileEncoding&quot; value=&quot;UTF-8&quot;\/&gt;\n        &lt;!-- \u7531\u4e8ebeginningDelimiter\u548cendingDelimiter\u7684\u9ed8\u8ba4\u503c\u4e3a\u53cc\u5f15\u53f7(&quot;)\uff0c\u5728Mysql\u4e2d\u4e0d\u80fd\u8fd9\u4e48\u5199\uff0c\u6240\u4ee5\u8fd8\u8981\u5c06\u8fd9\u4e24\u4e2a\u9ed8\u8ba4\u503c\u6539\u4e3a`  --&gt;\n        &lt;property name=&quot;beginningDelimiter&quot; value=&quot;`&quot;\/&gt;\n        &lt;property name=&quot;endingDelimiter&quot; value=&quot;`&quot;\/&gt;\n\n        &lt;!-- \u4e3a\u751f\u6210\u7684Java\u6a21\u578b\u521b\u5efa\u4e00\u4e2atoString\u65b9\u6cd5 --&gt;\n        &lt;plugin type=&quot;org.mybatis.generator.plugins.ToStringPlugin&quot;&gt;&lt;\/plugin&gt;\n\n        &lt;!-- \u4e3a\u751f\u6210\u7684Java\u6a21\u578b\u7c7b\u6dfb\u52a0\u5e8f\u5217\u5316\u63a5\u53e3\uff0c\u5e76\u751f\u6210serialVersionUID\u5b57\u6bb5 --&gt;\n        &lt;plugin type=&quot;cn.appblog.cloud.common.plugin.SerializablePlugin&quot;&gt;\n            &lt;property name=&quot;suppressJavaInterface&quot; value=&quot;false&quot;\/&gt;\n        &lt;\/plugin&gt;\n\n        &lt;!-- \u751f\u6210\u4e00\u4e2a\u65b0\u7684selectByExample\u65b9\u6cd5\uff0c\u8fd9\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u63a5\u6536offset\u548climit\u53c2\u6570\uff0c\u4e3b\u8981\u7528\u6765\u5b9e\u73b0\u5206\u9875\uff0c\u53ea\u652f\u6301mysql(\u5df2\u4f7f\u7528pagehelper\u4ee3\u66ff) --&gt;\n        &lt;!--&lt;plugin type=&quot;cn.appblog.cloud.common.plugin.PaginationPlugin&quot;&gt;&lt;\/plugin&gt;--&gt;\n\n        &lt;!-- \u751f\u6210\u5728XML\u4e2d\u7684&lt;cache&gt;\u5143\u7d20 --&gt;\n        &lt;plugin type=&quot;org.mybatis.generator.plugins.CachePlugin&quot;&gt;\n            &lt;!-- \u4f7f\u7528ehcache --&gt;\n            &lt;property name=&quot;cache_type&quot; value=&quot;org.mybatis.caches.ehcache.LoggingEhcache&quot; \/&gt;\n            &lt;!-- \u5185\u7f6ecache\u914d\u7f6e --&gt;\n            &lt;!--\n            &lt;property name=&quot;cache_eviction&quot; value=&quot;LRU&quot; \/&gt;\n            &lt;property name=&quot;cache_flushInterval&quot; value=&quot;60000&quot; \/&gt;\n            &lt;property name=&quot;cache_readOnly&quot; value=&quot;true&quot; \/&gt;\n            &lt;property name=&quot;cache_size&quot; value=&quot;1024&quot; \/&gt;\n            --&gt;\n        &lt;\/plugin&gt;\n\n        &lt;!-- Java\u6a21\u578b\u751f\u6210equals\u548chashcode\u65b9\u6cd5 --&gt;\n        &lt;plugin type=&quot;org.mybatis.generator.plugins.EqualsHashCodePlugin&quot;&gt;&lt;\/plugin&gt;\n\n        &lt;!-- \u751f\u6210\u7684\u4ee3\u7801\u6dfb\u52a0\u6ce8\u91ca --&gt;\n        &lt;commentGenerator type=&quot;cn.appblog.cloud.common.plugin.CommentGenerator&quot;&gt;\n            &lt;property name=&quot;suppressAllComments&quot; value=&quot;true&quot; \/&gt;\n            &lt;property name=&quot;suppressDate&quot; value=&quot;true&quot;\/&gt;\n        &lt;\/commentGenerator&gt;\n\n        &lt;!-- \u6570\u636e\u5e93\u8fde\u63a5 --&gt;\n        &lt;jdbcConnection driverClass=&quot;${generator.jdbc.driver}&quot;\n                        connectionURL=&quot;${generator.jdbc.url}&quot;\n                        userId=&quot;${generator.jdbc.username}&quot;\n                        password=&quot;${generator.jdbc.password}&quot; \/&gt;\n\n        &lt;!-- model\u751f\u6210 --&gt;\n        &lt;javaModelGenerator targetPackage=&quot;cn.appblog.cloud.test.dao.entity&quot; targetProject=&quot;..\/test-dao\/src\/main\/java&quot; \/&gt;\n\n        &lt;!-- MapperXML\u751f\u6210 --&gt;\n        &lt;sqlMapGenerator targetPackage=&quot;mybatis.mapper&quot; targetProject=&quot;..\/test-dao\/src\/main\/resources&quot; \/&gt;\n\n        &lt;!-- Mapper\u63a5\u53e3\u751f\u6210 --&gt;\n        &lt;javaClientGenerator targetPackage=&quot;cn.appblog.cloud.test.dao.mapper&quot; targetProject=&quot;..\/test-dao\/src\/main\/java&quot; type=&quot;XMLMAPPER&quot; \/&gt;\n\n        &lt;!-- \u9700\u8981\u6620\u5c04\u7684\u8868 --&gt;\n        &lt;!--&lt;table tableName=&quot;table1&quot; domainObjectName=&quot;Model1&quot;&gt;&lt;\/table&gt;--&gt;\n        &lt;table tableName=&quot;table2&quot; domainObjectName=&quot;Model2&quot;&gt;&lt;\/table&gt;\n    &lt;\/context&gt;\n&lt;\/generatorConfiguration&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u5e93\u8fde\u63a5\u914d\u7f6e generator.properties generator.jdbc.driver=com. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-2037","post","type-post","status-publish","format-standard","hentry","category-mybatis"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2037","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2037"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/2037\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2037"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2037"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2037"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}