这个方法真实有效,直接上代码
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中,取实体类的属性前面要加上类的引用