{"id":66344,"date":"2025-05-03T11:30:48","date_gmt":"2025-05-03T03:30:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66344\/"},"modified":"2025-05-03T11:30:48","modified_gmt":"2025-05-03T03:30:48","slug":"%e5%9c%a8-spring-boot-%e4%b8%ad%e5%ae%9e%e7%8e%b0%e5%8e%9f%e5%9e%8b%e8%ae%be%e8%ae%a1%e6%a8%a1%e5%bc%8f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66344\/","title":{"rendered":"\u5728 Spring Boot \u4e2d\u5b9e\u73b0\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f"},"content":{"rendered":"<h2> \u4ecb\u7ecd <\/h2>\n<p>\u5728\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0c\u7ba1\u7406\u5bf9\u8c61\u521b\u5efa\u53ef\u80fd\u5f88\u590d\u6742\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u51e0\u4e4e\u76f8\u540c\u4f46\u5177\u4f53\u7ec6\u8282\u6709\u6240\u4e0d\u540c\u7684\u5b9e\u4f8b\u65f6\u3002\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u63d0\u4f9b\u4e86\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u5141\u8bb8\u6211\u4eec\u901a\u8fc7\u590d\u5236\u6216\u201c\u514b\u9686\u201d\u73b0\u6709\u5bf9\u8c61\u6765\u521b\u5efa\u65b0\u5bf9\u8c61\u3002\u5f53\u5bf9\u8c61\u7684\u521b\u5efa\u6210\u672c\u9ad8\u6602\u6216\u6d89\u53ca\u5927\u91cf\u521d\u59cb\u5316\u65f6\uff0c\u6b64\u6a21\u5f0f\u7279\u522b\u6709\u7528\u3002<\/p>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u5b9e\u9645\u7684\u7535\u5b50\u5546\u52a1\u7528\u4f8b\u6765\u63a2\u7d22\u5982\u4f55\u5728 spring boot \u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\uff1a\u521b\u5efa\u548c\u4fdd\u7559\u4ea7\u54c1\u53d8\u4f53\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c\u60a8\u4e0d\u4ec5\u53ef\u4ee5\u4e86\u89e3\u539f\u578b\u6a21\u5f0f\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u8fd8\u53ef\u4ee5\u4e86\u89e3\u5b83\u5982\u4f55\u7b80\u5316\u5b9e\u9645\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5bf9\u8c61\u521b\u5efa\u3002<\/p>\n<h2> \u4e86\u89e3\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f <\/h2>\n<p>\u539f\u578b\u6a21\u5f0f\u662f\u4e00\u79cd\u521b\u5efa\u578b\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5141\u8bb8\u60a8\u901a\u8fc7\u514b\u9686\u73b0\u6709\u5bf9\u8c61\uff08\u79f0\u4e3a\u539f\u578b\uff09\u6765\u521b\u5efa\u65b0\u5b9e\u4f8b\u3002\u5f53\u60a8\u62e5\u6709\u5177\u6709\u5404\u79cd\u5c5e\u6027\u7684\u57fa\u7840\u5bf9\u8c61\u65f6\uff0c\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u6709\u7528\uff0c\u5e76\u4e14\u4ece\u5934\u5f00\u59cb\u521b\u5efa\u6bcf\u4e2a\u53d8\u4f53\u5c06\u662f\u591a\u4f59\u4e14\u4f4e\u6548\u7684\u3002<\/p>\n<p>\u5728 java \u4e2d\uff0c\u8fd9\u79cd\u6a21\u5f0f\u901a\u5e38\u4f7f\u7528 cloneable \u63a5\u53e3\u6216\u5b9a\u4e49\u81ea\u5b9a\u4e49\u514b\u9686\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u4e3b\u8981\u601d\u60f3\u662f\u63d0\u4f9b\u4e00\u4e2a\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u8fdb\u884c\u590d\u5236\u7684\u201c\u84dd\u56fe\u201d\uff0c\u4fdd\u6301\u539f\u59cb\u5bf9\u8c61\u5b8c\u6574\u3002<\/p>\n<h2> \u539f\u578b\u6a21\u5f0f\u7684\u4e3b\u8981\u4f18\u70b9\uff1a <\/h2>\n<ol>\n<li>\n<p>\u51cf\u5c11\u521d\u59cb\u5316\u65f6\u95f4\uff1a\u60a8\u65e0\u9700\u4ece\u5934\u5f00\u59cb\u521b\u5efa\u5bf9\u8c61\uff0c\u800c\u662f\u514b\u9686\u548c\u4fee\u6539\u73b0\u6709\u5b9e\u4f8b\uff0c\u4ece\u800c\u8282\u7701\u521d\u59cb\u5316\u65f6\u95f4\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c01\u88c5\u5bf9\u8c61\u521b\u5efa\u903b\u8f91\uff1a\u60a8\u53ef\u4ee5\u5b9a\u4e49\u5982\u4f55\u5728\u5bf9\u8c61\u672c\u8eab\u5185\u514b\u9686\u5bf9\u8c61\uff0c\u540c\u65f6\u9690\u85cf\u5b9e\u4f8b\u5316\u8be6\u7ec6\u4fe1\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u589e\u5f3a\u6027\u80fd\uff1a\u5bf9\u4e8e\u7ecf\u5e38\u521b\u5efa\u7c7b\u4f3c\u5bf9\u8c61\uff08\u4f8b\u5982\u4ea7\u54c1\u53d8\u4f53\uff09\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u539f\u578b\u6a21\u5f0f\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/li>\n<\/ol>\n<h2> \u7535\u5b50\u5546\u52a1\u7528\u4f8b\uff1a\u7ba1\u7406\u4ea7\u54c1\u53d8\u4f53 <\/h2>\n<p>\u60f3\u8c61\u4e00\u4e2a\u7535\u5b50\u5546\u52a1\u5e73\u53f0\uff0c\u5176\u4e2d\u57fa\u672c\u4ea7\u54c1\u5177\u6709\u5404\u79cd\u914d\u7f6e\u6216\u201c\u53d8\u4f53\u201d &#8211; \u4f8b\u5982\uff0c\u5177\u6709\u4e0d\u540c\u989c\u8272\u3001\u5b58\u50a8\u9009\u9879\u548c\u4fdd\u4fee\u6761\u6b3e\u7684\u667a\u80fd\u624b\u673a\u3002\u6211\u4eec\u53ef\u4ee5\u514b\u9686\u57fa\u7840\u4ea7\u54c1\uff0c\u7136\u540e\u6839\u636e\u9700\u8981\u8c03\u6574\u7279\u5b9a\u5b57\u6bb5\uff0c\u800c\u4e0d\u662f\u4ece\u5934\u5f00\u59cb\u91cd\u65b0\u521b\u5efa\u6bcf\u4e2a\u53d8\u4f53\u3002\u8fd9\u6837\uff0c\u5171\u4eab\u5c5e\u6027\u4fdd\u6301\u4e00\u81f4\uff0c\u6211\u4eec\u53ea\u4fee\u6539\u7279\u5b9a\u4e8e\u53d8\u4f53\u7684\u7ec6\u8282\u3002<\/p>\n<p>\u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 spring boot \u670d\u52a1\uff0c\u4ee5\u4f7f\u7528\u539f\u578b\u6a21\u5f0f\u521b\u5efa\u548c\u4fdd\u5b58\u4ea7\u54c1\u53d8\u4f53\u3002<\/p>\n<h2> \u5728 spring boot \u4e2d\u5b9e\u73b0\u539f\u578b\u6a21\u5f0f <\/h2>\n<h3> \u7b2c 1 \u6b65\uff1a\u5b9a\u4e49\u57fa\u7840\u4ea7\u54c1 <\/h3>\n<p>\u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u4ea7\u54c1\u7c7b\uff0c\u5176\u4e2d\u5305\u542b\u4ea7\u54c1\u7684\u5fc5\u8981\u5b57\u6bb5\uff0c\u4f8b\u5982 id\u3001\u540d\u79f0\u3001\u989c\u8272\u3001\u578b\u53f7\u3001\u5b58\u50a8\u3001\u4fdd\u4fee\u548c\u4ef7\u683c\u3002\u6211\u4eec\u8fd8\u5c06\u6dfb\u52a0\u4e00\u4e2a cloneproduct \u65b9\u6cd5\u6765\u521b\u5efa\u4ea7\u54c1\u7684\u526f\u672c\u3002<\/p>\n<pre>public interface productprototype extends cloneable {\n    productprototype cloneproduct();\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>@entity\n@table(name = \"products\")\n@data\npublic class product implements productprototype {\n\n    @id\n    @generatedvalue(strategy = generationtype.identity)\n    private long id;\n\n    @column(name = \"product_id\")\n    private long productid;\n\n    @column(name = \"name\")\n    private string name;\n\n    @column(name = \"model\")\n    private string model;\n\n    @column(name = \"color\")\n    private string color;\n\n    @column(name = \"storage\")\n    private int storage;\n\n    @column(name = \"warranty\")\n    private int warranty;\n\n    @column(name = \"price\")\n    private double price;\n\n    @override\n    public productprototype cloneproduct() {\n        try {\n            product product = (product) super.clone();\n            product.setid(null); \/\/ database will assign new id for each cloned instance\n            return product;\n        } catch (clonenotsupportedexception e) {\n            return null;\n        }\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u8bbe\u7f6e\u4e2d\uff1a<\/p>\n<p><strong>cloneproduct:<\/strong> \u6b64\u65b9\u6cd5\u521b\u5efa product \u5bf9\u8c61\u7684\u514b\u9686\uff0c\u5e76\u5c06 id \u8bbe\u7f6e\u4e3a null \u4ee5\u786e\u4fdd\u6570\u636e\u5e93\u4e3a\u6bcf\u4e2a\u514b\u9686\u5b9e\u4f8b\u5206\u914d\u4e00\u4e2a\u65b0 id\u3002<\/p>\n<h3> \u7b2c 2 \u6b65\uff1a\u521b\u5efa\u5904\u7406\u53d8\u4f53\u7684\u670d\u52a1 <\/h3>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u5177\u6709\u4fdd\u5b58\u53d8\u4f53\u65b9\u6cd5\u7684 productservice\u3002\u6b64\u65b9\u6cd5\u514b\u9686\u57fa\u7840\u4ea7\u54c1\u5e76\u5e94\u7528\u7279\u5b9a\u4e8e\u53d8\u4f53\u7684\u5c5e\u6027\uff0c\u7136\u540e\u5c06\u5176\u53e6\u5b58\u4e3a\u65b0\u4ea7\u54c1\u3002<\/p>\n<pre>public interface productservice {\n\n    \/\/ for saving the base product\n    product savebaseproduct(product product);\n\n    \/\/ for saving the variants\n    product savevariant(long baseproductid, variantrequest variant);\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>@log4j2\n@service\npublic class productserviceimpl implements productservice {\n\n    private final productrepository productrepository;\n\n    public productserviceimpl(productrepository productrepository) {\n        this.productrepository = productrepository;\n    }\n\n    \/**\n     * saving base product, going to use this object for cloning\n     *\n     * @param product the input\n     * @return product object\n     *\/\n    @override\n    public product savebaseproduct(product product) {\n        log.debug(\"save base product with the detail {}\", product);\n        return productrepository.save(product);\n    }\n\n    \/**\n     * fetching the base product and cloning it to add the variant informations\n     *\n     * @param baseproductid baseproductid\n     * @param variant       the input request\n     * @return product\n     *\/\n    @override\n    public product savevariant(long baseproductid, variantrequest variant) {\n        log.debug(\"save variant for the base product {}\", baseproductid);\n        product baseproduct = productrepository.findbyproductid(baseproductid)\n                .orelsethrow(() -&gt; new nosuchelementexception(\"base product not found!\"));\n\n        \/\/ cloning the baseproduct and adding the variant details\n        product variantdetail = (product) baseproduct.cloneproduct();\n        variantdetail.setcolor(variant.color());\n        variantdetail.setmodel(variant.model());\n        variantdetail.setwarranty(variant.warranty());\n        variantdetail.setprice(variant.price());\n        variantdetail.setstorage(variant.storage());\n\n        \/\/ save the variant details\n        return productrepository.save(variantdetail);\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u6b64\u670d\u52a1\u4e2d\uff1a<\/p>\n<p><strong>savevariant\uff1a<\/strong>\u6b64\u65b9\u6cd5\u901a\u8fc7 id \u68c0\u7d22\u57fa\u672c\u4ea7\u54c1\uff0c\u514b\u9686\u5b83\uff0c\u5e94\u7528\u53d8\u4f53\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3a\u6570\u636e\u5e93\u4e2d\u7684\u65b0\u6761\u76ee\u3002<\/p>\n<h2> \u7b2c 3 \u6b65\uff1a\u521b\u5efa\u53d8\u4f53\u7684\u63a7\u5236\u5668 <\/h2>\n<p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 rest \u63a7\u5236\u5668\u6765\u516c\u5f00\u53d8\u4f53\u521b\u5efa api\u3002<\/p>\n<pre>@restcontroller\n@requestmapping(\"\/api\/v1\/products\")\n@log4j2\npublic class productcontroller {\n\n    private final productservice productservice;\n\n    public productcontroller(productservice productservice) {\n        this.productservice = productservice;\n    }\n\n    @postmapping\n    public responseentity&lt;product&gt; savebaseproduct(@requestbody product product) {\n        log.debug(\"rest request to save the base product {}\", product);\n        return responseentity.ok(productservice.savebaseproduct(product));\n    }\n\n    @postmapping(\"\/{baseproductid}\/variants\")\n    public responseentity&lt;product&gt; savevariants(@pathvariable long baseproductid, @requestbody variantrequest variantrequest) {\n        log.debug(\"rest request to create the variant for the base product\");\n        return responseentity.ok(productservice.savevariant(baseproductid, variantrequest));\n    }\n}\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u91cc\uff1a<\/p>\n<p><strong>savevariant:<\/strong> \u6b64\u7aef\u70b9\u5904\u7406 http post \u8bf7\u6c42\u4ee5\u521b\u5efa\u6307\u5b9a\u4ea7\u54c1\u7684\u53d8\u4f53\u3002\u5b83\u5c06\u521b\u5efa\u903b\u8f91\u59d4\u6258\u7ed9 productservice\u3002<\/p>\n<h2> \u4f7f\u7528\u539f\u578b\u6a21\u5f0f\u7684\u597d\u5904 <\/h2>\n<p>\u901a\u8fc7\u6b64\u5b9e\u65bd\uff0c\u6211\u4eec\u770b\u5230\u4e86\u51e0\u4e2a\u660e\u663e\u7684\u4f18\u52bf\uff1a<\/p>\n<p><strong>\u4ee3\u7801\u53ef\u91cd\u7528\u6027\uff1a<\/strong>\u901a\u8fc7\u5c06\u514b\u9686\u903b\u8f91\u5c01\u88c5\u5728 product \u7c7b\u4e2d\uff0c\u6211\u4eec\u907f\u514d\u4e86\u670d\u52a1\u548c\u63a7\u5236\u5668\u5c42\u4e2d\u7684\u4ee3\u7801\u91cd\u590d\u3002<\/p>\n<p><strong>\u7b80\u5316\u7ef4\u62a4\uff1a<\/strong>\u539f\u578b\u6a21\u5f0f\u96c6\u4e2d\u4e86\u514b\u9686\u903b\u8f91\uff0c\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u7ba1\u7406\u5bf9\u8c61\u7ed3\u6784\u7684\u66f4\u6539\u3002<\/p>\n<p><strong>\u9ad8\u6548\u53d8\u4f53\u521b\u5efa\uff1a<\/strong>\u6bcf\u4e2a\u65b0\u53d8\u4f53\u90fd\u662f\u57fa\u7840\u4ea7\u54c1\u7684\u514b\u9686\uff0c\u51cf\u5c11\u5197\u4f59\u6570\u636e\u8f93\u5165\u5e76\u786e\u4fdd\u5171\u4eab\u5c5e\u6027\u7684\u4e00\u81f4\u6027\u3002<\/p>\n<h3> \u8fd0\u884c\u7a0b\u5e8f <\/h3>\n<h4> \u4f7f\u7528 gradle \u6784\u5efa spring boot \u9879\u76ee <\/h4>\n<pre>.\/gradlew build\n.\/gradlew bootrun\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4> \u901a\u8fc7rest\u5ba2\u6237\u7aef\u6267\u884c <\/h4>\n<p>\u4fdd\u5b58\u57fa\u7840\u4ea7\u54c1<\/p>\n<pre>curl --location 'http:\/\/localhost:8080\/api\/v1\/products' \n--header 'content-type: application\/json' \n--data '{\n    \"productid\": 101,\n    \"name\": \"apple iphone 16\",\n    \"model\": \"iphone 16\",\n    \"color\": \"black\",\n    \"storage\": 128,\n    \"warranty\": 1,\n    \"price\": 12.5\n}'\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4fdd\u5b58\u53d8\u4f53<\/p>\n<pre>curl --location 'http:\/\/localhost:8080\/api\/v1\/products\/101\/variants' \n--header 'Content-Type: application\/json' \n--data '{\n    \"model\": \"Iphone 16\",\n    \"color\": \"dark night\",\n    \"storage\": 256,\n    \"warranty\": 1,\n    \"price\": 14.5\n}'\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7ed3\u679c\uff08\u65b0\u53d8\u4f53\u4ecd\u7136\u5b58\u5728\uff0c\u6ca1\u6709\u4efb\u4f55\u95ee\u9898\uff09<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173163748391836.jpg\" class=\"aligncenter\" title=\"\u5728 Spring Boot \u4e2d\u5b9e\u73b0\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u63d2\u56fe\" alt=\"\u5728 Spring Boot \u4e2d\u5b9e\u73b0\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u63d2\u56fe\" \/><\/p>\n<h3> hub \u5b58\u50a8\u5e93 <\/h3>\n<p>\u60a8\u53ef\u4ee5\u5728\u4ee5\u4e0b github \u5b58\u50a8\u5e93\u4e2d\u627e\u5230\u4ea7\u54c1\u53d8\u4f53\u7684\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u7684\u5b8c\u6574\u5b9e\u73b0\uff1a\u200b\u200b<\/p>\n<p>github \u5b58\u50a8\u5e93\u94fe\u63a5<\/p>\n<h3> \u5728 linkedin \u4e0a\u5173\u6ce8\u6211 <\/h3>\n<p>\u4fdd\u6301\u8054\u7cfb\u5e76\u5173\u6ce8\u6211\uff0c\u83b7\u53d6\u6709\u5173\u8f6f\u4ef6\u5f00\u53d1\u3001\u8bbe\u8ba1\u6a21\u5f0f\u548c spring boot \u7684\u66f4\u591a\u6587\u7ae0\u3001\u6559\u7a0b\u548c\u89c1\u89e3\uff1a<\/p>\n<p>\u5728 linkedin \u4e0a\u5173\u6ce8\u6211<\/p>\n<h2> \u7ed3\u8bba <\/h2>\n<p>\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u9002\u7528\u4e8e\u5bf9\u8c61\u91cd\u590d\u9891\u7e41\u7684\u60c5\u51b5\uff0c\u5982\u7535\u5b50\u5546\u52a1\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u4ea7\u54c1\u53d8\u4f53\u3002\u901a\u8fc7\u5728 spring boot \u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u6b64\u6a21\u5f0f\uff0c\u6211\u4eec\u63d0\u9ad8\u4e86\u5bf9\u8c61\u521b\u5efa\u7684\u6548\u7387\u548c\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u9700\u8981\u521b\u5efa\u5177\u6709\u8f83\u5c0f\u53d8\u5316\u7684\u76f8\u4f3c\u5bf9\u8c61\u7684\u573a\u666f\u4e2d\u7279\u522b\u6709\u7528\uff0c\u4f7f\u5176\u6210\u4e3a\u73b0\u5b9e\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u7684\u4e00\u79cd\u6709\u4ef7\u503c\u7684\u6280\u672f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5728 Spring Boot \u4e2d\u5b9e\u73b0\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd \u5728\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0c\u7ba1\u7406\u5bf9\u8c61\u521b\u5efa\u53ef\u80fd\u5f88\u590d\u6742\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u51e0\u4e4e\u76f8\u540c\u4f46\u5177\u4f53\u7ec6\u8282\u6709\u6240\u4e0d\u540c\u7684\u5b9e\u4f8b\u65f6\u3002\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\u63d0\u4f9b\u4e86\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u5141\u8bb8\u6211\u4eec\u901a\u8fc7\u590d\u5236\u6216\u201c\u514b\u9686\u201d\u73b0\u6709\u5bf9\u8c61\u6765\u521b\u5efa\u65b0\u5bf9\u8c61\u3002\u5f53\u5bf9\u8c61\u7684\u521b\u5efa\u6210\u672c\u9ad8\u6602\u6216\u6d89\u53ca\u5927\u91cf\u521d\u59cb\u5316\u65f6\uff0c\u6b64\u6a21\u5f0f\u7279\u522b\u6709\u7528\u3002 \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u5b9e\u9645\u7684\u7535\u5b50\u5546\u52a1\u7528\u4f8b\u6765\u63a2\u7d22\u5982\u4f55\u5728 spring boot \u5e94\u7528\u7a0b\u5e8f\u4e2d\u5b9e\u73b0\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f\uff1a\u521b\u5efa\u548c\u4fdd\u7559\u4ea7\u54c1\u53d8\u4f53\u3002\u901a\u8fc7\u8fd9\u4e2a\u793a\u4f8b\uff0c\u60a8\u4e0d\u4ec5\u53ef\u4ee5\u4e86\u89e3\u539f\u578b\u6a21\u5f0f\u7684\u57fa\u7840\u77e5\u8bc6\uff0c\u8fd8\u53ef\u4ee5\u4e86\u89e3\u5b83\u5982\u4f55\u7b80\u5316\u5b9e\u9645\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u5bf9\u8c61\u521b\u5efa\u3002 \u4e86\u89e3\u539f\u578b\u8bbe\u8ba1\u6a21\u5f0f \u539f\u578b\u6a21\u5f0f\u662f\u4e00\u79cd\u521b\u5efa\u578b\u8bbe\u8ba1\u6a21\u5f0f\uff0c\u5141\u8bb8\u60a8\u901a\u8fc7\u514b\u9686\u73b0\u6709\u5bf9\u8c61\uff08\u79f0\u4e3a\u539f\u578b\uff09\u6765\u521b\u5efa\u65b0\u5b9e\u4f8b\u3002\u5f53\u60a8\u62e5\u6709\u5177\u6709\u5404\u79cd\u5c5e\u6027\u7684\u57fa\u7840\u5bf9\u8c61\u65f6\uff0c\u8fd9\u79cd\u65b9\u6cd5\u7279\u522b\u6709\u7528\uff0c\u5e76\u4e14\u4ece\u5934\u5f00\u59cb\u521b\u5efa\u6bcf\u4e2a\u53d8\u4f53\u5c06\u662f\u591a\u4f59\u4e14\u4f4e\u6548\u7684\u3002 \u5728 java \u4e2d\uff0c\u8fd9\u79cd\u6a21\u5f0f\u901a\u5e38\u4f7f\u7528 cloneable \u63a5\u53e3\u6216\u5b9a\u4e49\u81ea\u5b9a\u4e49\u514b\u9686\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u4e3b\u8981\u601d\u60f3\u662f\u63d0\u4f9b\u4e00\u4e2a\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u8fdb\u884c\u590d\u5236\u7684\u201c\u84dd\u56fe\u201d\uff0c\u4fdd\u6301\u539f\u59cb\u5bf9\u8c61\u5b8c\u6574\u3002 \u539f\u578b\u6a21\u5f0f\u7684\u4e3b\u8981\u4f18\u70b9\uff1a \u51cf\u5c11\u521d\u59cb\u5316\u65f6\u95f4\uff1a\u60a8\u65e0\u9700\u4ece\u5934\u5f00\u59cb\u521b\u5efa\u5bf9\u8c61\uff0c\u800c\u662f\u514b\u9686\u548c\u4fee\u6539\u73b0\u6709\u5b9e\u4f8b\uff0c\u4ece\u800c\u8282\u7701\u521d\u59cb\u5316\u65f6\u95f4\u3002 \u5c01\u88c5\u5bf9\u8c61\u521b\u5efa\u903b\u8f91\uff1a\u60a8\u53ef\u4ee5\u5b9a\u4e49\u5982\u4f55\u5728\u5bf9\u8c61\u672c\u8eab\u5185\u514b\u9686\u5bf9\u8c61\uff0c\u540c\u65f6\u9690\u85cf\u5b9e\u4f8b\u5316\u8be6\u7ec6\u4fe1\u606f\u3002 \u589e\u5f3a\u6027\u80fd\uff1a\u5bf9\u4e8e\u7ecf\u5e38\u521b\u5efa\u7c7b\u4f3c\u5bf9\u8c61\uff08\u4f8b\u5982\u4ea7\u54c1\u53d8\u4f53\uff09\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u539f\u578b\u6a21\u5f0f\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002 \u7535\u5b50\u5546\u52a1\u7528\u4f8b\uff1a\u7ba1\u7406\u4ea7\u54c1\u53d8\u4f53 \u60f3\u8c61\u4e00\u4e2a\u7535\u5b50\u5546\u52a1\u5e73\u53f0\uff0c\u5176\u4e2d\u57fa\u672c\u4ea7\u54c1\u5177\u6709\u5404\u79cd\u914d\u7f6e\u6216\u201c\u53d8\u4f53\u201d &#8211; \u4f8b\u5982\uff0c\u5177\u6709\u4e0d\u540c\u989c\u8272\u3001\u5b58\u50a8\u9009\u9879\u548c\u4fdd\u4fee\u6761\u6b3e\u7684\u667a\u80fd\u624b\u673a\u3002\u6211\u4eec\u53ef\u4ee5\u514b\u9686\u57fa\u7840\u4ea7\u54c1\uff0c\u7136\u540e\u6839\u636e\u9700\u8981\u8c03\u6574\u7279\u5b9a\u5b57\u6bb5\uff0c\u800c\u4e0d\u662f\u4ece\u5934\u5f00\u59cb\u91cd\u65b0\u521b\u5efa\u6bcf\u4e2a\u53d8\u4f53\u3002\u8fd9\u6837\uff0c\u5171\u4eab\u5c5e\u6027\u4fdd\u6301\u4e00\u81f4\uff0c\u6211\u4eec\u53ea\u4fee\u6539\u7279\u5b9a\u4e8e\u53d8\u4f53\u7684\u7ec6\u8282\u3002 \u5728\u6211\u4eec\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 spring boot \u670d\u52a1\uff0c\u4ee5\u4f7f\u7528\u539f\u578b\u6a21\u5f0f\u521b\u5efa\u548c\u4fdd\u5b58\u4ea7\u54c1\u53d8\u4f53\u3002 \u5728 spring boot \u4e2d\u5b9e\u73b0\u539f\u578b\u6a21\u5f0f \u7b2c 1 \u6b65\uff1a\u5b9a\u4e49\u57fa\u7840\u4ea7\u54c1 \u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u4ea7\u54c1\u7c7b\uff0c\u5176\u4e2d\u5305\u542b\u4ea7\u54c1\u7684\u5fc5\u8981\u5b57\u6bb5\uff0c\u4f8b\u5982 id\u3001\u540d\u79f0\u3001\u989c\u8272\u3001\u578b\u53f7\u3001\u5b58\u50a8\u3001\u4fdd\u4fee\u548c\u4ef7\u683c\u3002\u6211\u4eec\u8fd8\u5c06\u6dfb\u52a0\u4e00\u4e2a cloneproduct \u65b9\u6cd5\u6765\u521b\u5efa\u4ea7\u54c1\u7684\u526f\u672c\u3002 public interface productprototype extends cloneable { productprototype cloneproduct(); } \u767b\u5f55\u540e\u590d\u5236 @entity @table(name = &#8220;products&#8221;) @data public class product implements [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-66344","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=66344"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66344\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}