MyBatis动态增改,多字段模糊查询
示例:
insert
insert into bargain_products
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">id,</if>
<if test="userid != null and userid != ''">user_id,</if>
<if test="productName != null and productName != ''">product_name,</if>
<if test="type != null and type != ''">type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">#{id},</if>
<if test="userid != null and userid != ''">#{userid},</if>
<if test="productName != null and productName != ''">#{productName},</if>
<if test="type != null and type != ''">#{type},</if>
</trim>
update
update bargain_products
<trim prefix="set" suffixOverrides=",">
<if test="productName != null and productName != ''">product_name = #{productName},</if>
<if test="type != null and type != ''">type = #{type},</if>
<if test="texture != null and texture != ''">texture = #{texture},</if>
</trim>
where id = #{id}
select
SELECT
bp.id,
bp.user_id userid,
bp.product_name productName,
bp.type,
DATE_FORMAT(bp.create_time,'%Y-%m-%d') createTime
FROM
bargain_products bp
LEFT JOIN sys_user sus ON bp.user_id = sus.userid
<where>
<if test="secondLevel != null and secondLevel != ''">
sus.second_level = #{secondLevel}
</if>
<if test="fuzzyQuery != null and fuzzyQuery != '' ">
and CONCAT(bp.product_name, bp.type) LIKE "%"#{fuzzyQuery}"%"
</if>
</where>
ORDER BY bp.create_time DESC
多字段模糊查询中如果有一个字段为null,则返回的也是NULL,那么这一条记录可能就会被错过,怎么处理呢,我这边使用的是IFNULL进行判断
<if test="fuzzyQuery != null and fuzzyQuery != '' ">
and CONCAT(IFNULL(bp.product_name,''), IFNULL( bp.type,'')) LIKE "%"#{fuzzyQuery}"%"
</if>
delete
要么就直接删
DELETE
FROM
bargain_products
WHERE
id = 'BP-6ec77c53464f43afbe55b23d4a4e7b7d'
如果需要加别名的格式
DELETE bp FROM bargain_products bp WHERE bp.id ='BP-6ec77c5346'
MyBatis动态增改,多字段模糊查询的更多相关文章
- MySQL简单实现多字段模糊查询
我所做的商城项目前些时提了新需求,要求前台搜索商品除了能通过商品名称搜索到以外,还可以通过别个信息搜索,比如:商品编号.详情内容描述等等,类似于全文搜索了.我首先想到的就是lucene,但是对代码这样 ...
- Mysql 之实现多字段模糊查询
在一个table中有省,市,县,期,栋,单元,室几个字段,然后用户输入一个地址从表中的字段拼接起来进行模糊查询. 解决办法: <MySQL权威指南>中CONCAT的使用方法,在书中的对CO ...
- MySQL单表多字段模糊查询
今天工作时遇到一个功能问题:就是输入关键字搜索的字段不只一个字段,比如 我输入: 超天才 ,需要检索出 包含这个关键字的 name . company.job等多个字段.在网上查询了一会就找到了答案. ...
- MySQL单表多字段模糊查询解决方法 又折磨半天concat(字段不能为空,如为空则用IFNULL(字段,'');
SELECT `id`,`weixin_id`,`user_name`,`sex`,`area_id`,`address_near`,`phone`,`create_time`,`import_use ...
- Mysql多字段模糊查询
MySQL同一字段多值模糊查询 一. 同一字段多值模糊查询,使用多个or进行链接,效率不高,但没有更好的解决方案.(有看到CHARINDEX 关键字,可查询结果并不是模糊,举个栗子 例如SELECT ...
- Mybatis mysql 一个搜索框多个字段模糊查询 几种方法
第一种 or 根据搜索框给定的关键词,模糊搜索用户名和账号都匹配的用户集合 <select id="list" parameterType="com.user.Us ...
- django实战(二)--带多字段模糊查询的分页(也是不容易)
上节我们实现了分页功能,这节我们要实现对模糊查询后的结果进行分页.(引入了bootstrap框架) urls.py from django.urls import path from . import ...
- Oracle:时间字段模糊查询
需要查询某一天的数据,但是库里面存的是下图date类型 将Oracle中时间字段转化成字符串,然后进行字符串模糊查询 select * from CAINIAO_MONITOR_MSG t WHERE ...
- MyBatis Plus 实现多表分页模糊查询
项目中使用springboot+mybatis-plus来实现. 但是之前处理的时候都是一个功能,比如分页查询,条件查询,模糊查询. 这次将这个几个功能合起来就有点头疼,写下这边博客来记录自己碰到的问 ...
- MySQL单表多字段模糊查询解决方法
例如现有table表,其中有title,tag,description三个字段,分别记录一条资料的标题,标签和介绍.然后根据用户输入的查询请求,将输入的字串通过空格分割为多个关键字,再在这三个字段中查 ...
随机推荐
- 关于druid与springboot版本问题
datasource: druid: driver-class-name: ${sky.datasource.driver-class-name} url: jdbc:mysql://${sky.da ...
- LeetCode654. 最大二叉树
题目链接:https://leetcode.cn/problems/maximum-binary-tree/description/ 题目叙述 给定一个不重复的整数数组 nums . 最大二叉树 可以 ...
- hbuilder打包的应用上架appstore屏幕快照的生成方法
当我们使用hbuiderX或apicloud这些打包工具进行打包的时候,我们需要将打包好的ipa文件进行上架,但是你会发现,我们上架的时候需要上传5.5寸的iphone.6.5寸的iphone X和两 ...
- 一次url请求全过程
一次url请求全过程 1,从宏观总体来看url请求全流程 2,从家庭实际网络架构来看一看网络是如何搭建和传输的 3,从网络七层协议的角度来看一看网络在各个层次之间的传输过程 4,从三次握手四次挥手的角 ...
- 02 IO口的操作
目录 前言 一.IO的概念 1.IO接口 2.IO端口 二.CPU和外设进行数据传输的方法 1.程序控制方式 1.1 无条件 1.2 查询方式 2.中断方式 3.DMA方式 一.方法介绍和代码编写 1 ...
- 9、IDEA集成Github
9.1.登录Github账号 9.1.1.打开IDEA的Settings界面 如上图所示,打开IDEA的 Settings(设置)界面. 9.1.2.使用账号密码登录(方式一) 如上图所示,在&quo ...
- 【Vue2】Direct 指令
1.内容渲染指令 1.插值表达式 2.V - TEXT 3.V - HTML <!DOCTYPE html> <html lang="en"> <he ...
- pycuda学习过程中的一些发现,cuda函数的初始化要在cuda内存空间初始化之后,否则会报错
参考: https://www.cnblogs.com/devilmaycry812839668/p/15348610.html 最近在看WarpDrive的代码,其中cuda上运行的代码是使用pyc ...
- ffmpeg和ffplay常用指令
FFmpeg 常见用法 1. 基本命令结构 ffmpeg [global_options] -i input_file [input_options] output_file [output_opti ...
- AtCoder Beginner Contest 312
AtCoder Beginner Contest 312 A - Chord (atcoder.jp) #include <bits/stdc++.h> #define endl '\n' ...