请教个问题,在mapper中的动态sql中<if test="#{loginUser.user_id} == 'wangty55'.toString()">比对失败,其中传的值绝对是正确的,是不是写发有问题,以下是具体的代码: <select id="select_cust_product_all" parameterType="Map" resultMap="select_cust_product_all_map">
SELECT
c.*, d.product_status
FROM
(
SELECT
a.cust_id,
a.cust_name,
a.lt_manager_name,
a.department_name,
b.product_id,
b.industry_id
FROM
t_sj_cust a,
t_sj_industry_product b
WHERE
a.industry_id = #{industry_id}
AND b.industry_id IN (#{industry_id}, '12')
<if test="#{loginUser.user_id} == 'wangty55'.toString()">
AND a.lt_manager_id = 'wangty55'</if>
) c
LEFT JOIN t_sj_cust_product_status d ON c.cust_id = d.cust_id
AND c.product_id = d.product_id
</select>

解决方案 »

  1.   

    改成<if test="loginUser.user_id == 'wangty55'.toString()">就好用了,还是对参数的理解不到位,什么时候该加#{},什么什么该加${},什么时候不加,分的也不是很清楚
      

  2.   

    if test 里面直接取值, 不用写 ${ }   或  #{}
      

  3.   

     'wangty55'我没看错的话,你这个是 单引号,JAVA里面单引号,指这个是 char,说白了 就是会墙砖成int,你再.toString()你觉得它会变成 "wangty55"吗
      

  4.   

    话说你为何这里还要toString,直接来个"wangty55"不就好了嘛, 而且字符串比较你用 == 不应该是有eq嘛