您的位置:首页 > 其它

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

2017-01-03 16:59 543 查看
这个方法真实有效,直接上代码

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中,取实体类的属性前面要加上类的引用
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐