{"id":923,"date":"2021-09-09T14:34:27","date_gmt":"2021-09-09T06:34:27","guid":{"rendered":"https:\/\/fireinsect.top\/?p=923"},"modified":"2021-10-06T08:01:58","modified_gmt":"2021-10-06T00:01:58","slug":"mybatis%e5%9f%ba%e7%a1%802%ef%bc%88xml%ef%bc%89","status":"publish","type":"post","link":"https:\/\/fireinsect.top\/index.php\/2021\/09\/09\/mybatis%e5%9f%ba%e7%a1%802%ef%bc%88xml%ef%bc%89\/","title":{"rendered":"MyBatis\u57fa\u78402\uff08XML\uff09"},"content":{"rendered":"\n<p>XML\u6a21\u5f0f\u5f00\u53d1\u987a\u5e8f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u521b\u5efaDO\u5bf9\u8c61<\/li><li>\u521b\u5efaDAO\u5bf9\u8c61\uff0c\u914d\u7f6e<strong>@Mapper<\/strong>\u6ce8\u89e3<\/li><li>\u521b\u5efaXML\u6587\u4ef6\uff0c\u5e76\u5b8c\u6210<strong>resultMap<\/strong>\u914d\u7f6e<\/li><li>\u521b\u5efa\u5bf9\u5e94\u7684XML\u8bed\u53e5<\/li><\/ol>\n\n\n\n<!--more-->\n\n\n\n<div style=\"height:36px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u5728MyBatis\u4e2d\u4f7f\u7528XML\u9996\u5148\u9700\u8981\u5728 application.properties \u6587\u4ef6\u4e2d\u6dfb\u52a0\u914d\u7f6e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">mybatis.mapper-locations=classpath:com\/youkeda\/dao\/*.xml,classpath:com\/youkeda\/comment\/dao\/*.xml<\/code><\/pre>\n\n\n\n<p>\u4e00\u822c\u6765\u8bf4\u8fd9\u4e2a\u8def\u5f84\u548cDAO\u7684\u5305\u8def\u5f84\u4e00\u81f4\uff0c\u4e00\u4e2aDAO\u7c7b\u5bf9\u5e94\u4e00\u4e2aXML\u6587\u4ef6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\"><strong>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<\/strong>\n<strong>&lt;!DOCTYPE mapper PUBLIC \"-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN\"\n        \"http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd\"&gt;<\/strong>\n\/\/\u4ee5\u4e0a\u4e3a\u5934\u4fe1\u606f\n&lt;mapper namespace=\"com.youkeda.comment.dao.UserDAO\"&gt;\n&lt;\/mapper&gt;<\/code><\/pre>\n\n\n\n<p>XML\u5728\u5199\u5165\u5934\u4fe1\u606f\u540e\u9700\u8981\u7ee7\u7eed\u6dfb\u52a0mapper\u8282\u70b9\uff0c\u8282\u70b9\u5b58\u5728<strong> namespace<\/strong> \u5c5e\u6027\u8868\u793a\u547d\u540d\u7a7a\u95f4\uff0c\u4e00\u822c\u8fd9\u91cc\u6240\u5bf9\u5e94\u7684DAO\u7684\u5168\u79f0\u3002<\/p>\n\n\n\n<div style=\"height:37px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\" style=\"font-size:25px\">resultMap<\/p>\n\n\n\n<p>resultMap\u7528\u4e8e\u5904\u7406\u8868\u548cDO\u5bf9\u8c61\u7684\u5c5e\u6027\u6620\u5c04\uff0c\u786e\u4fdd\u8868\u4e2d\u7684\u6bcf\u4e00\u4e2a\u5b57\u6bb5\u90fd\u6709\u5c5e\u6027\u53ef\u4ee5\u5339\u914d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;mapper namespace=\"com.youkeda.comment.dao.UserDAO\"&gt;\n\n  &lt;resultMap id=\"userResultMap\" type=\"com.youkeda.comment.dataobject.UserDO\"&gt;\n    &lt;id column=\"id\" property=\"id\"\/&gt;\n    &lt;result column=\"user_name\" property=\"userName\"\/&gt;\n  &lt;\/resultMap&gt;\n\n&lt;\/mapper&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:14px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>resultMap\u4e2d\u7684\u5c5e\u6027\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"list1 wp-block-list\"><li><strong>id<\/strong>  \u552f\u4e00\u6807\u8bc6\uff0c\u4e00\u822c\u547d\u540d\u4e3a <strong>xxxResultMap<\/strong><\/li><li><strong>type<\/strong> \u5bf9\u5e94\u7684DO\u7c7b\u5b8c\u6574\u8def\u5f84<\/li><\/ul>\n\n\n\n<p> <\/p>\n\n\n\n<p>resultMap\u7684\u5b50\u8282\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"list1 wp-block-list\"><li><strong>id<\/strong>  \u8bbe\u7f6e\u6570\u636e\u5e93\u4e3b\u952e\u5b57\u6bb5\u4fe1\u606f\uff0ccolumn\u5c5e\u6027\u5bf9\u5e94\u7684\u662f\u8868\u7684\u5b57\u6bb5\u540d\uff0cproperty\u5bf9\u5e94\u7684\u662fDO\u5c5e\u6027\u540d\u79f0<\/li><li><strong>result<\/strong>  \u8bbe\u7f6e\u6570\u636e\u5e93\u5176\u4ed6\u5b57\u6bb5\u4fe1\u606f\uff0ccolumn\u5c5e\u6027\u5bf9\u5e94\u7684\u662f\u8868\u7684\u5b57\u6bb5\u540d\uff0cproperty\u5bf9\u5e94\u7684\u662fDO\u5c5e\u6027\u540d\u79f0<\/li><\/ul>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>resultMap\u4e5f\u5b58\u5728\u5b50\u8282\u70b9 <strong>&lt;association&gt;<\/strong> \u7528\u4e8e\u805a\u5408\u5176\u4ed6\u5bf9\u8c61\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">              &lt;association property=\"author\" javaType=\"com.youkeda.comment.model.User\"&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;id column=\"user_id\" property=\"id\"\/&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;result column=\"user_name\" property=\"userName\"&gt;&lt;\/result&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;result column=\"nick_name\" property=\"nickName\"&gt;&lt;\/result&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;result column=\"avatar\" property=\"avatar\"&gt;&lt;\/result&gt;\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;\/association&gt;<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d <strong>javaType<\/strong> \u8868\u793a\u5bf9\u5e94\u662f\u6570\u636e\u6a21\u578b\uff0cproperty \u5bf9\u5e94\u7684\u662f\u8868\u4e2d\u5b57\u6bb5\u540d<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">XML\u5b9e\u73b0Insert\u529f\u80fd<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;insert id=\"add\" parameterType=\"com.youkeda.comment.dataobject.UserDO\" &gt;\n    INSERT INTO user (user_name, pwd, nick_name,avatar,gmt_created,gmt_modified)\n    VALUES(#{userName}, #{pwd}, #{nickName}, #{avatar},now(),now())\n  &lt;\/insert&gt;\n<\/code><\/pre>\n\n\n\n<p>\u5c5e\u6027\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>id <\/strong>\u540cDAO\u7c7b\u7684\u65b9\u6cd5\u540d\uff0c\u540c\u4e00\u4e2axml\u5185\u662f\u8981\u552f\u4e00\u7684\u3002<\/li><li><strong>parameterType<\/strong> \u7528\u4e8e\u4f20\u9012\u53c2\u6570\u7c7b\u578b\uff0c\u4e00\u822c\u662f\u548cDAO\u5185\u5bf9\u5e94\u65b9\u6cd5\u7684\u53c2\u6570\u7c7b\u578b\u4e00\u81f4<\/li><li><span class=\"has-inline-color has-pale-pink-color\">\u4ee5\u4e0a\u4e24\u4e2a\u5c5e\u6027\u4e5f\u9002\u7528\u4e8e update\u3001delete\u3001select \u8bed\u53e5\u4e2d<\/span><\/li><\/ul>\n\n\n\n<p>\u5982\u4e4b\u524d\u7684DAO\u5185\u5199\u5165Insert\u65b9\u6cd5\uff0cXML\u4e5f\u53ef\u4ee5\u4fee\u6539\u4e3b\u952e\u8bbe\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;insert id=\"add\" parameterType=\"com.youkeda.comment.dataobject.UserDO\" useGeneratedKeys=\"true\" keyProperty=\"id\"&gt;<\/code><\/pre>\n\n\n\n<p>\u4e0eDAO\u5185 <strong>@Options<\/strong> \u6ce8\u89e3\u6548\u679c\u76f8\u540c<\/p>\n\n\n\n<p> <\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\" style=\"font-size:25px\">Update\/Delete\u8bed\u53e5\u540c\u7406<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;update id=\"update\" parameterType=\"com.youkeda.comment.dataobject.UserDO\"&gt;\n        update user set nick_name=#{nickName},gmt_modified=now() where id=#{id}\n&lt;\/update&gt;<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\"> &lt;delete id=\"delete\"&gt;\n        delete from user where id=#{id}\n &lt;\/delete&gt;<\/code><\/pre>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u56e0\u4e3a\u6211\u4eec\u5728\u5199\u5220\u9664\u8bed\u53e5\u7684DAO\u65f6\uff0c\u8bed\u53e5\u4e3a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"java\" class=\"language-java\"><strong>int<\/strong> <strong>delete<\/strong>(<strong>@Param(\"id\")<\/strong> <strong>long<\/strong> id);<\/code><\/pre>\n\n\n\n<p><strong>@Param<\/strong>\u4f20\u5165\u7684\u53c2\u6570\uff08\u8be6\u89c1\u6ce8\u89e3\u6574\u7406\uff09\u662f\u666e\u901a\u53c2\u6570\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u8fd9\u7c7b\u6570\u636e\u4f1a\u88ab\u5f53\u505a <strong>Map<\/strong> \u7c7b\u578b\u4f20\u5165\uff0c\u800c<strong>parameterType<\/strong>\u9ed8\u8ba4\u7684\u7c7b\u578b\u5c31\u662f<strong> Map<\/strong> \u56e0\u6b64\u8fd9\u91cc\u53ef\u4ee5\u628a\u7c7b\u578b\u6307\u5b9a\u7701\u7565\u3002<\/p>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\" style=\"font-size:25px\">Select\u8bed\u53e5<\/p>\n\n\n\n<p>select\u8bed\u53e5\u7531\u4e8e\u662f\u83b7\u53d6\u6570\u636e\uff0c\u4e0e\u4e0a\u9762\u51e0\u4e2a\u8bed\u53e5\u4e0d\u540c\uff0c\u6240\u4ee5\u8bed\u6cd5\u4e5f\u4e0d\u540c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;select id=\"findByUserName\" resultMap=\"userResultMap\"&gt;\n  select * from user where user_name=#{userName} limit 1\n&lt;\/select&gt;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u4f7f\u7528\u4e86<strong> resultMap<\/strong> \u5c5e\u6027\uff0c\u5b83\u7684\u503c\u4e00\u822c\u4e3aXML\u6587\u4ef6\u4e0b <strong>resultMap<\/strong> \u8282\u70b9\u7684id\u503c\uff0c\u53ef\u4ee5\u5c06\u83b7\u53d6\u7684\u6570\u636e\u901a\u8fc7 <strong>resultMap<\/strong> \u8282\u70b9\u96c6\u4f53\u6620\u5c04\u3002<\/p>\n\n\n\n<div style=\"height:27px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">if\u8bed\u53e5<\/p>\n\n\n\n<p>XML\u6a21\u5f0f\u662f\u652f\u6301\u6dfb\u52a0if\u8bed\u53e5\u7684\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;update id=\"update\" parameterType=\"com.youkeda.comment.dataobject.UserDO\"&gt;\n  update user set\n   &lt;if test=\"nickName != null\"&gt;\n    nick_name=#{nickName},gmt_modified=now()\n   &lt;\/if&gt;\n   where id=#{id}\n&lt;\/update&gt;<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2d <strong>if<\/strong> \u5b58\u5728\u5c5e\u6027 <strong>test<\/strong> \u8868\u660e <strong>if<\/strong> \u7684\u6761\u4ef6<\/p>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\" style=\"font-size:25px\">set\u8bed\u53e5<\/p>\n\n\n\n<p>\u5728\u5b9e\u9645\u4f7f\u7528if\u8bed\u53e5\u4e2d\uff0c\u53ef\u80fd\u4f1a\u4ea7\u751f\u7531\u4e8e\u6761\u4ef6\u4e0d\u6ee1\u8db3\u800c\u5bfc\u81f4SQL\u8bed\u53e5\u9519\u8bef\uff0c\u6211\u4eec\u4e00\u822c\u914d\u5408 set\u6807\u7b7e\u6765\u5b8c\u6210 update<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;update id=\"update\" parameterType=\"com.youkeda.comment.dataobject.UserDO\"&gt;\n  update user\n  &lt;set&gt;\n    &lt;if test=\"nickName != null\"&gt;\n      nick_name=#{nickName},\n    &lt;\/if&gt;\n    &lt;if test=\"avatar != null\"&gt;\n      avatar=#{avatar},\n    &lt;\/if&gt;\n    gmt_modified=now()\n  &lt;\/set&gt;\n   where id=#{id}\n&lt;\/update&gt;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u901a\u8fc7 <strong>set<\/strong> \u6807\u7b7e\u4ee3\u66ff\u4e86SQL\u8bed\u53e5\u4e2d\u7684<strong>set<\/strong> \uff0c\u4f46\u6ce8\u610f\u7684\u662f\u5176\u4e2d\u7684\u9017\u53f7\u4e0d\u80fd\u6f0f\u6389\uff0c\u4e14\u4f7f\u7528 <strong>&lt;set&gt;<\/strong> \u7cfb\u7edf\u4f1a\u81ea\u52a8\u53bb\u9664\u6700\u540e\u4e00\u4e2a\u9017\u53f7\uff0c\u800c\u4e0d\u7528\u62c5\u5fc3\u54ea\u4e00\u5217\u624d\u662f\u6700\u540e\u4e00\u4e2a\u3002<\/p>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\" style=\"font-size:25px\">if+select<\/p>\n\n\n\n<p>\u5148\u770b\u4f8b\u5b50<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;select id=\"search\" resultMap=\"userResultMap\"&gt;\n  select * from user where\n    &lt;if test=\"keyWord != null\"&gt;\n      user_name like CONCAT('%',#{keyWord},'%')\n        or nick_name like CONCAT('%',#{keyWord},'%')\n    &lt;\/if&gt;\n    &lt;if test=\"time != null\"&gt;\n      and  gmt_created &lt;![CDATA[ &gt;= ]]&gt; #{time}\n    &lt;\/if&gt;\n&lt;\/select&gt;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc <strong>&gt;=\u3001&lt;\u3001&lt;=\u3001&gt;\u3001&amp;\u3001|<\/strong> \u8fd9\u7c7b\u8868\u8fbe\u5f0f\u4f1a\u5bfc\u81f4MyBatis\u89e3\u6790\u5931\u8d25\uff0c\u6240\u4ee5\u6211\u4eec\u9700\u8981\u4f7f\u7528  <strong>&lt;![CDATA[ key ]]&gt;<\/strong> \u6765\u5305\u88f9<\/p>\n\n\n\n<div style=\"height:21px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>\u7c7b\u4f3c\u4e8e Insert\u4e2d\u7684 <strong>set<\/strong> \u53ef\u4ee5\u7528 <strong>&lt;set&gt;<\/strong> \u8bed\u53e5\u4ee3\u66ff\uff0cselect\u4e2d\u7684 <strong>where<\/strong> \u4e5f\u53ef\u4ee5\u7528 <strong>&lt;where&gt;<\/strong> \u8bed\u53e5\u4ee3\u66ff<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">   &lt;where&gt;\n      &lt;if test=\"keyWord != null\"&gt;\n          user_name like CONCAT('%',#{keyWord},'%')\n            or nick_name like CONCAT('%',#{keyWord},'%')\n      &lt;\/if&gt;\n      &lt;if test=\"time != null\"&gt;\n        and  gmt_created &lt;![CDATA[ &gt;= ]]&gt; #{time}\n      &lt;\/if&gt;\n   &lt;\/where&gt;<\/code><\/pre>\n\n\n\n<div style=\"height:100px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u5faa\u73af\u8bed\u53e5<\/p>\n\n\n\n<p>XML\u5b58\u5728\u5faa\u73af\u8bed\u53e5 <strong>&lt;foreach&gt;<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;insert id=\"batchAdd\" parameterType=\"java.util.List\" useGeneratedKeys=\"true\" keyProperty=\"id\"&gt;\n    INSERT INTO user (user_name, pwd, nick_name,avatar,gmt_created,gmt_modified)\n    VALUES\n    &lt;foreach collection=\"list\" item=\"it\" index=\"index\" separator =\",\"&gt;\n        (#{it.userName}, #{it.pwd}, #{it.nickName}, #{it.avatar},now(),now())\n    &lt;\/foreach &gt;\n&lt;\/insert&gt;<\/code><\/pre>\n\n\n\n<p>\u5c5e\u6027\uff1a<\/p>\n\n\n\n<ul class=\"list1 wp-block-list\"><li><strong>collection<\/strong> \u6307\u5b9a\u96c6\u5408\u7684\u4e0a\u4e0b\u6587\u53c2\u6570\u540d\u79f0\uff0c\u6bd4\u5982\u8fd9\u91cc\u7684list \u5bf9\u5e94 <strong>@Param(&#8220;list&#8221;)<\/strong><\/li><li><strong>item<\/strong> \u6307\u5b9a\u904d\u5386\u4e2d\u6bcf\u4e00\u4e2a\u6570\u636e\u7684\u53d8\u91cf\u7684\u6307\u4ee3\u540d\uff0c\u4e00\u8fb9\u7528it\u547d\u540d<\/li><li><strong>index<\/strong> \u96c6\u5408\u7684\u7d22\u5f15\u503c\u540d\u79f0\u6307\u5b9a<\/li><li><strong>separator<\/strong> \u904d\u5386\u6bcf\u6761\u8bb0\u5f55\u5e76\u6dfb\u52a0\u5206\u9694\u7b26<\/li><li><strong>open<\/strong> \u8868\u793a\u8282\u70b9\u5f00\u59cb\u65f6\u7684\u5206\u9694\u7b26\u5373\u6240\u6709\u6570\u636e\u524d\u9762\u7684\u7b26\u53f7<\/li><li><strong>close<\/strong> \u8868\u793a\u8282\u70b9\u7ed3\u675f\u65f6\u7684\u5206\u9694\u7b26\u5373\u6240\u6709\u6570\u636e\u4e4b\u540e\u7684\u7b26\u53f7<\/li><\/ul>\n\n\n\n<p>\u4e0a\u9762\u4ee3\u7801\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>INSERT<\/strong> <strong>INTO<\/strong> <strong>user<\/strong> (user_name, pwd, nick_name,avatar,gmt_created,gmt_modified)\n    <strong>VALUES<\/strong>\n    (?, ?, ?,?,now(),now()),\n    (?, ?, ?,?,now(),now()),\n    (?, ?, ?,?,now(),now())<\/code><\/pre>\n\n\n\n<p>MyBatis\u4f1a\u81ea\u52a8\u4f18\u5316\u6700\u540e\u4e00\u4e2a\u9017\u53f7\uff0c\u786e\u4fddSQL\u6b63\u786e\u3002<\/p>\n\n\n\n<p>\u6dfb\u52a0\u4e0aopen\u548cclose\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"xml\" class=\"language-xml\">&lt;select id=\"findByIds\" resultMap=\"userResultMap\"&gt;\n    select * from user\n    &lt;where&gt;\n        id in\n        &lt;foreach item=\"item\" index=\"index\" collection=\"ids\"\n                    open=\"(\" separator=\",\" close=\")\"&gt;\n            #{item}\n        &lt;\/foreach&gt;\n    &lt;\/where&gt;\n&lt;\/select&gt;<\/code><\/pre>\n\n\n\n<p>\u5176\u7ed3\u679c\u4e3a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\"><strong>select<\/strong> * <strong>from<\/strong> <strong>user<\/strong> <strong>where<\/strong> id <strong>in<\/strong> (?,?,?)<\/code><\/pre>\n\n\n\n<div style=\"height:37px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-vivid-red-color has-text-color has-large-font-size\">\u914d\u7f6e\u4f18\u5316<\/p>\n\n\n\n<p>\u5f53\u6570\u636eJSON\u8f93\u51fa\u65f6\uff0c\u4f1a\u5b58\u5728null\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u5ffd\u7565\u5b83\u6765\u8282\u7ea6\u6d41\u91cf\uff0c\u901a\u8fc7\u4fee\u6539\u914d\u7f6e\u6587\u4ef6 <strong>application.properties<\/strong> \u6765\u5b8c\u6210<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"properties\" class=\"language-properties\">spring.jackson.deserialization.fail-on-unknown-properties=false\nspring.jackson.default-property-inclusion=non_null<\/code><\/pre>\n\n\n\n<p>\u4e24\u4e2a\u914d\u7f6e\u7684\u4f5c\u7528\u662f\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u5141\u8bb8\u5e8f\u5217\u5316\u672a\u77e5\u5b57\u6bb5\uff0c\u53ef\u4ee5\u517c\u5bb9Java\u6a21\u578b\u548cJSON\u6570\u636e\u4e0d\u4e00\u81f4\u7684\u60c5\u51b5<\/li><li>\u5ffd\u7565null\u5b57\u6bb5<\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>XML\u6a21\u5f0f\u5f00\u53d1\u987a\u5e8f\uff1a \u521b\u5efaDO\u5bf9\u8c61 \u521b\u5efaDAO\u5bf9\u8c61\uff0c\u914d\u7f6e@Mapper\u6ce8\u89e3 \u521b\u5efaXML\u6587\u4ef6\uff0c\u5e76\u5b8c\u6210result [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-923","post","type-post","status-publish","format-standard","hentry","category-6","category-wcd"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/923"}],"collection":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/comments?post=923"}],"version-history":[{"count":14,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/923\/revisions"}],"predecessor-version":[{"id":1019,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/posts\/923\/revisions\/1019"}],"wp:attachment":[{"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/media?parent=923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/categories?post=923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fireinsect.top\/index.php\/wp-json\/wp\/v2\/tags?post=923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}