{"id":1459,"date":"2025-03-01T19:11:51","date_gmt":"2025-03-01T11:11:51","guid":{"rendered":"https:\/\/www.tqazy.com\/?p=1459"},"modified":"2025-03-05T16:20:07","modified_gmt":"2025-03-05T08:20:07","slug":"mybatisplus%ef%bc%88%e4%b8%80%ef%bc%89%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/www.tqazy.com\/?p=1459","title":{"rendered":"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8"},"content":{"rendered":"<blockquote>\n<p>\u89c6\u9891\u8bfe\u7a0b\u5730\u5740\uff1a<a href=\"https:\/\/www.bilibili.com\/video\/BV1S142197x7\" target=\"_black\">\u9ed1\u9a6c\u5546\u57ce\u9879\u76ee<\/a><\/p>\n<p>\u4e0b\u4e00\u8282\uff1a<a href=\"https:\/\/www.tqazy.com\/?p=1551\" target=\"_black\">MybatisPlus\uff08\u4e8c\uff09\u6838\u5fc3\u529f\u80fd01 \u2014 \u6761\u4ef6\u6784\u9020\u5668<\/a><br \/>\n\u672c\u8282\u5b66\u4e60MybatisPlus\uff08MP\uff09\u7684\u57fa\u672c\u4f7f\u7528\u6d41\u7a0b\uff1a<\/p>\n<ol>\n<li>\u5f15\u5165\u8d77\u6b65\u4f9d\u8d56<\/li>\n<li>\u81ea\u5b9a\u4e49Mapper\u7ee7\u627fBaseMapper<\/li>\n<li>\u5728\u5b9e\u4f53\u7c7b\u4e0a\u6dfb\u52a0\u6ce8\u89e3\u58f0\u660e \u8868\u4fe1\u606f<\/li>\n<li>\u5728application.yml\u4e2d\u6839\u636e\u9700\u8981\u6dfb\u52a0\u914d\u7f6e<\/li>\n<\/ol>\n<\/blockquote>\n<p>MybatisPlus\u5b98\u7f51\uff1a<a href=\"https:\/\/baomidou.com\" target=\"_black\"><a href=\"https:\/\/baomidou.com\">https:\/\/baomidou.com<\/a><\/a><\/p>\n<h1>\u4e00\u3001\u4f7f\u7528MybatisPlus\u6d41\u7a0b<\/h1>\n<h2>1.1 \u5f15\u5165\u8d77\u6b65\u4f9d\u8d56<\/h2>\n<p>MyBatisPlus\u5b98\u65b9\u63d0\u4f9b\u4e86starter\uff0c\u5176\u4e2d\u96c6\u6210\u4e86Mybatis\u548cMybatisPlus\u7684\u6240\u6709\u529f\u80fd\uff0c\u5e76\u4e14\u5b9e\u73b0\u4e86\u81ea\u52a8\u88c5\u914d\u6548\u679c\u3002<\/p>\n<p>\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u7528MybatisPlus\u7684starter\u4ee3\u66ffMybatis\u7684starter\uff1a<\/p>\n<pre><code class=\"language-xml\">&lt;!-- MybatisPlus --&gt;\n&lt;dependency&gt;\n  &lt;groupId&gt;com.baomidou&lt;\/groupId&gt;\n  &lt;artifactId&gt;mybatis-plus-boot-starter&lt;\/artifactId&gt;\n  &lt;version&gt;3.5.3.1&lt;\/version&gt;\n&lt;\/dependency&gt;<\/code><\/pre>\n<div style=\"height:1.5em\"><\/div>\n<h2>1.2 \u5b9a\u4e49Mapper<\/h2>\n<p>\u81ea\u5b9a\u4e49\u7684Mapper\u7ee7\u627fMybatisPlus\u63d0\u4f9b\u7684BaseMapper\u63a5\u53e3\uff1a<\/p>\n<pre><code class=\"language-java\">public interface UserMapper extends BaseMapper&lt;User&gt; {\n\n}<\/code><\/pre>\n<p>BaseMapper\u63a5\u53e3\u65b0\u589e\u4e86\u5f88\u591aCRUD\u7684\u63a5\u53e3\uff1a<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1.5em\"><\/div>\n<h2>1.3 \u66ff\u6362Mybatis\u6848\u4f8b<\/h2>\n<h3>1.3.1 \u4f7f\u7528Mybatis\u7684\u5199\u6cd5<\/h3>\n<p><strong>1\u3001UserMapper.java<\/strong><\/p>\n<pre><code class=\"language-java\">package com.itheima.mp.mapper;\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport com.itheima.mp.domain.po.User;\nimport org.apache.ibatis.annotations.Param;\nimport java.util.List;\n\npublic interface UserMapper extends BaseMapper&lt;User&gt; {\n\n    void saveUser(User user);\n\n    void deleteUser(Long id);\n\n    void updateUser(User user);\n\n    User queryUserById(@Param(&quot;id&quot;) Long id);\n\n    List&lt;User&gt; queryUserByIds(@Param(&quot;ids&quot;) List&lt;Long&gt; ids);\n}\n<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><strong>2\u3001UserMapper.xml<\/strong><\/p>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;!DOCTYPE mapper PUBLIC &quot;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&quot; &quot;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&quot;&gt;\n&lt;mapper namespace=&quot;com.itheima.mp.mapper.UserMapper&quot;&gt;\n    &lt;insert id=&quot;saveUser&quot; parameterType=&quot;com.itheima.mp.domain.po.User&quot;&gt;\n        INSERT INTO `user` (`id`, `username`, `password`, `phone`, `info`, `balance`)\n        VALUES\n        (#{id}, #{username}, #{password}, #{phone}, #{info}, #{balance});\n    &lt;\/insert&gt;\n    &lt;update id=&quot;updateUser&quot; parameterType=&quot;com.itheima.mp.domain.po.User&quot;&gt;\n        UPDATE `user`\n        &lt;set&gt;\n            &lt;if test=&quot;username != null&quot;&gt;\n                `username`=#{username}\n            &lt;\/if&gt;\n            &lt;if test=&quot;password != null&quot;&gt;\n                `password`=#{password}\n            &lt;\/if&gt;\n            &lt;if test=&quot;phone != null&quot;&gt;\n                `phone`=#{phone}\n            &lt;\/if&gt;\n            &lt;if test=&quot;info != null&quot;&gt;\n                `info`=#{info}\n            &lt;\/if&gt;\n            &lt;if test=&quot;status != null&quot;&gt;\n                `status`=#{status}\n            &lt;\/if&gt;\n            &lt;if test=&quot;balance != null&quot;&gt;\n                `balance`=#{balance}\n            &lt;\/if&gt;\n        &lt;\/set&gt;\n        WHERE `id`=#{id};\n    &lt;\/update&gt;\n    &lt;delete id=&quot;deleteUser&quot; parameterType=&quot;com.itheima.mp.domain.po.User&quot;&gt;\n        DELETE FROM user WHERE id = #{id}\n    &lt;\/delete&gt;\n\n    &lt;select id=&quot;queryUserById&quot; resultType=&quot;com.itheima.mp.domain.po.User&quot;&gt;\n        SELECT *\n        FROM user\n        WHERE id = #{id}\n    &lt;\/select&gt;\n\n    &lt;select id=&quot;queryUserByIds&quot; resultType=&quot;com.itheima.mp.domain.po.User&quot;&gt;\n        SELECT *\n        FROM user\n        &lt;if test=&quot;ids != null&quot;&gt;\n            WHERE id IN\n            &lt;foreach collection=&quot;ids&quot; open=&quot;(&quot; close=&quot;)&quot; item=&quot;id&quot; separator=&quot;,&quot;&gt;\n                #{id}\n            &lt;\/foreach&gt;\n        &lt;\/if&gt;\n        LIMIT 10\n    &lt;\/select&gt;\n\n&lt;\/mapper&gt;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><strong>3\u3001\u6d4b\u8bd5<\/strong><\/p>\n<pre><code class=\"language-java\">    @Test\n    void testQueryByIds() {\n        List&lt;User&gt; users = userMapper.queryUserByIds(List.of(1L, 2L, 3L, 4L));\n        users.forEach(System.out::println);\n    }<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104944330.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104944330.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1.5em\"><\/div>\n<h3>1.3.2 \u4f7f\u7528MybatisPlus\u7684\u5199\u6cd5<\/h3>\n<p><strong>1\u3001UserMapper.java<\/strong><\/p>\n<pre><code class=\"language-java\">package com.itheima.mp.mapper;\n\nimport com.baomidou.mybatisplus.core.mapper.BaseMapper;\nimport com.itheima.mp.domain.po.User;\n\npublic interface UserMapper extends BaseMapper&lt;User&gt; {\n\n}<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><strong>2\u3001UserMapper.xml<\/strong><\/p>\n<pre><code class=\"language-xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\n&lt;!DOCTYPE mapper PUBLIC &quot;-\/\/mybatis.org\/\/DTD Mapper 3.0\/\/EN&quot; &quot;http:\/\/mybatis.org\/dtd\/mybatis-3-mapper.dtd&quot;&gt;\n&lt;mapper namespace=&quot;com.itheima.mp.mapper.UserMapper&quot;&gt;\n\n&lt;\/mapper&gt;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><strong>3\u3001\u6d4b\u8bd5<\/strong><\/p>\n<pre><code class=\"language-java\">    @Test\n    void testQueryByIds() {\n        List&lt;User&gt; users = userMapper.selectBatchIds(List.of(1L, 2L, 3L, 4L));\n        users.forEach(System.out::println);\n    }<\/code><\/pre>\n<p>\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301105153440.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301105153440.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>\u8fd0\u884c\u7ed3\u679c\u76f8\u540c\u3002<\/p>\n<div style=\"height:1.5em\"><\/div>\n<h1>\u4e8c\u3001\u5e38\u7528\u6ce8\u89e3<\/h1>\n<h2>2.1 MyBatisPlus\u5b9e\u73b0CRUD\u7684\u539f\u7406<\/h2>\n<p>MyBatisPlus\u901a\u8fc7\u626b\u63cf\u5b9e\u4f53\u7c7b\uff0c\u5e76\u57fa\u4e8e\u53cd\u5c04\u83b7\u53d6\u5b9e\u4f53\u7c7b\u4fe1\u606f\u4f5c\u4e3a\u6570\u636e\u5e93\u8868\u4fe1\u606f\u3002<\/p>\n<p>\u547d\u540d\u539f\u5219\uff08\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e\uff09\uff1a<\/p>\n<ul>\n<li>\u7c7b\u540d\u9a7c\u5cf0\u8f6c\u4e0b\u5212\u7ebf\u4f5c\u4e3a\u8868\u540d<\/li>\n<li>\u540d\u4e3aid\u7684\u5b57\u6bb5\u4f5c\u4e3a\u4e3b\u952e<\/li>\n<li>\u53d8\u91cf\u540d\u9a7c\u5cf0\u8f6c\u4e0b\u5212\u7ebf\u4f5c\u4e3a\u8868\u7684\u5b57\u6bb5\u540d<\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301105217610.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301105217610.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<div style=\"height:1.5em\"><\/div>\n<h2>2.2 \u5e38\u89c1\u6ce8\u89e3<\/h2>\n<p>MybatisPlus\u4e2d\u6bd4\u8f83\u5e38\u7528\u7684\u51e0\u4e2a\u6ce8\u89e3\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><code>@TableName<\/code>\uff1a\u7528\u6765\u6307\u5b9a\u8868\u540d<\/li>\n<li><code>@TableId<\/code>\uff1a\u7528\u6765\u6307\u5b9a\u8868\u4e2d\u7684\u4e3b\u952e\u5b57\u6bb5\u4fe1\u606f<\/li>\n<li><code>@TableField<\/code>\uff1a\u7528\u6765\u6307\u5b9a\u8868\u4e2d\u7684\u666e\u901a\u5b57\u6bb5\u4fe1\u606f<\/li>\n<\/ul>\n<div style=\"height:1.5em\"><\/div>\n<h3>2.2.1 <code>@TableName<\/code><\/h3>\n<p>\u7528\u4e8e\u7ed9\u7c7b\u6307\u5b9a\u8868\u540d\u3002<\/p>\n<p>\u7528\u6cd5\uff1a<\/p>\n<pre><code class=\"language-java\">@TableName(&quot;tb_user&quot;)\npublic class User {\n}<\/code><\/pre>\n<div style=\"height:1.5em\"><\/div>\n<h3>2.2.2 <code>@TableId<\/code><\/h3>\n<p>\u4f7f\u7528\u65b9\u6cd5\uff1a<\/p>\n<pre><code class=\"language-java\">@TableId(&quot;id&quot;)\nprivate Long userId;<\/code><\/pre>\n<p>\u6216\u8005\uff1a<\/p>\n<pre><code class=\"language-java\">@TableId(value=&quot;id&quot;, type=IdType.AUTO)\nprivate Long userId;<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p><code>IdType<\/code>\u679a\u4e3e\uff1a<\/p>\n<ul>\n<li><code>AUTO<\/code>\uff1a\u6570\u636e\u5e93\u81ea\u589e\u957f<\/li>\n<li><code>INPUT<\/code>\uff1a\u901a\u8fc7set\u65b9\u6cd5\u81ea\u884c\u8f93\u5165<\/li>\n<li><code>ASSIGN_ID<\/code>\uff1a\u5206\u914dID\u3002(\u9ed8\u8ba4\u503c)\n<ul>\n<li>\u63a5\u53e3<code>IdentifierGenerator<\/code>\u7684\u65b9\u6cd5<code>nextId<\/code>\u6765\u751f\u6210<code>id<\/code>\uff0c\u9ed8\u8ba4\u5b9e\u73b0\u7c7b\u4e3a<code>DefaultIdentifierGenerator<\/code>\u96ea\u82b1\u7b97\u6cd5<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div style=\"height:1.5em\"><\/div>\n<h3>2.2.3 <code>@TableField<\/code><\/h3>\n<p>\u4f7f\u7528@TableField\u7684\u5e38\u89c1\u573a\u666f\uff1a<\/p>\n<ul>\n<li>\n<p>\u6210\u5458\u53d8\u91cf\u540d\u4e0e\u6570\u636e\u5e93\u5b57\u6bb5\u540d\u4e0d\u4e00\u81f4<\/p>\n<ul>\n<li>\n<pre><code class=\"language-java\">@TableField(\"username\")\nprivate String name;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6210\u5458\u53d8\u91cf\u540d\u4ee5is\u5f00\u5934\uff0c\u4e14\u662f\u5e03\u5c14\u503c\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0d\u5904\u7406\uff0cMP\u4f1a\u81ea\u52a8\u53bb\u6389is<\/p>\n<ul>\n<li>\n<pre><code class=\"language-java\">@TableField(\"is_married\")\nprivate Boolean isMarried;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6210\u5458\u53d8\u91cf\u540d\u4e0e\u6570\u636e\u5e93\u5173\u952e\u5b57\u51b2\u7a81\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0d\u5904\u7406\uff0c\u6267\u884cSQL\u65f6\u6570\u636e\u5e93\u4f1a\u62a5\u9519<\/p>\n<ul>\n<li>\n<pre><code class=\"language-java\">@TableField(\"`<code>order<\/code>`\")\nprivate Integer order;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6210\u5458\u53d8\u91cf\u4e0d\u662f\u6570\u636e\u5e93\u5b57\u6bb5\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0d\u5904\u7406\uff0cMP\u4f1a\u8bc6\u522b\u9519\u8bef<\/p>\n<ul>\n<li>\n<pre><code class=\"language-java\">@TableField(exist = false)\nprivate String address;<\/code><\/pre>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div style=\"height:1.5em\"><\/div>\n<h3>2.2.4 \u793a\u4f8b<\/h3>\n<p>\u5982\u679c\u5b9e\u4f53\uff08Java\u7684\u7c7b\uff09\u5b57\u6bb5\u540d\u4e0e\u8868\uff08MySQL\uff09\u7684\u5217\u540d\u4e0d\u7b26\u5408\u4e0a\u9762\u7684\u547d\u540d\u539f\u5219\uff0c\u5219\u4f7f\u7528\u8fd9\u4e2a\u6ce8\u89e3\u8fdb\u884c\u8f85\u52a9\u3002<\/p>\n<p>\u4f8b\u5982\uff1a<\/p>\n<p>\u82e5\u6570\u636e\u8868\u5982\u4e0b\uff1a<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301105308562.png'><img class=\"lazyload lazyload-style-6\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301105308562.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" \/><\/div><\/p>\n<p>\u4f46\u662fJava\u7c7b\u5374\u662f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-java\">public class User {\n\n    private Long userId;\n\n    private String name;\n\n    private Boolean isMarried;\n\n    private Integer order;\n\n    private String address;\n}<\/code><\/pre>\n<div style=\"height:1em\"><\/div>\n<p>\u90a3\u4e48\u5c31\u9700\u8981\u4f7f\u7528\u8fd9\u4e9b\u6ce8\u89e3\u8fdb\u884c\u8f85\u52a9\u4e86\uff1a<\/p>\n<pre><code class=\"language-java\">@TableName(&quot;tb_user&quot;)\npublic class User {\n    @TableId(value=&quot;id&quot;, type=IdType.AUTO)\n    private Long userId;\n\n    @TableField(&quot;username&quot;)\n    private String name;\n\n    @TableField(&quot;is_married&quot;)\n    private Boolean isMarried;\n\n    @TableField(&quot;`order`&quot;)\n    private Integer order;\n\n    @TableField(exist = false)\n    private String address;\n}<\/code><\/pre>\n<div style=\"height:1.5em\"><\/div>\n<h1>\u4e09\u3001\u5e38\u7528\u914d\u7f6e<\/h1>\n<p>MyBatisPlus\u7684\u914d\u7f6e\u9879\u7ee7\u627f\u4e86MyBatis\u539f\u751f\u914d\u7f6e\u548c\u4e00\u4e9b\u81ea\u5df1\u7279\u6709\u7684\u914d\u7f6e\u3002<\/p>\n<p>\u4f8b\u5982\uff1a(\u7528\u4e8eapplication.yml\u6216\u88ab\u5176\u5f15\u7528\u7684yml\u4e2d)<\/p>\n<pre><code class=\"language-yaml\">mybatis-plus:\n  type-aliases-package: com.itheima.mp.domain.po # \u522b\u540d\u626b\u63cf\u5305\n  mapper-locations: &quot;classpath*:\/mapper\/**\/*.xml&quot; # Mapper.xml\u6587\u4ef6\u5730\u5740\uff0c\u9ed8\u8ba4\u503c\n  configuration:\n    map-underscore-to-camel-case: true # \u662f\u5426\u5f00\u542f\u4e0b\u5212\u7ebf\u548c\u9a7c\u5cf0\u7684\u6620\u5c04\n    cache-enabled: false # \u662f\u5426\u5f00\u542f\u4e8c\u7ea7\u7f13\u5b58\n  global-config: # \uff08MP\u7279\u6709\uff09\u5168\u5c40\u914d\u7f6e\n    db-config: # \u6570\u636e\u5e93\u914d\u7f6e\n      id-type: assign_id # id\u4e3a\u96ea\u82b1\u7b97\u6cd5\u751f\u6210\uff0c\u8fd8\u53ef\u4ee5\uff1aauto\n      update-strategy: not_null # \u66f4\u65b0\u7b56\u7565\uff1a\u53ea\u66f4\u65b0\u975e\u7a7a\u5b57\u6bb5<\/code><\/pre>\n<p>\u5177\u4f53\u53ef\u53c2\u8003\u5b98\u65b9\u6587\u6863\uff1a<a href=\"https:\/\/baomidou.com\/reference\/\" target=\"_black\">\u4f7f\u7528\u914d\u7f6e | MyBatis-Plus<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u8282\u5b66\u4e60MybatisPlus\uff08MP\uff09\u7684\u57fa\u672c\u4f7f\u7528\u6d41\u7a0b\uff1a\u5f15\u5165\u8d77\u6b65\u4f9d\u8d56\u3001\u7ee7\u627fBaseMapper\u3001\u5e38\u7528\u6ce8\u89e3\u3001\u5e38\u7528\u914d\u7f6e<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[102,110],"tags":[111],"class_list":["post-1459","post","type-post","status-publish","format-standard","hentry","category-spring_boot","category-heima_mall","tag-mybatisplus"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tqazy.com\/?p=1459\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"\u672c\u8282\u5b66\u4e60MybatisPlus\uff08MP\uff09\u7684\u57fa\u672c\u4f7f\u7528\u6d41\u7a0b\uff1a\u5f15\u5165\u8d77\u6b65\u4f9d\u8d56\u3001\u7ee7\u627fBaseMapper\u3001\u5e38\u7528\u6ce8\u89e3\u3001\u5e38\u7528\u914d\u7f6e\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tqazy.com\/?p=1459\" \/>\n<meta property=\"og:site_name\" content=\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2025-03-01T11:11:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-05T08:20:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png\" \/>\n<meta name=\"author\" content=\"\u9676\u5176\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u9676\u5176\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1459\"},\"author\":{\"name\":\"\u9676\u5176\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"headline\":\"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8\",\"datePublished\":\"2025-03-01T11:11:51+00:00\",\"dateModified\":\"2025-03-05T08:20:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1459\"},\"wordCount\":60,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"image\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#primaryimage\"},\"thumbnailUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png\",\"keywords\":[\"MybatisPlus\"],\"articleSection\":[\"Spring Boot\",\"\u9ed1\u9a6c\u5546\u57ce\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tqazy.com\/?p=1459#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1459\",\"url\":\"https:\/\/www.tqazy.com\/?p=1459\",\"name\":\"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#primaryimage\"},\"thumbnailUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png\",\"datePublished\":\"2025-03-01T11:11:51+00:00\",\"dateModified\":\"2025-03-05T08:20:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tqazy.com\/?p=1459\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#primaryimage\",\"url\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png\",\"contentUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1459#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.tqazy.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tqazy.com\/#website\",\"url\":\"https:\/\/www.tqazy.com\/\",\"name\":\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"description\":\"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765\",\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"alternateName\":\"TaoQi's Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tqazy.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\",\"name\":\"\u9676\u5176\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"contentUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"width\":940,\"height\":940,\"caption\":\"\u9676\u5176\"},\"logo\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\"},\"description\":\"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458\",\"sameAs\":[\"https:\/\/www.tqazy.com\"],\"url\":\"https:\/\/www.tqazy.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tqazy.com\/?p=1459","og_locale":"zh_CN","og_type":"article","og_title":"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","og_description":"\u672c\u8282\u5b66\u4e60MybatisPlus\uff08MP\uff09\u7684\u57fa\u672c\u4f7f\u7528\u6d41\u7a0b\uff1a\u5f15\u5165\u8d77\u6b65\u4f9d\u8d56\u3001\u7ee7\u627fBaseMapper\u3001\u5e38\u7528\u6ce8\u89e3\u3001\u5e38\u7528\u914d\u7f6e","og_url":"https:\/\/www.tqazy.com\/?p=1459","og_site_name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","article_published_time":"2025-03-01T11:11:51+00:00","article_modified_time":"2025-03-05T08:20:07+00:00","og_image":[{"url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png","type":"","width":"","height":""}],"author":"\u9676\u5176","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u9676\u5176","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tqazy.com\/?p=1459#article","isPartOf":{"@id":"https:\/\/www.tqazy.com\/?p=1459"},"author":{"name":"\u9676\u5176","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"headline":"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8","datePublished":"2025-03-01T11:11:51+00:00","dateModified":"2025-03-05T08:20:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tqazy.com\/?p=1459"},"wordCount":60,"commentCount":0,"publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"image":{"@id":"https:\/\/www.tqazy.com\/?p=1459#primaryimage"},"thumbnailUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png","keywords":["MybatisPlus"],"articleSection":["Spring Boot","\u9ed1\u9a6c\u5546\u57ce"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tqazy.com\/?p=1459#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tqazy.com\/?p=1459","url":"https:\/\/www.tqazy.com\/?p=1459","name":"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.tqazy.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.tqazy.com\/?p=1459#primaryimage"},"image":{"@id":"https:\/\/www.tqazy.com\/?p=1459#primaryimage"},"thumbnailUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png","datePublished":"2025-03-01T11:11:51+00:00","dateModified":"2025-03-05T08:20:07+00:00","breadcrumb":{"@id":"https:\/\/www.tqazy.com\/?p=1459#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tqazy.com\/?p=1459"]}]},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.tqazy.com\/?p=1459#primaryimage","url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png","contentUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2025\/03\/20250301104747123.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.tqazy.com\/?p=1459#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.tqazy.com\/"},{"@type":"ListItem","position":2,"name":"MybatisPlus\uff08\u4e00\uff09\u5feb\u901f\u5165\u95e8"}]},{"@type":"WebSite","@id":"https:\/\/www.tqazy.com\/#website","url":"https:\/\/www.tqazy.com\/","name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","description":"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765","publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"alternateName":"TaoQi's Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tqazy.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e","name":"\u9676\u5176","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/","url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","contentUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","width":940,"height":940,"caption":"\u9676\u5176"},"logo":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/"},"description":"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458","sameAs":["https:\/\/www.tqazy.com"],"url":"https:\/\/www.tqazy.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/1459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1459"}],"version-history":[{"count":11,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/1459\/revisions"}],"predecessor-version":[{"id":1567,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/1459\/revisions\/1567"}],"wp:attachment":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}