{"id":14300,"date":"2023-12-04T01:21:26","date_gmt":"2023-12-03T17:21:26","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=14300"},"modified":"2023-12-04T01:21:59","modified_gmt":"2023-12-03T17:21:59","slug":"mybatis-chang-yong-zhu-jie","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/12\/04\/mybatis-chang-yong-zhu-jie\/","title":{"rendered":"MyBatis \u5e38\u7528\u6ce8\u89e3\uff1f"},"content":{"rendered":"<p>MyBatis \u4e2d\u5e38\u7528\u7684\u6ce8\u89e3\u5305\u62ec\uff1a<\/p>\n<h3>1. <code>@Select<\/code>\u3001<code>@Insert<\/code>\u3001<code>@Update<\/code>\u3001<code>@Delete<\/code>\uff1a<\/h3>\n<p>\u7528\u4e8e\u5728\u63a5\u53e3\u65b9\u6cd5\u4e0a\u76f4\u63a5\u5b9a\u4e49 SQL \u8bed\u53e5\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-java  line-numbers\">@Select(\"SELECT * FROM users WHERE id = #{id}\")\nUser getUserById(int id);\n\n@Insert(\"INSERT INTO users(name, age) VALUES(#{name}, #{age})\")\nvoid insertUser(User user);\n\n@Update(\"UPDATE users SET name = #{name} WHERE id = #{id}\")\nvoid updateUser(User user);\n\n@Delete(\"DELETE FROM users WHERE id = #{id}\")\nvoid deleteUserById(int id);\n<\/code><\/pre>\n<h3>2. <code>@Results<\/code>\u3001<code>@Result<\/code>\uff1a<\/h3>\n<p>\u7528\u4e8e\u5728\u63a5\u53e3\u65b9\u6cd5\u4e0a\u5b9a\u4e49\u7ed3\u679c\u96c6\u7684\u6620\u5c04\u5173\u7cfb\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-java  line-numbers\">@Results({\n    @Result(property = \"userId\", column = \"id\"),\n    @Result(property = \"userName\", column = \"name\")\n})\n@Select(\"SELECT id, name FROM users WHERE id = #{id}\")\nUser getUserById(int id);\n<\/code><\/pre>\n<h3>3. <code>@Param<\/code>\uff1a<\/h3>\n<p>\u6307\u5b9a\u65b9\u6cd5\u53c2\u6570\u5728 SQL \u4e2d\u7684\u5bf9\u5e94\u5173\u7cfb\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-java  line-numbers\">@Select(\"SELECT * FROM users WHERE id = #{id} AND name = #{name}\")\nUser getUserByIdAndName(@Param(\"id\") int id, @Param(\"name\") String name);\n<\/code><\/pre>\n<h3>4. <code>@Options<\/code>\uff1a<\/h3>\n<p>\u7528\u4e8e\u8bbe\u7f6e\u4e00\u4e9b\u9009\u9879\uff0c\u6bd4\u5982\u662f\u5426\u8fd4\u56de\u81ea\u52a8\u751f\u6210\u7684\u4e3b\u952e\u503c\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre><code class=\"language-java  line-numbers\">@Insert(\"INSERT INTO users(name, age) VALUES(#{name}, #{age})\")\n@Options(useGeneratedKeys = true, keyProperty = \"id\")\nvoid insertUser(User user);\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u6ce8\u89e3\u63d0\u4f9b\u4e86\u5728\u63a5\u53e3\u65b9\u6cd5\u4e0a\u76f4\u63a5\u5b9a\u4e49 SQL \u8bed\u53e5\u3001\u7ed3\u679c\u96c6\u6620\u5c04\u3001\u53c2\u6570\u4f20\u9012\u7b49\u529f\u80fd\uff0c\u4f7f\u5f97 MyBatis \u5f00\u53d1\u66f4\u52a0\u4fbf\u6377\u548c\u7075\u6d3b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MyBatis \u4e2d\u5e38\u7528\u7684\u6ce8\u89e3\u5305\u62ec\uff1a 1. @Select\u3001@Insert\u3001@Update\u3001@Delete\uff1a \u7528 [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[113],"tags":[],"class_list":["post-14300","post","type-post","status-publish","format-standard","hentry","category-mybatis"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/14300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=14300"}],"version-history":[{"count":1,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/14300\/revisions"}],"predecessor-version":[{"id":14301,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/14300\/revisions\/14301"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=14300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=14300"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=14300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}