if-test 等于某个值书写
<insert id="insertDelivery" parameterType="com.zuci.request.DeliveryPreferenceReq">
insert cx_customer_deliverypreference
<trim prefix="(" suffix=")" suffixOverrides=",">
.... 此处省略
<if test="takeWay == '1' and workday != null ">
WORKDAY,
</if>
....
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
.... 此处省略
<if test="takeWay == '1' and workday != null ">
#{workday, jdbcType=VARCHAR},
</if>
....
</trim>
</insert>
takeWay == '1' 处出错,导致不执行if判断中的sql,运行程序不报错,没有任何提示。去掉takeWay == '1' and 则可执行。
原因是:mybatis是用OGNL表达式来解析的,在OGNL的表达式中,’1’会被解析成字符,java是强类型的,char 和 一个string 会导致不等,所以if标签中的sql不会被解析。
解决方案:
把<if test="takeWay == '1' and workday != null ">
改为<if test='takeWay == "1" and workday != null '> 即可

if-test 判断判断是否包含某个特定字符
<!-- 包含-->
<if test='bae.contains("null") '></if>
<!-- 不包含-->
<if test='!bae.contains("null") '></if>
8万+

被折叠的 条评论
为什么被折叠?



