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>
相关推荐
swg32132120 小时前
Spring Boot 3.X Oauth2 认证服务与资源服务
java·spring boot·后端
像我这样帅的人丶你还20 小时前
别再让JS耽误你进步了。
css·vue.js
gelald20 小时前
SpringBoot - 自动配置原理
java·spring boot·后端
@yanyu66620 小时前
07-引入element布局及spring boot完善后端
javascript·vue.js·spring boot
王霸天20 小时前
💥别再抄网上的Scale缩放代码了!50行源码教你写一个永不翻车的大屏适配
前端·vue.js·数据可视化
那个失眠的夜20 小时前
Mybatis延迟加载策略
xml·java·数据库·maven·mybatis
悟空瞎说20 小时前
深入 Vue3 响应式:为什么有的要加.value,有的不用?从设计到源码彻底讲透
前端·vue.js
程序猿_极客21 小时前
SpringBoot 三大参数注解详解:@RequestParam @RequestBody @PathVariable 区别及常用开发注解
java·spring boot·后端·面试八股文·springboot注释
小胖java21 小时前
校园通衢公告枢纽系统
java·spring boot
身如柳絮随风扬1 天前
MyBatis 插件原理详解:从拦截器到动态代理,手写一个分页插件
java·mybatis