Mybatis Integer type, the value of 0 is considered a solution to an empty string

When querying or inserting in Mybatis, we generally perform non-null check on the data. example:

<if test="payerId != null and payerId != '' ">
      AND payer_id = #{payerId}
</if>
<if test="payeeId != null and payeeId != '' ">
      AND payee_id = #{payeeId}
</if>

 

If it is not empty and not null, the value will be modified, but this can only be written for the string (String) type. If it is an Integer type, there will be problems. example:

int parentId  = 0;
<if test="parentId != null and parentId != '' ">
      AND parent_id = #{parentId}
</if>
As in the above pseudo code, AND parent_id = #{parentId} will not be executed, which means that mybatis defaults the value of parentId to
empty string.

 So, for this problem, my solution is: if the type is an Integer type, I will remove it! = ", just judge !=null.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327033529&siteId=291194637
Recommended