1、在代码中拼接好字符串后传入进来
2、使用CONCAT在xml中拼接字符串:
<if test="queryParam.keyword != null"> AND b.appName LIKE CONCAT('%', #{queryParam.keyword}, '%') </if>
3、Mybatis的bind:
List<RoleEntity> selectBykeyWord(@Param("keyword") String keyword);
<select id="selectBykeyWord" parameterType="string" resultType="com.why.mybatis.entity.RoleEntity"> <bind name="pattern" value="'%' + keyword + '%'" /> SELECT * FROM t_role WHERE role_name LIKE #{pattern} OR id LIKE #{pattern} OR role_type like #{pattern} </select>