NullPointerException Can't add values % , null

一、报错信息

NullPointerException Can't add values % , null

二、出现原因

在mybatis中使用like进行模糊查询时,不能使用'%#{param}%' 来拼接字符串,便使用 <bind> 标签绑定参数,再之后的查询中,若传入参数为null,便会运行报错。

三、解决方法

处理null值

<!-- <bind name="username" value="'%'+user.username+'%'"/>
         <bind name="status" value="'%'+user.status+'%'"/> -->
         <choose>
             <when test="user.username">
                 <bind name="username" value="'%'+user.username+'%'"/>
             </when>
             <otherwise>
                 <bind name="username" value="'%%'"/>
             </otherwise>
         </choose>
         <choose>
             <when test="user.status">
                 <bind name="status" value="'%'+user.status+'%'"/>
             </when>
             <otherwise>
                 <bind name="status" value="'%%'"/>
             </otherwise>
         </choose>
原文地址:https://www.cnblogs.com/peanut-zh/p/13991888.html