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>
相关推荐
天若有情6731 小时前
SpringBoot4 + MyBatis 前后端分离实战|从零实现坏习惯管理系统,支持局域网手机访问CRUD
智能手机·mybatis
Bad_Shepherd1 小时前
vue-element-plus-admin添加自定义svg图标,并且图标选择组件可选自定义图标
vue.js·elementui·前端框架
dkbnull3 小时前
Spring Boot请求处理组件对比详解
java·spring boot
不能只会打代码3 小时前
Day 011 — Spring 全家桶深度拆解
spring boot·mybatis·spring aop·spring mvc·spring ioc
吴声子夜歌3 小时前
MongoDB 4.x——SpringBoot框架整合
数据库·spring boot·mongodb
snow@li4 小时前
Spring Boot:项目服务器完整部署教程(零基础可直接实操)
服务器·spring boot·后端
会周易的程序员4 小时前
Mermaid Renderer:一款的图表可视化小工具
前端·vue.js·流程图·mermaid
万亿少女的梦1685 小时前
基于Spring Boot、Java与MySQL的网络订餐系统设计与实现
java·spring boot·mysql·系统设计·网络订餐
鱟鲥鳚13 小时前
Spring Boot 集成 LangChain4j:从模型调用到 Tool Calling(Demo版)
java·spring boot
腾渊信息科技公司16 小时前
Spring Boot对接MES实战:视觉检测数据自动同步方案
java·人工智能·spring boot·后端·计算机视觉·ai·软件需求