{"id":1489,"date":"2023-08-31T09:21:34","date_gmt":"2023-08-31T01:21:34","guid":{"rendered":"https:\/\/www.yeetrack.com\/?p=1489"},"modified":"2023-08-31T09:23:26","modified_gmt":"2023-08-31T01:23:26","slug":"ebean%e5%a4%9a%e6%95%b0%e6%8d%ae%e6%ba%90%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/www.yeetrack.com\/?p=1489","title":{"rendered":"ebean\u591a\u6570\u636e\u6e90\u914d\u7f6e"},"content":{"rendered":"<p>ebean\u4e3ajava\u64cd\u4f5c\u6570\u636e\u5e93ORM\u6846\u67b6\u4e2d\uff0c\u6bd4\u8f83\u8f7b\u91cf\u7ea7\u7684\u4e00\u6b3e\uff0c\u4f7f\u7528\u5176\u53ef\u4ee5\u5feb\u901f\u5bf9mysql\u7b49\u6570\u636e\u5e93\u8bb0\u5f55\u8fdb\u884c\u589e\u5220\u6539\u67e5\uff0c\u914d\u7f6e\u5f88\u5c11\uff0c\u5c24\u5176\u9002\u5408\u5c0f\u578b\u9879\u76ee\u5f00\u53d1\u548c\u7814\u6d4b\u5de5\u5177\u7684\u5f00\u53d1\u3002\u5728\u505a\u4e00\u4e9b\u504f\u878d\u5408\u7684\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u4f1a\u6709\u64cd\u4f5c\u591a\u4e2a\u6570\u636e\u5e93\u7684\u9700\u6c42\uff0c\u4f7f\u7528ebean\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u505a\u5230\uff0c\u5177\u4f53\u65b9\u6cd5\u5982\u4e0b\u3002<\/p>\n<ol>\n<li>\n<p>\u914d\u7f6e\u6587\u4ef6\uff0capplication.properties<br \/>\n\u5982\u4e0b\u65b9\u914d\u7f6e\uff0c\u914d\u5408\u4e86\u4e09\u4e2amysql\u6570\u636e\u5e93\u6570\u636e\u6e90\uff0c\u9ed8\u8ba4\u4e3a\u6807\u8bc6\u4e3a&quot;db&quot;\u7684\u6570\u636e\u6e90  <\/p>\n<pre><code>ebean.default=com.yeetrack.devops.ebeandemo.Entity.db.*\n# the name of the default server\ndatasource.default=db\n\ndatasource.db.username=user_xxx1\ndatasource.db.password=pass_xxx1\ndatasource.db.databaseUrl=jdbc:mysql:\/\/x.x.x.x:3306\/db_1?rewriteBatchedStatements=true\ndatasource.db.databaseDriver=com.mysql.cj.jdbc.Driver\n\ndatasource.road.username=user_xxx2\ndatasource.road.password=pass_xxx2\ndatasource.road.databaseUrl=jdbc:mysql:\/\/x.x.x.x:3306\/db_2?rewriteBatchedStatements=true\ndatasource.road.databaseDriver=com.mysql.cj.jdbc.Driver\n\ndatasource.data.username=user_xxx3\ndatasource.data.password=pass_xxx3\ndatasource.data.databaseUrl=jdbc:mysql:\/\/x.x.x.x:3306\/db_3?rewriteBatchedStatements=true\ndatasource.data.databaseDriver=com.mysql.cj.jdbc.Driver<\/code><\/pre>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u6570\u636e\u6e90\u5e76\u4f7f\u7528<br \/>\n\u5982\u4e0b\u4ee3\u7801\uff0c\u9ed8\u8ba4\u7684\u201cDB\u201d\u6570\u636e\u6e90\u76f4\u63a5\u4f7f\u7528\u5373\u53ef\uff0cebean\u4f1a\u81ea\u52a8\u52a0\u8f7d\uff1b\u5176\u4ed6\u4e24\u4e2a\u6570\u636e\u6e90\u201croad\u201d\u3001\u201cdata\u201d\u9700\u8981\u624b\u52a8\u521d\u59cb\u5316\u540e\u518d\u4f7f\u7528\u3002  <\/p>\n<pre><code>public class EbeanServer {\n    public static Database ROAD_DB_SERVER;\n    public static Database DATA_DB_SERVER;\n\n    static {\n        ROAD_DB_SERVER = DatabaseFactory.create(\"road\");\n        DATA_DB_SERVER = DatabaseFactory.create(\"data\");\n    }\n\n    public static void main(String[] args) {\n        ROAD_DB_SERVER.find(RoadBugEntity.class).findList();\n        DATA_DB_SERVER.find(BugDataEntity.class).findList();\n        DB.find(BugEntity.class).findList();\n    }\n}<\/code><\/pre>\n<\/li>\n<li>\n<p>\u6570\u636e\u5e93\u5b9e\u4f53\u7c7b  <\/p>\n<pre><code>@Entity\n@DbName(\"road\")\n@Table(name = \"XXX_table\")\npublic class RoadBugEntity {\n    @Id\n    int id;\n\n    @Column(name = \"code\")\n    String code;\n\n    @Column(name = \"task_id\")\n    String taskId;\n    ....\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n<p>\u5907\u6ce8\uff1a\u5f53\u524d\u9879\u76ee\u4f7f\u7528jdk11\uff0cebean 13.17.0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ebean\u4e3ajava\u64cd\u4f5c\u6570\u636e\u5e93ORM\u6846\u67b6\u4e2d\uff0c\u6bd4\u8f83\u8f7b\u91cf\u7ea7\u7684\u4e00\u6b3e\uff0c\u4f7f\u7528\u5176\u53ef\u4ee5\u5feb\u901f\u5bf9mysql\u7b49\u6570\u636e\u5e93\u8bb0\u5f55\u8fdb\u884c\u589e\u5220\u6539\u67e5\uff0c\u914d\u7f6e\u5f88\u5c11\uff0c\u5c24\u5176\u9002\u5408\u5c0f\u578b\u9879\u76ee\u5f00\u53d1\u548c\u7814\u6d4b\u5de5\u5177\u7684\u5f00\u53d1\u3002\u5728\u505a\u4e00\u4e9b\u504f\u878d\u5408\u7684\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u4f1a\u6709\u64cd\u4f5c\u591a&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pgc_sgb_lightbox_settings":"","footnotes":""},"categories":[33],"tags":[63,8,56],"class_list":["post-1489","post","type-post","status-publish","format-standard","hentry","category-coding","tag-ebean","tag-java","tag-mysql"],"views":710,"_links":{"self":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1489","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1489"}],"version-history":[{"count":3,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1489\/revisions"}],"predecessor-version":[{"id":1492,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=\/wp\/v2\/posts\/1489\/revisions\/1492"}],"wp:attachment":[{"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1489"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1489"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yeetrack.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1489"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}