{"id":10020424,"date":"2024-11-28T18:47:31","date_gmt":"2024-11-28T10:47:31","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020424"},"modified":"2024-11-28T18:47:31","modified_gmt":"2024-11-28T10:47:31","slug":"spring-data-jpa%e8%87%aa%e5%8a%a8%e7%94%9f%e6%88%90%e8%a1%a8%e6%97%b6%e5%88%97%e9%a1%ba%e5%ba%8f%e6%b7%b7%e4%b9%b1%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95%ef%bc%88%e6%9c%80%e6%96%b0%e7%89%88","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020424","title":{"rendered":"Spring Data JPA\u81ea\u52a8\u751f\u6210\u8868\u65f6\u5217\u987a\u5e8f\u6df7\u4e71\u7684\u89e3\u51b3\u529e\u6cd5\uff08\u6700\u65b0\u7248\uff09"},"content":{"rendered":"<p>\u6700\u8fd1\u628aSpring Boot\u7684\u7248\u672c\u5347\u7ea7\u5230\u4e863.3.5\uff0c\u7a81\u7136\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff1a\u5f53\u4f7f\u7528Spring Data JPA\u81ea\u52a8\u751f\u6210\u8868\u7684\u65f6\u5019\uff0c\u6240\u4ea7\u751f\u7684\u5217\u987a\u5e8f\u4e0eEntity\u7c7b\u4e2d\u7684\u53d8\u91cf\u987a\u5e8f\u4e0d\u4e00\u81f4\u4e86\u3002\u6bd4\u5982\uff0c\u6709\u4e00\u4e2a\u4e0b\u9762\u8fd9\u6837\u7684Entity\uff1a<\/p>\n<pre><code class=\"java\">@Data\n@Entity(name = &quot;t_config&quot;)\n@EntityListeners(AuditingEntityListener.class)\npublic class Config {\n\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    private Long id;\n    \n    @Column(length = 20)\n    private String itemKey;\n    @Column(length = 200)\n    private String itemValue;\n    @Column(length = 200)\n    private String itemDesc;\n\n    @CreatedDate\n    private Date createTime;\n    @LastModifiedDate\n    private Date modifyTime;\n\n}<\/code><\/pre>\n<p>\u5b9e\u9645\u81ea\u52a8\u521b\u5efa\u51fa\u6765\u7684\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"312\" height=\"154\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVde7gy\" alt=\"image.png\" title=\"image.png\"><\/p>\n<p>\u81ea\u52a8\u521b\u5efa\u7684\u8868\u7ed3\u6784\u4e2d\u5404\u4e2a\u5217\u4e0eEntity\u7c7b\u4e2d\u7684\u53d8\u91cf\u987a\u5e8f\u4e0d\u4e00\u81f4\u3002\u5176\u5b9e\u8be5\u95ee\u9898\u662f\u4e00\u4e2a\u8001\u751f\u5e38\u8c08\u7684\u95ee\u9898\u4e86\uff0c\u5728<a href=\"https:\/\/link.segmentfault.com\/?enc=cNKcgjzBQwVJs54u9vzHgw%3D%3D.QJPUEJq3NZiwgQf6QzJ%2B1yZe%2BIxWTAnZFQZo0zp1t0g%3D\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">DD<\/a>\u8fd9\u6b21\u5347\u7ea7\u7684\u5de5\u7a0b\u91cc\u662f\u6709\u505a\u8fc7\u89e3\u51b3\u65b9\u6848\u7684\u3002\u53ea\u662f\u5347\u7ea7\u4e86Spring Boot\u7248\u672c\u4e4b\u540e\uff0c\u4e4b\u524d\u7684\u89e3\u51b3\u65b9\u6848\u5931\u6548\u4e86\u3002<\/p>\n<p>\u641c\u7d22\u4e86\u4e00\u756a\uff0c\u540c\u65f6\u8fd8\u95ee\u4e86\u4e00\u4e0bAI\uff0c\u53d1\u73b0\u7ed9\u51fa\u7684\u65b9\u6848\u8fd8\u90fd\u662f\u8001\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u6240\u4ee5\u4eca\u5929\u7279\u522b\u5199\u4e00\u7bc7\u6765\u8bb0\u5f55\u4e0b\u65b0\u7248\u672c\u4e4b\u4e0b\uff0c\u8981\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002\u5982\u679c\u60a8\u521a\u597d\u9047\u5230\u7c7b\u4f3c\u7684\u95ee\u9898\uff0c\u53ef\u4ee5\u53c2\u8003\u672c\u6587\u6765\u89e3\u51b3\u3002<\/p>\n<h2>\u8001\u7248\u672c\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u65b0\u8001\u7248\u672c\u7684\u89e3\u51b3\u601d\u8def\u662f\u7c7b\u4f3c\u7684\uff0c\u90fd\u662f\u66ff\u6362Hibernate\u7684\u5b9e\u73b0\uff0c\u4e0b\u9762\u662f\u8001\u7248\u672c\u7684\u89e3\u51b3\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5728\u5de5\u7a0b\u4e2d\u65b0\u5efa<code>org.hibernate.cfg<\/code>\u5305<\/li>\n<li>\u627e\u5230<code>hibernate-core<\/code>\u5305\u4e0b\u7684<code>org.hibernate.cfg<\/code>\u4e0b\u7684<code>PropertyContainer<\/code>\u7c7b\uff0c\u590d\u5236\u5230\u672c\u5de5\u7a0b\u7684<code>org.hibernate.cfg<\/code>\u5305\u4e0b<\/li>\n<li>\u628a<code>PropertyContainer<\/code>\u7c7b\u4e2d\u5b9a\u4e49\u7684<code>persistentAttributeMap<\/code>\u7c7b\u578b\u4ece<code>TreeMap<\/code>\u4fee\u6539\u4e3a<code>LinkedHashMap<\/code><\/li>\n<\/ol>\n<h2>\u65b0\u7248\u672c\u89e3\u51b3\u65b9\u6848<\/h2>\n<p>\u867d\u7136\u4e4b\u524d\u7684\u65b9\u6848\u5931\u6548\u4e86\uff0c\u4f46\u601d\u8def\u5e94\u8be5\u8fd8\u662f\u5bf9\u7684\uff0c\u6240\u4ee5\u7b2c\u4e00\u53cd\u5e94\u662f\u770b\u770b\u5f53\u524d\u7248\u672c\u4e0b\u7684<code>PropertyContainer<\/code>\u7c7b\uff0c\u5177\u4f53\u5982\u4e0b\uff08\u7701\u7565\u4e86\u4e00\u4e9b\u4e0d\u91cd\u8981\u7684\u5185\u5bb9\uff09\uff1a<\/p>\n<pre><code class=\"java\">package org.hibernate.boot.model.internal;\n\n\/\/\u7701\u7565...\n\npublic class PropertyContainer {\n\n    private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, PropertyContainer.class.getName());\n\n    \/**\n     * The class for which this container is created.\n     *\/\n    private final XClass xClass;\n    private final XClass entityAtStake;\n\n    \/**\n     * Holds the AccessType indicated for use at the class\/container-level for cases where persistent attribute\n     * did not specify.\n     *\/\n    private final AccessType classLevelAccessType;\n\n    private final List&lt;XProperty&gt; persistentAttributes;\n\n    \/\/\u7701\u7565...\n\n}<\/code><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u6709\u4e24\u4e2a\u91cd\u8981\u53d8\u5316\u90e8\u5206\uff1a<\/p>\n<ol>\n<li><code>PropertyContainer<\/code>\u7c7b\u7684\u5305\u540d\u4ece<code>org.hibernate.cfg<\/code>\u6539\u5230\u4e86<code>org.hibernate.boot.model.internal<\/code><\/li>\n<li>\u4e4b\u524d\u7684<code>TreeMap&lt;String XProperty&gt; persistentAttributeMap<\/code>\u53d8\u91cf\u6ca1\u6709\u4e86\uff0c\u4f46\u591a\u4e86\u4e00\u4e2a<code>List&lt;XProperty&gt; persistentAttributes<\/code>\u3002\u8fdb\u4e00\u6b65\u89c2\u5bdf\u8fd9\u4e2a\u65b0\u53d8\u91cf\u7684\u5904\u7406\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u770b\u5230\u5982\u4e0b\u903b\u8f91\uff1a<\/li>\n<\/ol>\n<p><img decoding=\"async\" width=\"723\" height=\"292\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/bVde7gz\" alt=\"image.png\" title=\"image.png\" loading=\"lazy\"><\/p>\n<p>\u6240\u4ee5\uff0c\u65b0\u7248\u7684\u65b9\u6848\u5c31\u4ee5\u4e0b\u4e24\u4e2a\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u5728\u5de5\u7a0b\u4e2d\u65b0\u5efa<code>org.hibernate.boot.model.internal<\/code>\u5305<\/li>\n<li>\u627e\u5230<code>hibernate-core<\/code>\u5305\u4e0b\u7684<code>org.hibernate.boot.model.internal<\/code>\u4e0b\u7684<code>PropertyContainer<\/code>\u7c7b\uff0c\u590d\u5236\u5230\u672c\u5de5\u7a0b\u7684<code>org.hibernate.boot.model.internal<\/code>\u5305\u4e0b<\/li>\n<li>\u628a<code>PropertyContainer<\/code>\u7c7b\u4e2d\uff0c\u4e0a\u9762\u56fe\u4e2d\u7ea2\u8272\u5708\u51fa\u90e8\u95e8\u5b9a\u4e49\u7684<code>localAttributeMap = new TreeMap&lt;&gt;();<\/code>\u4fee\u6539\u4e3a<code>localAttributeMap = new LinkedHashMap&lt;&gt;();<\/code><\/li>\n<\/ol>\n<p>\u5230\u8fd9\u91cc\uff0c\u5728\u65b0\u7248\u672c\u4e2d\u7684\u8fd9\u4e2a\u95ee\u9898\u5c31\u89e3\u51b3\u4e86\u3002\u5982\u679c\u4f60\u4e5f\u9047\u5230\u4e86\u7c7b\u4f3c\u7684\u95ee\u9898\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002\u53e6\u5916\uff0c\u6b22\u8fce\u52a0\u5165\u6211\u4eec\u7684<a href=\"https:\/\/link.segmentfault.com\/?enc=zBKg%2BEQhPmU8%2F3iiNirz4Q%3D%3D.uwFDfpmkGlBaAAVCw0g8gaLtKn2sw87%2FN7mmrTRvZ2lxMt4EX3ampCz9DsFSjvkv\" rel=\"nofollow noopener noreferrer\" target=\"_blank\">Spring\u6280\u672f\u4ea4\u6d41\u7fa4<\/a>\uff0c\u53c2\u4e0e\u4ea4\u6d41\u4e0e\u8ba8\u8bba\uff0c\u66f4\u597d\u7684\u5b66\u4e60\u4e0e\u8fdb\u6b65\uff01<\/p>\n<blockquote><p>\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u516c\u4f17\u53f7\uff1a\u7a0b\u5e8f\u733fDD\u3002\u7b2c\u4e00\u65f6\u95f4\u4e86\u89e3\u524d\u6cbf\u884c\u4e1a\u6d88\u606f\u3001\u5206\u4eab\u6df1\u5ea6\u6280\u672f\u5e72\u8d27\u3001\u83b7\u53d6\u4f18\u8d28\u5b66\u4e60\u8d44\u6e90<\/p><\/blockquote>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000045509507\">https:\/\/segmentfault.com\/a\/1190000045509507<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u628aSpring Boot\u7684\u7248\u672c\u5347\u7ea7\u5230\u4e863.3.5\uff0c\u7a81\u7136\u53d1\u73b0\u4e00\u4e2a\u95ee\u9898\uff1a\u5f53\u4f7f\u7528Spring Data JPA\u81ea [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020424","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020424"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020424\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}