vue springboot mybatis实现自定义条件检索功能

文章目录

概要

部门需求,要求检索可以实现,自选检索字段、检索条件、参数。并且在页面不要冗余显示。

整体流程

1.前端效果

前端部分通过组件实现,下拉选项 由字典提供。

2.后端

这一部分由mybatis拼接后,进行sql查询

技术细节

2.1检索条件的映射

java 复制代码
    <!-- 字段映射片段  -->
    <sql id="searchCondition">
        <choose>
            <when test="${searchKey} == 'code'"> //此处就是对应的字段
                <include refid="buildCondition">
                    <property name="column" value="code"/>
                    <property name="searchType" value="${searchType}"/>//选择的参数
                    <property name="inputA" value="${inputA}"/>//检索的数值
                    <property name="inputB" value="${inputB}"/>//检索的数值多选
                </include>
            </when>
        </choose>
    </sql>

2.2 可复用的条件构建片段

java 复制代码
    <!-- 可复用的条件构建片段 -->
    <sql id="buildCondition">
        <choose>
            <when test="${searchType} == 'dayu'">
                and ${column} &gt; #{${inputA}}
            </when>
            <when test="${searchType} == 'dayudengyu'">
                and ${column} &gt;= #{${inputA}}
            </when>
            <when test="${searchType} == 'isnull'">
                and ${column} is null
            </when>

            <when test="${searchType} == 'isnotnull'">
                and ${column}  is not null
            </when>
        </choose>
    </sql>

2.3检索语句的使用

java 复制代码
  <select id="selectList" parameterType="listParameter" resultMap="listParameterResult">
  select * from 
   <where>
                   <include refid="searchCondition"> //有多个就对应创建多个
                    <property name="searchKey" value="params.searchKey1"/>//我是用数字区分
                    <property name="searchType" value="params.searchType1"/>
                    <property name="inputA" value="params.searchInputA1"/>
                    <property name="inputB" value="params.searchInputB1"/>
                </include>
                 </where>
                    </select>
相关推荐
Java陈序员5 小时前
企业级!一个基于 Java 开发的开源 AI 应用开发平台!
spring boot·agent·mcp
DarkLONGLOVE7 小时前
快速上手 Pinia!Vue3 极简状态管理使用教程
javascript·vue.js
宸翰8 小时前
解决 uni-app App 端 vue-i18n 占位符丢失:封装跨端可用的 tf 格式化方法
前端·vue.js·uni-app
用户21366100357212 小时前
VueRouter进阶-动态路由与嵌套路由
前端·vue.js
杨运交13 小时前
[041][公共模块]分布式唯一ID生成器设计与实现:一款灵活可扩展的雪花算法框架
spring boot
暴走的小呆1 天前
Vue 2 中 Object 的变化侦测:从 getter/setter 到 Dep、Watcher、Observer
vue.js
英勇无比的消炎药1 天前
TinyVue v-auto-tip: 文本超长自动提示的优雅方案
vue.js
时光足迹1 天前
腾讯云 TRTC UniApp SDK 从入门到上线
前端·vue.js·uni-app
时光足迹1 天前
uni-app 里把加密视频嵌入页面播放?我分析了 4 种方案,只有 1 种接近完美
前端·vue.js·uni-app
时光足迹1 天前
JPush UniApp UTS 插件完全参考手册:API、事件与厂商通道一网打尽
vue.js·ios·uni-app