{"id":598,"date":"2026-05-14T17:04:58","date_gmt":"2026-05-14T09:04:58","guid":{"rendered":"https:\/\/hhh3m.top\/?p=598"},"modified":"2026-05-14T17:18:39","modified_gmt":"2026-05-14T09:18:39","slug":"crud%e5%ad%a6%e4%b9%a0-querywrapper","status":"publish","type":"post","link":"https:\/\/hhh3m.top\/index.php\/2026\/05\/14\/crud%e5%ad%a6%e4%b9%a0-querywrapper\/","title":{"rendered":"CRUD\u5b66\u4e60-QueryWrapper"},"content":{"rendered":"\n<p>\u5b9e\u4e60\u65f6\u53eb\u6211\u7ed9\u9700\u6c42\u7ba1\u7406\u52a0\u4e2a\u67e5\u8be2\u6761\u4ef6 \uff0c\u7b2c\u4e00\u6b65\u5148\u6253\u7b97\u770b\u770b\u9700\u6c42\u7ba1\u7406\u7684controller\u91cc\u7684\u76f8\u5173api\u5bf9\u5e94service\u7684\u54ea\u4e2a\u65b9\u6cd5\uff0c\u7ed3\u679c\u4e00\u770bcontroller\u91cc\u4e00\u4e2a\u63a5\u53e3\u5199\u4e00\u767e\u591a\u884c\u800c\u4e14\u6ca1\u6709\u6307\u5411service\u3002\u3002\u3002<\/p>\n\n\n\n<p>\u770b\u4ee3\u7801\u5b66\u5230\u4e86QueryWrapper\u6784\u9020\u65b9\u6cd5\uff0c\u662fMyBatis-Plus \u63d0\u4f9b\u7684<strong>\u6761\u4ef6\u6784\u9020\u5668<\/strong>\uff0c\u4ee5\u9762\u5411\u5bf9\u8c61\u65b9\u5f0f\u52a8\u6001\u7ec4\u88c5 SQL \u67e5\u8be2\u6761\u4ef6\uff0c\u65e0\u9700\u624b\u5199 SQL \u4e0e XML \u8bed\u53e5\uff0c\u53ef\u5feb\u901f\u5b9e\u73b0\u7b49\u503c\u3001\u6a21\u7cca\u3001\u8303\u56f4\u3001\u6392\u5e8f\u7b49\u5e38\u7528\u67e5\u8be2\u903b\u8f91\uff0c\u7b80\u5316\u5355\u8868\u6570\u636e\u67e5\u8be2\u5f00\u53d1\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>QueryWrapper&lt;Dict&gt; wrapper = new QueryWrapper&lt;&gt;();\/\/Dick\u6307\u5b9a\u5bf9\u8c61\u540d\nwrapper.eq(\"status\",1);        \/\/ \u8c03\u7528eq\u65b9\u6cd5\uff08equal\u7b80\u5199\uff09\u610f\u601d\u662fstatus \u5b57\u6bb5 = 1<\/code><\/pre>\n\n\n\n<p>\u76f8\u5f53\u4e8eSQL\u8bed\u53e5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM t_dict WHERE status = 1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">QueryWrapper\u81ea\u5e26\u67e5\u8be2\u65b9\u6cd5<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b49\u503c\u67e5\u8be2<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>eq(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u7b49\u4e8e <code>=<\/code><\/li>\n\n\n\n<li><code>ne(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u4e0d\u7b49\u4e8e <code>!=<\/code><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u8303\u56f4\u67e5\u8be2<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>gt(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u5927\u4e8e <code>&gt;<\/code><\/li>\n\n\n\n<li><code>ge(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u5927\u4e8e\u7b49\u4e8e <code>&gt;=<\/code><\/li>\n\n\n\n<li><code>lt(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u5c0f\u4e8e <code>&lt;<\/code><\/li>\n\n\n\n<li><code>le(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u5c0f\u4e8e\u7b49\u4e8e <code>&lt;=<\/code><\/li>\n\n\n\n<li><code>between(\u5b57\u6bb5,\u5de6,\u53f3)<\/code>\uff1a\u533a\u95f4\u8303\u56f4<\/li>\n\n\n\n<li><code>notBetween(\u5b57\u6bb5,\u5de6,\u53f3)<\/code>\uff1a\u4e0d\u5728\u533a\u95f4<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u6a21\u7cca\u67e5\u8be2<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>like(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u5de6\u53f3\u6a21\u7cca <code>%\u503c%<\/code><\/li>\n\n\n\n<li><code>likeLeft(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u5de6\u6a21\u7cca <code>%\u503c<\/code><\/li>\n\n\n\n<li><code>likeRight(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u53f3\u6a21\u7cca <code>\u503c%<\/code><\/li>\n\n\n\n<li><code>notLike(\u5b57\u6bb5,\u503c)<\/code>\uff1a\u4e0d\u5305\u542b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u7a7a\u503c\u5224\u65ad<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>isNull(\u5b57\u6bb5)<\/code>\uff1a\u5b57\u6bb5\u4e3a null<\/li>\n\n\n\n<li><code>isNotNull(\u5b57\u6bb5)<\/code>\uff1a\u5b57\u6bb5\u4e0d\u4e3a null<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5305\u542b\u5339\u914d<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>in(\u5b57\u6bb5,\u96c6\u5408\/\u6570\u7ec4)<\/code>\uff1a\u5b57\u6bb5\u5728\u6307\u5b9a\u8303\u56f4\u5185<\/li>\n\n\n\n<li><code>notIn(\u5b57\u6bb5,\u96c6\u5408\/\u6570\u7ec4)<\/code>\uff1a\u4e0d\u5728\u6307\u5b9a\u8303\u56f4<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u6392\u5e8f<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>orderByAsc(\u5b57\u6bb5)<\/code>\uff1a\u5347\u5e8f<\/li>\n\n\n\n<li><code>orderByDesc(\u5b57\u6bb5)<\/code>\uff1a\u964d\u5e8f<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u903b\u8f91\u62fc\u63a5<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>and()<\/code>\uff1a\u5e76\u4e14<\/li>\n\n\n\n<li><code>or()<\/code>\uff1a\u6216\u8005<\/li>\n<\/ul>\n\n\n\n<p>\u4f8b\u5982\u5bf9\u4e8e\u4e4b\u524d\u7684\u5b66\u751f\u7ba1\u7406crud\uff0c\u53ea\u6709\u81ea\u5e26\u7684\u6839\u636eid\u7684\u67e5\u8be2\uff0c\u5229\u7528queryMapper\u53ef\u4ee5\u5b9e\u73b0\u5176\u4ed6\u6761\u4ef6\u67e5\u8be2<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@GetMapping(\"\/student\/search\")\npublic List&lt;Student> list(\n        @RequestParam(required = false) String name,\n        @RequestParam(required = false) Integer age\n) {\n    \/\/\u521b\u5efa\u6761\u4ef6\u6784\u9020\u5668\n    QueryWrapper&lt;Student> wrapper = new QueryWrapper&lt;>();\n\n    \/\/\u62fc\u63a5\u6761\u4ef6\uff08\u52a8\u6001\u6761\u4ef6\uff0c\u6709\u503c\u624d\u62fc\u63a5\uff09\n    wrapper.like(StringUtils.hasText(name), \"name\", name);   \/\/ \u59d3\u540d\u6a21\u7cca\n    wrapper.ge(age != null, \"age\", age);                    \/\/ \u5e74\u9f84 >= \u4f20\u5165\u503c\n    wrapper.orderByDesc(\"age\");                              \/\/ \u6309\u5e74\u9f84\u5012\u5e8f\n\n    \/\/\u76f4\u63a5\u67e5\u8be2\u8fd4\u56de\n    return studentMapper.selectList(wrapper);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u4e60\u65f6\u53eb\u6211\u7ed9\u9700\u6c42\u7ba1\u7406\u52a0\u4e2a\u67e5\u8be2\u6761\u4ef6 \uff0c\u7b2c\u4e00\u6b65\u5148\u6253\u7b97\u770b\u770b\u9700\u6c42\u7ba1\u7406\u7684controller\u91cc\u7684\u76f8\u5173api\u5bf9\u5e94servi [&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],"tags":[],"class_list":["post-598","post","type-post","status-publish","format-standard","hentry","category-misc"],"_links":{"self":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts\/598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/comments?post=598"}],"version-history":[{"count":4,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts\/598\/revisions"}],"predecessor-version":[{"id":603,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/posts\/598\/revisions\/603"}],"wp:attachment":[{"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/media?parent=598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/categories?post=598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hhh3m.top\/index.php\/wp-json\/wp\/v2\/tags?post=598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}