mybatis查询参数中既有 实体类参数又有基本类型参数 解决方案

来源:互联网 发布:数学建模优化模型论文 编辑:程序博客网 时间:2024/05/16 15:21

这个方法真实有效,直接上代码
DAO中的查询方法

public LogisticNodes findFirstNode(@Param("ln")LogisticNodes ln,@Param("stringId")String stringId);

第一个参数为实体类,需要加上@param()注解
xml中的写法

        SELECT            <include refid="logisticNodesColumns"/>        FROM            order_logistic_nodes a        <where>                                     <if test="ln.id != null and ln.id !=''">                     AND a.id = #{ln.id,jdbcType=VARCHAR}                </if>                <if test="ln.nodeName != null and ln.nodeName !=''">                     AND a.node_name = #{ln.nodeName,jdbcType=VARCHAR}                </if>               <if test="ln.nodeSort != null">                     AND a.node_sort = #{ln.nodeSort,jdbcType=DECIMAL}               </if>        </where>        and            a.logistic_type IN (                SELECT                    s.logistic_type                FROM                    order_logistic_nodes s            <where>                                     <if test="stringId != null and stringId !=''">                      s.id = #{stringId,jdbcType=VARCHAR}                </if>           </where>        )        order by a.node_sort        limit 1

xml中,取实体类的属性前面要加上类的引用

0 0
原创粉丝点击