{"id":212,"date":"2024-08-16T12:36:20","date_gmt":"2024-08-16T04:36:20","guid":{"rendered":"https:\/\/note.ui11.cc\/?p=212"},"modified":"2024-08-16T12:36:21","modified_gmt":"2024-08-16T04:36:21","slug":"%e9%81%8d%e5%8e%86%e9%9b%86%e5%90%88","status":"publish","type":"post","link":"https:\/\/note.ui11.cc\/index.php\/2024\/08\/16\/%e9%81%8d%e5%8e%86%e9%9b%86%e5%90%88\/","title":{"rendered":"\u904d\u5386\u96c6\u5408"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&lt;insert id=\"insertBatch\">\n    insert into dish_flavor(dish_id, name, value) values\n     &lt;foreach collection=\"flavors\" item=\"df\" separator=\",\">\n    (#{df.dishId}, #{df.name},#{df.value})\n\n     &lt;\/foreach>\n\n    &lt;\/insert><\/code><\/pre>\n\n\n\n<p>\u4ee3\u7801\u7247\u6bb5\u662f\u4e00\u4e2aMyBatis\u7684&nbsp;<code>&lt;insert&gt;<\/code>&nbsp;\u6620\u5c04\u5668\u914d\u7f6e\uff0c\u7528\u4e8e\u6279\u91cf\u63d2\u5165\u6570\u636e\u5230&nbsp;<code>dish_flavor<\/code>&nbsp;\u8868\u4e2d\u3002\u8fd9\u4e2a\u914d\u7f6e\u4f7f\u7528\u4e86&nbsp;<code>&lt;foreach&gt;<\/code>&nbsp;\u6807\u7b7e\u6765\u904d\u5386&nbsp;<code>flavors<\/code>&nbsp;\u96c6\u5408\uff0c\u5e76\u4e3a\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u751f\u6210\u4e00\u6761\u63d2\u5165\u8bed\u53e5\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5173\u952e\u70b9\u89e3\u91ca\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;insert><\/code>\u00a0\u6807\u7b7e\u7528\u4e8e\u5b9a\u4e49\u4e00\u4e2a\u63d2\u5165\u64cd\u4f5c\u7684\u6620\u5c04\u3002<\/li>\n\n\n\n<li><code>id<\/code>\u00a0\u5c5e\u6027\u4e3a\u8fd9\u4e2a\u63d2\u5165\u64cd\u4f5c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u53ef\u4ee5\u5728MyBatis\u7684Mapper\u63a5\u53e3\u4e2d\u901a\u8fc7\u8fd9\u4e2a\u6807\u8bc6\u7b26\u6765\u8c03\u7528\u8fd9\u4e2a\u63d2\u5165\u64cd\u4f5c\u3002<\/li>\n\n\n\n<li><code>&lt;foreach><\/code>\u00a0\u6807\u7b7e\u7528\u4e8e\u904d\u5386\u96c6\u5408\uff0c<code>collection<\/code>\u00a0\u5c5e\u6027\u6307\u5b9a\u4e86\u8981\u904d\u5386\u7684\u96c6\u5408\uff0c<code>item<\/code>\u00a0\u5c5e\u6027\u5b9a\u4e49\u4e86\u96c6\u5408\u4e2d\u6bcf\u4e2a\u5143\u7d20\u7684\u522b\u540d\uff0c\u5728\u00a0<code>&lt;foreach><\/code>\u00a0\u5185\u90e8\u4f7f\u7528\u3002<\/li>\n\n\n\n<li><code>separator<\/code>\u00a0\u5c5e\u6027\u5b9a\u4e49\u4e86\u5728\u6bcf\u4e2a\u63d2\u5165\u8bed\u53e5\u4e4b\u95f4\u7684\u5206\u9694\u7b26\uff0c\u8fd9\u91cc\u4f7f\u7528\u9017\u53f7\u00a0<code>,<\/code>\u00a0\u6765\u5206\u9694\u6bcf\u4e2a\u63d2\u5165\u503c\u3002<\/li>\n\n\n\n<li><code>#{df.dishId}<\/code>,\u00a0<code>#{df.name}<\/code>,\u00a0<code>#{df.value}<\/code>\u00a0\u662fMyBatis\u7684\u53c2\u6570\u5360\u4f4d\u7b26\uff0c\u5b83\u4eec\u4f1a\u88ab\u66ff\u6362\u4e3a\u5b9e\u9645\u7684\u53c2\u6570\u503c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u573a\u666f<\/h3>\n\n\n\n<p>\u8fd9\u4e2a&nbsp;<code>&lt;insert&gt;<\/code>&nbsp;\u6620\u5c04\u5668\u914d\u7f6e\u901a\u5e38\u7528\u4e8e\u5904\u7406\u6279\u91cf\u63d2\u5165\u6570\u636e\u7684\u573a\u666f\uff0c\u4f8b\u5982\u5728\u521d\u59cb\u5316\u6570\u636e\u6216\u6279\u91cf\u5904\u7406\u7528\u6237\u63d0\u4ea4\u7684\u6570\u636e\u65f6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u793a\u4f8b<\/h3>\n\n\n\n<p>\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a&nbsp;<code>DishFlavorMapper<\/code>&nbsp;\u63a5\u53e3\uff0c\u5b83\u5b9a\u4e49\u4e86\u4e00\u4e2a&nbsp;<code>insertBatch<\/code>&nbsp;\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public interface DishFlavorMapper {\n    int insertBatch(List&lt;DishFlavor> flavors);\n}<\/code><\/pre>\n\n\n\n<p>\u5728\u00a0<code>DishFlavorMapper.xml<\/code>\u00a0\u6587\u4ef6\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u7684\u00a0<code>&lt;insert><\/code>\u00a0\u6620\u5c04\u5668\u914d\u7f6e\u6765\u5b9e\u73b0\u8fd9\u4e2a\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;mapper namespace=\"com.example.mapper.DishFlavorMapper\">\n    &lt;insert id=\"insertBatch\">\n        insert into dish_flavor(dish_id, name, value) values\n        &lt;foreach collection=\"flavors\" item=\"df\" separator=\",\">\n            (#{df.dishId}, #{df.name},#{df.value})\n        &lt;\/foreach>\n    &lt;\/insert>\n&lt;\/mapper><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u6ce8\u610f\u4e8b\u9879<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u786e\u4fdd\u00a0<code>flavors<\/code>\u00a0\u53c2\u6570\u662f\u4e00\u4e2a\u975e\u7a7a\u7684\u00a0<code>List&lt;DishFlavor><\/code>\u00a0\u7c7b\u578b\u7684\u96c6\u5408\uff0c\u4e14\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u00a0<code>DishFlavor<\/code>\u00a0\u5bf9\u8c61\u90fd\u5305\u542b\u6709\u6548\u7684\u00a0<code>dishId<\/code>,\u00a0<code>name<\/code>, \u548c\u00a0<code>value<\/code>\u00a0\u5c5e\u6027\u503c\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u00a0<code>flavors<\/code>\u00a0\u96c6\u5408\u4e3a\u7a7a\u6216\u4e3a\u00a0<code>null<\/code>\uff0c\u5219\u4e0d\u4f1a\u751f\u6210\u4efb\u4f55\u63d2\u5165\u8bed\u53e5\u3002<\/li>\n\n\n\n<li>\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u786e\u4fddMyBatis\u7684\u914d\u7f6e\u6b63\u786e\uff0c\u5305\u62ecMapper\u63a5\u53e3\u548cXML\u6620\u5c04\u6587\u4ef6\u7684\u6b63\u786e\u5173\u8054\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u4f60\u53ef\u4ee5\u7075\u6d3b\u5730\u5904\u7406\u6279\u91cf\u63d2\u5165\u64cd\u4f5c\uff0c\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee3\u7801\u7247\u6bb5\u662f\u4e00\u4e2aMyBatis\u7684&nbsp;&lt;insert&gt;&nbsp;\u6620\u5c04\u5668\u914d\u7f6e\uff0c\u7528\u4e8e\u6279\u91cf\u63d2\u5165\u6570\u636e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4],"tags":[],"class_list":["post-212","post","type-post","status-publish","format-standard","hentry","category-uncategorized","category-4"],"_links":{"self":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/comments?post=212"}],"version-history":[{"count":1,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/212\/revisions"}],"predecessor-version":[{"id":213,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/212\/revisions\/213"}],"wp:attachment":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/media?parent=212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/categories?post=212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/tags?post=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}