zoukankan      html  css  js  c++  java
  • Mybatis 同时传入多个参数和对象

    流程

    1,mapper 接口文件使用 @param 注解(一个参数就不用使用注解,多个参数要么使用注解,要么使用数组的方式取值)

    2,mapper xml 文件使用

    mapper 接口文件传参

    public interface AccountMapper {
        List<Account> selectBySearch(@Param("record") Account record, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("companyName") String companyName);
    }

    mapper xml 文件使用参数

    传入的参数不止一个,就不要指定参数类型

    <select id="selectBySearch" resultMap="BaseResultMap">
        select 
        <include refid="Base_Column_List" />
        from main_account
        where 1 = 1
        <!-- 使用参数 1 (是个对象) -->
        <if test="record.email != null">
            and email = #{record.email}
        </if>
        <!-- 使用参数 2 -->
        <if test="startDate != null">
            and create_date &gt; str_to_date(concat('', #{startDate}),'%Y-%m-%d %H %i %s')
        </if>
        <!-- 使用参数 3 -->
        <if test="endDate != null">
            and create_date &lt; str_to_date(concat('', #{endDate}),'%Y-%m-%d %H %i %s')
        </if>
        <!-- 使用参数 4 -->
        <if test="companyName != null">
            and (full_name like "%"#{companyName}"%" or short_name like "%"#{companyName}"%")
        </if>
    </select>
  • 相关阅读:
    Eclipse中用两个控制台测试网络通信程序
    c++ primer 11 泛型算法
    c++ primer 10 关联容器
    c++ primer 9 顺序容器
    c++ primer 8 标准IO库
    安装使用
    InfluxDB介绍
    proxy.go
    monitor.go
    balancer.go
  • 原文地址:https://www.cnblogs.com/huanggy/p/9326669.html
Copyright © 2011-2022 走看看