使用myabtis中的动态sql语句实现多条件查询

2023-09-12

StoreHouseMapper

复制代码
package com.hh.mapper;

import com.hh.pojo.StoreHouse;

import java.util.List;

/**
 * @author hh
 * @version 1.0
 * @DATE 2023-09-12 14:09:48
 */
public interface StoreHouseMapper {

    List<StoreHouse> selectSHByCondition(StoreHouse storeHouse);
    List<StoreHouse> selectSHByConditionTwo(StoreHouse storeHouse);
}
复制代码

StoreHouseMapper.xml

复制代码
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.hh.mapper.StoreHouseMapper">


    <select id="selectSHByCondition" resultType="com.hh.pojo.StoreHouse">
        select * from t_storehouse
        <where>
            <if test="sName!=null and sName!=''">
                s_name like "%"#{sName}"%"
            </if>
            <if test="sType!=null and sType!=''">
                and s_type like "%"#{sType}"%"
            </if>
            <if test="sDescription!=null and sDescription!=''">
                and s_description like "%"#{sDescription}"%"
            </if>
        </where>
    </select>

    <select id="selectSHByConditionTwo" resultType="StoreHouse">
        select * from t_storehouse
        <trim prefix="where" suffixOverrides="and">
            <if test="sName!=null and sName!=''">
                s_name like "%"#{sName}"%" and
            </if>
            <if test="sType!=null and sType!=''">
                s_type like "%"#{sType}"%" and
            </if>
            <if test="sDescription!=null and sDescription!=''">
                 s_description like "%"#{sDescription}"%"
            </if>
        </trim>
    </select>
</mapper>
复制代码

 

posted @   努力是一种常态  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示