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>
相关推荐
学长毕设6 小时前
基于SpringBoot智慧养老服务平台设计与实现-附源码
java·spring boot·后端
一个游离的指针7 小时前
Vue2:vue-router
前端·javascript·vue.js
千寻技术帮8 小时前
10454_基于Springboot的企业购销链管理系统
spring boot·mysql·vue·毕业设计·进销存
用户4514194293228 小时前
2026 Vue 生态分析:底层重写了一遍,升级却几乎零成本
vue.js
Forget the Dream8 小时前
Spring AI 2.0 系列(二):第一个 ChatClient——从注入到一次完整调用
java·人工智能·spring boot·ai·springai
tryCbest10 小时前
Vue系列——第 20 篇:Vue Router 4——路由管理完全指南(上)
前端·javascript·vue.js
用户8417948145611 小时前
vue 表格组件 vxe-table 实现 Excel 双击填充柄向下复制填充功能
vue.js
她的男孩11 小时前
设计器能拖抄送,一点发布却报 flowable-servicetask-invalid-type:Forge Admin 部署前改写节点属性
spring boot·低代码·工作流引擎
徐小夕17 小时前
深度拆解 Design Agent:LangChain 出品,AI 设计从「好看」走向「可用」
前端·vue.js·github
1-1=018 小时前
Vue 表单数据和过滤器
前端·javascript·vue.js